Introduction: Basic Mood Light With Minimal Parts ATTiny85 and WS2812B Pixel
This is a basic Mood Light or Night Light setup using a recycled wooden box as casing.
Focus in this Instructable is to choose hardware and how to calculate the right placement for the LED. The reader should aldready be familiar with how to program a microcontroller and what relevant libraries of code to use.
With as few components as possible I selected the Digispark ATTiny85 that is Arduino compatible together with a RGB LED with the famous WS2812B chipset integrated (such as "NeoPixel"). All the components needed to drive the Pixel are on board and needs just one wire to recieve commands.
The electronic components were cheap and clearly marked where to connect Power and Data. Soldering is required and can take some practice before attaching wires to the Pixel that has small connectors. Using a little solder flux liquid it is quite managable to get it right.
To get a soft light from the box without sharp light or shadows you must use a "diffuser" material placed on a certain distance from the very bright and clear light of the Pixel. I used the lid of a foodbox and you can look around at home for something that has a frosted or milky look but must be enough transparent to let the light out in a pleasant color tone.
For power I used a rechargable 5v USB powerbank. The size of the battery used will also set the minimum size of the box used for the Mood Light.
Step 1: Get Your Kit Ready
Attach the Digispark ATTiny85 or a USB-connector to the 5v battery and use it to measure out a box it will fit in. Make sure the box is deep enough to place battery under the Pixel and have enough distance to the top where you will attach the sheet of diffuser material.
How to calculate a minimum distance between the Pixel and diffucer sheet is reviewed in the next step.
Solder three wires to the Pixel. It should be clearly marked Ground (-) / Data (Din) / 5v (+). Inspect and make sure proper connections are made. Take care to not overheat when soldering which can destroy the Pixel circuit inside. Use a Flux liquid pen to make the soldering process quick.
Solder the Data wire (Din) to one of the top row pads in the ATTiny85, make a note of the number to be used in the software to drive the Pixel. Solder the Ground wire to the ATTiny85 pad on the side marked GND. Solder the 5v (+) wire to the pad on the side marked 5v.
If you want to reuse the components for other projects you should solder male pins to the ATTiny85 and solder wires to the Pixel with Dupont female connectors. This is the recommended way but will also take up extra space when connectors are used. Be sure to measure again using connectors if the components fits in your box.
Want even more light from the box? Pixels are chainable, that is several pixels can be connected to the first one. Simply connect three additional wires, using Dataout (Dout) from the first Pixel to the Datain (Din) on the second Pixel.
A USB Micro female connector breakout board can also be used to drive the ATTiny85 without attaching a battery directly to the microcontroller. This is useful if you make a hole in the side of the box for external power. However there are ATTiny85 dev boards with Micro USB that you should use instead and only mentioned here as a reference.
Step 2: Calculating Optimal LED Distance for Ambient Light
To get the best ambient light from the box the distance between the Pixel and the Diffuse sheet should not be too close or far apart. These "clear" LEDs have a light beam with narrow angle and the colors will be far too strong and sharp for this project.
When you find a good material to use as diffuser it will blend the different colors to a smooth radiant glow. A LED placed close may show circles or have faded edges. When LED is placed on a too great distance the light from the box may have sharp edges and all we want is a nice colored crown.
Calculating the optimal LED distance is by using two known variables to get the height (or distance) where the LED should be placed relative to the diffusing sheet. See the reference images.
We can easily measure what the longest distance is between two corners of the top or bottom on the box. We also need to know the angle of light produced from the LED used. Then we can calculate the distance using math for a Right-angle Triangle using only these two known variables.
The length of my box is 14 centimeters and the Pixel used has a 120 degree angle of light. Divide them by two (2) and I get 7 centimeters and 60 degrees to use in the calculation. The distance (height) is 4.04 centimeters.
Step 3: Upload Code to ATTiny85 With Pixel (reference)
The most common way to program the ATTiny is by using Arduino IDE free software here.
Also check out Arduino Create webtool (sign up, it's free).
This is where you need to check what number you connected the Pixel Data wire (Din) to your ATTiny85.
There are several excellent guides on Instructables that go into detail in programming and uploading code.
Here are instructables that even goes beyond the Digispark boards and show how to program a single chip for similar use.
Step 4: The RGB Pixel LED Box - and Beyond
This image show the result of using just one Pixel with the ATTiny85, using Adafruit NeoPixel library for Arduino.
Pretty and good looking for a quick project, using a few common unused components and reused materials.
Where to go next?
Here comes a few suggestions to go from here now that you have the base setup done.
- Power switch. A natural addition to turn off and on the light, but much could als be added to code. Check out sleepmode and timer functions for your microcontroller. Put on a rotary encoder to change colors and intensity manually?
- Add a LDR resistor to check if the room is dark before turning on the Pixel. Perhaps start with a sparkle of random colors and why not choose a signature color based on data from a temperature sensor?
- Use a PIR movement detector or Noise detector to wake the light and periodically keep it from burning out.
Just remember that each extra addition takes up more digital code and physical space in a box. Less is more.
We have a be nice policy.
Please be positive and constructive.