$1 Rainbow Fire Lamp With CH32V003 and WS2812
by arduinocelentano in Circuits > Art
335 Views, 1 Favorites, 0 Comments
$1 Rainbow Fire Lamp With CH32V003 and WS2812
There are numerous LED lamp projects available. Let this lamp be one of the most minimalistic and affordable, aiming to achieve more with less. You can use such electronic "candles" to accentuate your bookshelf, create a night light, holidays decorations, or even make battery-powered wearables.
This is an attempt to remake my old $1 mood lamp project using more up-to-date hardware. Originally powered by the ATtiny13, which has become more expensive due to the global chip shortage, that project now exceeds the $1 budget.
I decided to replace it with a low cost RISC V chip that I recently discussed. As I found out, ch32v003fun framework already has two implementations of WS2812 protocol. By utilizing the CH32V003 chip, the overall cost decreased, enabling me to venture into a battery-powered project. Unfortunately, batteries are not included, but you could repurpose rechargeable batteries from old devices.
Despite the WS2812 LEDs are thirst for 5V, they work surprisingly well from 3.7V battery, provided you dial down the brightness and keep the LED count modest. My initial prototype was able to work normally nearly 20 hours on a single charge.
The fire animation remains the same, but now it is possible to change fire color with thumbwheel potentiometer. Two other modes were removed because they were not fun. They could be easily ported too, but I prefer to keep the lamp free from excessive buttons and controls. Still looking for the optimal human interface.
This is a bare-bones project, so there is no 3D-printed case or custom PCB included, as they are beyond the scope of the $1 project concept. However, feel free to create your own designs.
Supplies
Bill of materials:
- CH32V003 in SOP-8 package ($0.10)
- WS2812 RGB LED stick ($0.40)
- two-sided SOP8/TSSOP8 adapter ($0.05)
- 10uF capacitor ($0.01)
- 100nF capacitor ($0.01)
- charge current limiting resistor (it depends on your battery) (<$0.01)
- 2.54mm 90° pin header (<$0.01)
- potentiometer (or any other analog control to tune the color) ($0.06)
- power switch ($0.03)
- TP4056 charge controller board ($0.11)
- 3.7V rechargeable battery (it's obviously out of $1 budget if you buy it, but you could collect some used batteries from old cellphones, vapes, laptops etc.)
- scrap wires
Tools:
- soldering tools (soldering iron, solder, solder flux, solder wick, tweezers etc.)
- multimeter
- WCH-Link debugger
All prices are given assuming you order 10+ items, they might be different the moment you are reading this and depend on your location.
Install the Microcontroller to the Breakout PCB
First, fix two opposite corner pins. Apply some soldering flux and solder the remaining pins. Use copper wick with flux if you need to remove unwanted solder.
Install the Pin Header
Only pins 1-4 will be used in this project.
Upload the Firmware
ch32v003fun toolkit has a tool named minichlink for firmware uploading. You'll only need to connect three lines of WCH-Link:
3v3 WCH-Link - pin 4 breakout board
GND WCH-Link - pin 2 breakout board
SWDIO WCH-Link - pin 8 breakout board
Just run make command inside the project directory. I also attached a binary if you don't want to compile it.
Attach WS2812 LED Stick
The LED module has pads on the both sides. Make sure you use the DIN side. I also installed two capacitors (10uF and 100nF) between VSS and VDD. They are needed for MCU, not for LEDs. So you might want to install them closer to the MCU power pins.
Install the Potentiometer
The potentiometer is connected to PIN1, which corresponds to A6 analog input.
💡At this point you could connect everything to the power supply to ensure that it works correctly.
Tuning TP4056 Charging Controller (optionally)
The charging current is determined by the R3 resistor. Typically, the default resistor is set for the maximum current, which could potentially damage your battery. If your board is becoming hot during charging, you may consider replacing the resistor. The typical values are in the table below.
R3 (kOhm) I_BAT (mA)
10 130
5 250
4 300
3 400
2 580
1.66 690
1.5 780
1.33 900
1.2 1000
Installing the Power Switch
Connect the switch to one of the output pads.
Assembling Everything Together
Connect the TP4056 output leads to the power inputs of the microcontroller using thick wires.
Installing the Battery
Connect the battery to B+ and B- pads of of TP4056.
⚠️Be careful at this point! Wrong polarity could damage your board. Moreover there is a risk of accidentally shorting the battery with your soldering iron or tweezers.
Understanding Animation and Color Transformation
I wanted to provide a natural color picking interface, so I used a thumbwheel potentiometer, which resembles HSV color model cylinder. The plot depicts the idea of HSV to RGB transformation. it is implemented in setHue() function. The user could only change hue, while everything else is controlled by fireAnimation() routine.
Each pixel holds its own heat value. As the animation unfolds, pixels experience random cooldowns, with only the three bottom pixels occasionally receiving random bursts of heat. Following the laws of thermodynamics, heat gracefully flows and evens out among neighboring pixels. This simple model creates the illusion of fire.
You could make it more interesting by replacing the potentiometer by another analog sensor. Just a couple of possibilities:
- temperature mod: use a thermistor to have the fire's hue shift in response to changes in temperature
- light mod: incorporate a photoresistor to allow the fire's color to adapt based on the surrounding ambient light levels