Introduction: Programmable RGB Mood Light - Attiny85

About: Unable to comment - keeping the articles for reference

Welcome to my first instructables page. A year ago I got introduced to the wonderful world of Arduino and electronics. I have learned a lot from this site and this seems a great place to show my projects. I hope you find this project entertaining and helpful.

I'm eager to know what you think. Let me know in the comments, please keep in mind I'm a beginner and not a native speaker. All of your comments are welcome ;)

The project

I few months ago my night lamp broke and I was looking for a replacement. Then I thought: why buy one if I can make one! My first intentions was to use an Atmega328 but this project required only a few pins and I wanted the built be a cheap as possible. So I did some research and ended up with an Attiny85.

My self-built night lamp has 3 knobs to choose the desired colour, saturation and brightness. Also there are 3 buttons you can press to select one of your favorite preset colours. These presets are programmable and can be altered as may times you would like. Just pick your desired colour and hold the button down for 3 seconds. I also implemented a fading colour wheel. Hold down button 1 and button 3 to activate this mode. The knob to control the colour can now be used to control the speed of the fading colour wheel. To exit this mode simply press one of the preset buttons or turn one of the knobs.

Watch this video to see the finished project:

Step 1: Get Your Supplies

It's time to get your supplies! The most items on the list I got from eBay or Amazon. These items are widely available so I recon it won't be a problem to find them.


Items

  • ATTINY85 (20PU)
  • Proto-Board
  • Single Addressable LED 8mm {PL9823 or WS28xx-series} [60mA, 5V] (8x)
  • Ceramic capacitor 100pF [104] (8x)
  • Electrolytic capacitor 47uF (3x)
  • Potentiometer 10K (3x)
  • Knobs (3x)
  • Silicon diode (3x)
  • Push button with green led [12V] (3x)
  • Resistor 220 ohm (4x)
  • Resistor 10K ohm (3x)
  • On/off switch
  • IC socket (8 pins)
  • Rubber foot (4x)
  • Power supply [5V, 500mA]
  • Pinewood bar (1000mm X 100mm X 12mm)
  • Opal acrylic glass (500mm x 250mm x 5mm)
  • Wood glue
  • 4 nails


About the LEDs (PL9823)

For this project I used a cheap version of the Adafruit Neopixel. I got them on eBay, 100pcs for 18 euro. They are similar to the ws28xx-series LEDs and only need one data-pin to control them. They also work with the popular FastLed library and are easy to control.


About ATTINY85

The Attiny85 is a low power 8-bit Atmel microcontroller and can be programmed via the Arduino IDE. I chose this microcontroller because it's small and has all the necessary pins for this project. As we only need 3 AnalogIn-pins and 2 digitalOut-pins.

Step 2: Make the Base

Time to show off your wood working skills!

Cut the wood - For this built I used regular pinewood (vurenhout in Dutch). I cut the pinewood bar into 4 pieces each with a height of 100mm. The front and the back will have a length of 220mm and the sides 196mm because I want to make a square and the wood has a thickness of 12mm.

Drill holes - I drilled 10 holes in the frontplate and 6 in the back plate (for the 4 nails, power cable and switch). Make sure the holes for the buttons have clean edges because otherwise the end result will look sloppy. The holes for the potentiometers can be a little rough because they will be covered by the knobs.

Make indentations - I made a few indentations for de potentiometers and the pushbuttons because the wood I chose was to think. I used a rotary tool and lots of patience. You can skip this step if you have chosen the correct thickness (depends on the size of the buttons and potentiometer).

Make a hole for the switch - Use a file to make a square hole for the power switch. Don't forget the hole for the power cable.

Pre-drill holes for nails - I used long nails and some wood glue to hold the pieces together. I therefore drilled 8 holes (4 in each of the sides). Make sure you drill perfectly straight otherwise the nails will come out through the side panels.

Apply some wood glue and insert the nails - Apply the glue before you insert the nails.

Make a standing edge - Use a file or a rotary tool to make a standing edge. This wil prevent the cover form sliding off.

