Introduction: Twinkling Stars in the Hallway

Some years ago I put a series of white LED's into the ceiling of our hallway in a number of constellations, mostly those seen in the southern hemisphere. I made a PWM (pulse wave modulator) based on a 555 timer to dim them which has worked nicely since then.

However I have been reading up on AVR microcontrollers recently, those found in Arduinos, and decided that this was an opportunity to learn how to use the AVR microcontroller by making the stars in the ceiling twinkle, instead of just shining.

Step 1: The Components & Circuit

The twinkler circuit is built around an ATMega328 AVR chip, with a ULN2803 Darlington array chip used to drive the LED's.

The full part list is here

  • 1 - U1 ATMega328 (DIP28N)
  • 1 - U2 ULN2803 Darlington transistor array (DIP18)
  • 1 - U3 LM7805 +5V 1A Fixed Voltage Regulator
  • 1 - D1 1N4002 a power diode
  • 1 - C1 100nF Capacitor
  • 1 - POT 10k linear variable potentiometer
  • 1 - R1 100K Resistor
  • 8 - R2 - R9 150Ohm resistor
  • 24 - Ultrabright while LED's - LA0071UB
  • 2 - 3 pin connectors
  • 1 - 10 pin connector
  • Vero board (strip board)
  • Plastic case
  • 12 - electrical block connectors
  • 1 - 2.1mm DC power socket

The circuit diagram is simpler than it looks

D1 is a diode to protect the circuit if/when I connect the power round the wrong way.

There is a 5v voltage regulator (U3, LM7805) gets the voltage to the right level for the ATMega328 AVR (U1)

The capacitors, resistor R1 and crystal oscillator, are necessary to drive the ATMega328

The potentiometer is connected to A0 and is used to set the level of the LED's so they don't disturb people at night, but can be seen in the day.

The digital outputs from the ATMega328 go to U2 a ULN2803 chip with 8 darlington transistor pairs, which are used to drive the actual LED's. The remaining resistors manage the current through the LED's.

I use connectors so I can remove the board from box if needed.

The circuit was developed in TinyCad, a freeware program.

Step 2: The Code

I used 6 different structs to control the LED's. While I have 8 stings in the roof I decided to stick with the native PWM capabilities of the ATMega328. I did consider using the SoftPWM library but decided to leave that for later projects.

I use a serial channel for some basic commands and to display outputs. The finished version has some pins on the board, but they are not connected to anything at the moment.

SO a code walk through

The first section is defining constants & variable, as well as the 6 structs to control the LED strings.

The setup section opens the serial channel and initialises the structs defining the LED strings

The main loop:

Checks the serial channel for input;

If the mode of operation is NORMAL

Sets each of the LED channels to a brightness based on time, each one cycles brighter and dimmer at different rates, which creates an effect of reasonably random 'twinkling'.

If the mode of operation in ON, all LED's are set full on

If the mode of operation is OFF, the LED's are turned off.

The final procedures manage the serial channel, looking for any inputs, changing the operational mode if necessary, and displaying the status of some variables.

All the code relating to the serial channel could be removed as the serial interface is not used when in use, but I left it in in case I wanted to change things in the future.

Step 3: Building the Circuit Board

Once the circuit is built in TinyCad I exported the info into VeeCAD, which is a very useful program for developing circuits on stripboards.

It may be possible to build the circuit onto a smaller board, but the box I have in the roof was quite big so I left the circuit quite spread out as it is easier to work that way.

I drilled out the breaks in the stripboard on my drill press and then started with the connectors, as in the attached picture.

Then it was time for the IC sockets, I use socket so there is no chance of damaging the IC's when soldering, and has the additional advantage that I could take the AVR out and reprogram it if I wanted to.

Lastly it was time for the discrete components and connectors.

Step 4: Installing in the Roof

The last part was quite easy as I was re-using the LED's in the ceiling. All the LED's were in strings of 3 LED's in series, I didn't take any photo's of them as the wires & LED's have been covered with insulation since I installed them. They generate no heat so there was no issue there.

I have a 13.8V transformer that drives the system nearby with a 2.1 mm power plug on it. The wire from the LED strings are connected to an electrical connector block.

Powered it up and it all worked well.

Only thing I may still change is making more difference in the interval for each LED string.

Well, that's my first instructable, hope it's useful to someone.