YVmWXq5

Moonlight - Based on ESP32-C3 controller

 
Overview
Update Log

2024.01.20: Initially open-sourced this project Ver2.4
2024.01.20: D1 can be removed and D2 shorted for better power supply performance; awaiting redesign.

0. Model Description
Lunar Model Link: https://www.thingiverse.com/thing:3242080
Flange and base models are attached (.SLDPRT file created in SW 2020, please open with 2020 or later).
The lunar model needs to be offset a certain distance from the hotbed in the anti-normal direction to provide a reference plane for mounting the base.
Then import the flange model and adjust it to a suitable position so that the two fit well.
Then merge the two models, or directly slice them (direct slicing will result in slight overflow and overlapping of traces).
Finally, import and print.
(See Figure 7 for the printing effect)
It is recommended to embed M3 8mm nuts/copper embedded nuts in the flange holes for better assembly.
The assembly screws should be M3x26 (I think that's the parameter, I don't have the model on hand and have forgotten, longer is fine).
(This is a lunar model printed a long time ago. The printer wasn't properly calibrated at the time, so the layer lines are still very obvious.)
I. Effect Demonstration
Figure 1: Actual Product Image 1
Figure 2: Actual Product Image 2
Figure
3: Exploded View II. Hardware Design
The controller needs to be as small as possible, therefore, smaller components are required.
2.1 MCU
The MCU uses the ESP32-C3-MINI-N4. This package is small and easier to solder than QFN chips, requiring fewer external resistors and capacitors.
It has a built-in USB JTAG controller, allowing direct USB programming, saving the cost and space of a USB-TTL chip (although the ESP32-C3 is relatively expensive).
It has WIFI and Bluetooth functions, enabling connection to IoT platforms.
2.2 Power Management
Power management needs to meet the requirements of battery charging, system power distribution, and control. The power architecture is shown in Figure 4:
Power Architecture
The power management uses the ETA6002.
2.3 Lighting
Of course, it must have LEDs! G! B!
The mainstream WS2812b LEDs are used. Choosing a smaller packaged model might be better, but since I had quite a few 5050 packages on hand, I used them directly.
Due to space constraints, only two batteries were placed, resulting in limited brightness.
But, I doubt anyone would use this for lighting, right?
2.4 The battery
used is a 1000mAh polymer battery with a size of L35W30H10mm.
Battery link: https://item.taobao.com/item.htm?id=589740856789&spm=a1z10.1-c.w4004-22660760862.4.2c3e7f05jPE9V6&skuId=4258503775257
(Khaki 103035-1000mAh)
III. Software Design
3.1 Button Functions
In terms of button functions, the software needs to implement: light on/off, light brightness switching, and light color switching.
This project uses single button function reuse to achieve this.
The functions are as follows:

KEY1 Long press: On/off light
; KEY1 Double press: Switch light color (5 presets);
KEY1 Single press: Switch brightness (8 brightness levels).

The OneButton library is used for button function reuse.
3.2 WS2812b Control:
The WS2812b is a programmable RGB LED that can be controlled programmatically.
This project uses the FastLED library for control.
3.3 Low Power Consumption & IoT:
Currently, the battery life is poor, lasting approximately 6 hours at maximum brightness.
Therefore, we aim to reduce MCU power consumption and improve battery life by allowing the MCU to enter a low-power state during idle periods.
With IoT integration, the APP can be used to view and control the light's status or connect to Mi Home lights.
These two functions are currently under development.
IV. More Pictures
Figure 5 Actual Picture 3
Figure 6 Actual Picture 4
Figure 7 Actual Picture 5
Figure 8 Actual Picture 6 (This side has a Type-C interface and reset button - requires a pin)
Figure 9 Actual Picture 7 (This side has a multi-function button)
Figure 10 Actual Picture 8
Appendix
Appendix 1: Source Code
#include
#include
#include "OneButton.h"

// FastLED
#define NUM_LEDS 2 // Number of LED beads
#define DATA_PIN 10 // Arduino output control signal pin
#define LED_TYPE WS2812 // LED strip model
#define COLOR_ORDER GRB // Arrangement order of red, green, and blue LEDs in RGB LED beads

uint8_t max_bright = 255; // LED brightness control variable, can use values ​​from 0 to 255, the larger the value, the higher the brightness of the light strip

CRGB leds[NUM_LEDS]; // Create the light strip leds

// OneButton
#define button1_Pin 5
OneButton button1(button1_Pin, true);

// Variable
unsigned char status=0; // LED on/off status
unsigned char brightness=0; // Brightness status
unsigned char colorStatus=0; // Color status

// function
void click1()
{
if(status)
{
brightness+=32;
FastLED.setBrightness(brightness);
FastLED.show();
if(brightness<10)
{
brightness=0;
}
}
}

void doubleclick1()
{
if(status)
{
colorStatus++;
switch(colorStatus)
{
case 0: fill_solid(leds, 2, CRGB::White);break;
case 1: fill_solid(leds, 2, CRGB::LightBlue);break;
case 2: fill_solid(leds, 2, CRGB::LightCoral);break;
case 3: fill_solid(leds, 2, CRGB::Pink);break;
case 4: fill_solid(leds, 2, CRGB::MediumPurple);break;
case 5: fill_solid(leds, 2, CRGB::Gold);break;
case 6: colorStatus=0;
}
FastLED.show();
}
}

void longPressStart1()
{
status=!status;
if(status & brightness==0)
​​{
brightness=128;
}
else if(!status)
{
brightness=0;
}
FastLED.setBrightness(brightness*status);
FastLED.show();
}

void setup() {
// put your setup code here, to run once:
LEDS.addLeds(leds, NUM_LEDS); // Initialize the light strip
FastLED.setBrightness(brightness); // Set the light strip brightness
fill_solid(leds, 2, CRGB::White);
FastLED.show();

button1.attachClick(click1);
button1.attachDoubleClick(doubleclick1);
button1.attachLongPressStart(longPressStart1);
}

void loop() {
// put your main code here, to run repeatedly:
button1.tick();
delay(50);
}
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2026-03-27 02:45:53

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号