Step 3: Make the Cover

Prepare to get hot and sticky

Cut the acrylic - Cut the acrylic glass to a length of 500mm and a width of 220mm. Make sure you have a straight cut.

Bend the acrylic - Use a heat gun or an oven to heat the piece so it can be bend. I used tinfoil to protect the areas I don't want to bend. Again: make sure you have a straight and even angle.

Cut the side pieces - Cut the side pieces from the remaining acrylic. I purposely cut them too wide and sanded them down later to ensure a good fit.

Glue it together - I used hot glue to secure the pieces but there are better kinds of glue you can use for this task (if you demand a stronger bond)

(Optional) Sand down the acrylic - I sanded down the acrylic to give it a softer touch and less glossy finish.

Step 4: Schematics

The built is pretty easy but there is a little trick. The lamp has 6 inputs (3 knobs and 3 buttons) but the Attiny only has 3 analog input pins. To solve this problem the first potentiometer and the first button share an analog pin, this applies also to the second and third potentiometer and button.

When a button is pressed the current flows without much resistance to the analog pin, and we get a reading of 1024 (i.e. 5V). When the button is not pressed the current flows through the potentiometer. This current has to travel through a diode (which has a voltage drop) first before it can enter the analog pin. Therefore the maximum reading we can get is determined by the diode voltage drop.

The maximum reading I got was 910. So now we know when the value of the first pin exceeds 915 that a button is pressed, a lower number indicates otherwise.

Further we use a 10K ohm pull-down resistor to debounce the button press and a electrolytic capacitor for the potentiometer.

We use a 100pF ceramic capacitor for the LEDs and a 220 ohm resistor to protect the data pin from voltage spikes. And a four 220 ohm resistors for the push button LEDs to limit the current.

Note: The 9V depicted is not representative, we use a 5V power source

Step 5: Solder

Now comes the tricky part: the soldering.

Pay close attention to the positive an negative pins, the LEDs are not protected agains reverse voltage. And make sure the buttons are well placed and they have a snug fit into the holes we drilled in the front plate.

Step 6: The Code

I did my best to describe the code as well as I could. This is my first real coding project and I think there is room for some improvements, I'm open for suggestions.

If you want to use this code for your Arduino Uno you will have to change the pins

Step 7: Program the ATTINY85

I won't go in to much detail here. There are a lot of great tutorials how you can program an attiny85. I linked in 2 sources below. I will briefly describe the steps you will have to take

1. Download the attiny library at github:

https://github.com/damellis/attiny/ar...

2. Upload the ArduinoISP file to the arduino

3. Connect the arduino with the attiny:

Arduino pin Attiny Pin

  • 5V -> VCC
  • GND -> GND
  • Pin 10 -> Reset
  • Pin 11 -> IO 0 / digital1 / 5
  • Pin 12 -> IO 1 / digital2 / 6
  • Pin 13 -> IO 2 / analog1/ 7

Don't forget to put a 10uF capacitor between the ground and the reset of the arduino

4. Select ArduinoISP as programmer and select Attiny 1Mhz or 8Mhz board

5. Upload your sketch

Helpful sites:

AwesomePCB: https://www.instructables.com/id/How-to-Program-ATt...

codebender_cc: https://www.instructables.com/id/How-to-program-the...

Step 8: Put It All Together

Now comes the fun part, bringing it all together!

- Feed the power cable through the hole and solder it to the proto-board

- Screw the buttons in the front panel

- Insert the programmed Attiny85 in its socket

- Place the knobs

- Screw on some rubber feet

- Optional: To increase the weight I used a few heavy bolts and hot glued them to the base

- Place the cover, plug it in and enjoy

Step 9: Future Improvements

In the next version I would like to implement:

1. More LEDs - I would use at least 16 LEDs and a bigger power supply, I find 8 LEDs a bit too weak.

2. Paint the base

3. Use memory - to store the new presets possible with a EEPROM IC. (now if you unplug the lamp, it will forget your newly added presets)

4. Find a way to individually address the push button LEDs - so I can display which program is currently active