This tiny project has been made around a nicely carved 10x6x5cm wooden box I found in a shop.
Its best feature, which has not actually been properly caught on camera, is to light up with bright, saturated colors, the sides of the tree-carved lid of the box.
On the other side, be aware that using a rainbow effect on a strip of narrow RGB 5050 LEDs will always result in a whiteish illumination within some centimeters from the LEDs, as each pixel's color soon mixes with its neighbors'. Should you want to avoid this effect, you can try (unless you use some focusing lens)
The brightness of the lamp is kept proportional to the ambient light thanks to a LDR: the lamp will shine in daylight conditions and won't be too bright if used as a nightlight, in the dark.
Bill of materials:
- one Attiny85 Digispark (clone) board, with its Micronucleusbootloader
- one 8x WS2812 bar
- one LDR, used to tune the lamp's brightness depending on the surroundings
- one 10KΩ pull-up resistor for the LDR
- an USB micro cable to program the Digispark and to power the lamp once done
- an hollow wooden box
- a 5V⎓ power source (capable of providing not less than 500mA)
Skills and tools:
- PlatformIO (running on Visual Studio Code) as the IDE - any Arduino IDE will do the job, though
- a soldering iron, some solder wire and basic soldering skills
- some wiring, scissors
- some glue, tweezers
- some opaque paint (to cover Digispark LED and to protect the LDR from being influenced by the lamp light)
Step 1: Digispark and PlatformIO
- Digispark (and every clone involving the same 8-bit microcontroller) is a breakout board built around an AVR Attiny85, capable of straightforward USB communication thanks to a Micronucleusbootloader.
Please find any further information on its wiki: http://digistump.com/wiki/digispark
Step 2: Schematic and Wiring
- connect three wires to the WS2812 bar (ground, power input and data input)
- wire ground and Vcc to 5V and GND pin of the Digispark
- solder the remaining wire to Digispark's P0 pin
- solder a 10KΩ resistor to GND and P2 pins of the board
- use two wires to connect the LDR to 5V and P2 pins (I used barely visible enameled wires for aesthetic reasons)
Step 3: Firmware
Find the code for this project on my GitHub: https://github.com/fbattarra/attiny85_8bit_ldr_rai...
Nice to know:
- #include has to be used while working with PlatformIO
- the parameters, like pins' assignment, number of WS2812 LEDs, rainbow wheel speed and dark/bright thresholds for both LEDs and LDR are at the beginning of the code
- Adafruit Neopixel is the library used to control the WS2812 LEDs
- RunningMedian library is used to make LDR readings more stable; due to the boundaries set, mapping LED brightness boundaries, this is especially nice in low brightness condition, where a tiny fluctuation may result in an annoying flickering
- You won't find any attempt of locking the Attiny85, so the project will remain editable
Some hints (appearing also in the README.md file on GitHub):
- To upload the code, make sure to have an USB cable with every pin wired: cheap charging cables often have just +5V and ground wired
- Uploading from PlatformIO to DigiSpark needs you to plug the DigiSpark after compiling, even though the console doesn't warn "now it's time to plug your DigiSpark", as Arduino IDE does.
- Quick fix for issue in uploading to DigiSpark from PlatformIO on MacOS: PIO issue 111
- Cheap USB chargers may provide dirty/noisy output, which could make LEDs oddly flicker especially at low brightness: make sure to have a clean 5VDC source, or to filter adding a capacitor (or a more proper circuit)
Step 4: Casing & Finishing Touch
- Carve an hole in the box of your choice for hosting the project, to plug your USB cable. Be aware that the bigger the hole around the micro USB connector, the more the leaking of light from your LED bar, unless you won't provide some opaque seal.
- Carve an hole for the LDR; make sure to make it point not towards the area that will be illuminated by the LEDs, otherwise the auto-regulation will fall in a loop
- Engrave the inner surface to make room for the LED bar, as you should not want to directly see the LEDs while looking at your lamp
- Seal with an opaque medium the bottom of the LDR, to avoid any interference in sensing environment's brightness caused be the WS2812 bar
- Use a drop of opaque paint to mask the Digispark power led, thus avoiding having it shining inside the box
- Glue Digispark board, LED bar, LDR and every cable to avoid the interior of your hollow box looking untidy
- Foresee an USB cable with a switch, to easily turn on and off the lamp