You Are Here: Home » AVR ATmega Projects » Heart of LEDs using microcontroller

Heart of LEDs using microcontroller




One of the requests we received after publication of the Christmas Star was “can you do different shapes?” Well, with Mother’s Day coming up soon, we thought a heart would be appropriate. Now you can have something different to give to that special Mum or Grandmother. Or you may be able to redeem yourself if you forgot St Valentines Day! Either way, the Heart will certainly last a lot longer than the traditional bunch of flowers!

For those who don’t like microcontroller projects, pretend the micro is a dedicated LED driver IC that just happens to have been designed to control 30 LEDs in the shape of a Heart (what a stroke of luck!). And it won’t be declared obsolete just after publication like a purpose designed IC might be!

As the design is derived from the Christmas Star, those readers who saw that article will notice that the schematic is very similar. The major differences between the Heart and the Star are in the physical layout of the LEDs and in the software.

Why use a Microcontroller?

Using a PC parallel port to control external devices is a popular approach these days but imagine the response when you present Mum with a flashing Heart attached to an umbilical cable running into the next room! No, self- contained is better. The answer is to use a small microcontroller. They are cheap and easy to use. And if the software doesn’t work first time (when does it?), you simple change the program and re-program the micro.

Also, you can easily create something using a micro that is the equivalent of many discrete logic chips. In this case, the circuit is simple enough to build on VeroBoard ™ though it is much easier to use a printed circuit board. To do the Heart in discrete logic would be a ‘challenge’ (pronounced nightmare)!

Given a few inexpensive software tools, a microcontroller such as the Atmel AT89C2051 should be just as easy to use as a handful of 4000-series CMOS chips. In my experience, the micro is usually easier and results in a more flexible design!

Another reason for using a micro is that micros are the future of electronics. While it is useful to know how to design with 4000-series logic, most new products require more than can be easily done in discrete logic. Virtually all the electronic gadgets that we now rely on (microwave ovens, mobile phones, TVs, VCRs, video cameras, fax machines, etc) use micros to perform their tasks.

So what’s in a ‘2051?

The Atmel AT89C2051 is a relatively recent derivative of Intel’s “industry standard” 8051. It includes the following features:

  • 20 pin skinny-DIP plastic package
  • 2k bytes of Flash program memory
  • 128 bytes of RAM
  • 15 programmable I/O lines
  • on-chip oscillator (24MHz max)
  • two 16 bit counter/timers
  • six interrupt sources
  • a full duplex serial port (UART)
  • the I/O pins can sink 20mA for directly driving LEDs
  • two I/O pins are connected to an on-chip analogue comparator

As the program memory is re-programmable Flash with 1000 erase/write cycles, the annoyance of erasing EPROMs no longer exists. Software development is now that much more convenient.

The Hardware

The heart of the hardware is, of course, the Atmel ‘2051 micro. To make it start predictably, we need a reset circuit consisting of C7. D2 forces C7 to discharge quickly when power is removed. To set how fast it thinks, we need an external crystal X1 and associated capacitors C1 and C2. Note that the specified crystal could be replaced by a ceramic resonator or crystal in the 10MHz to 12MHz range without any significant change in performance. If you use a resonator with built-in capacitors, omit C1 and C2. At 12MHz, the ‘2051 will execute an instruction every 1 or 2us.

As you can see from the schematic, the 30 LEDs are connected in an X-Y matrix. Why 30 LEDs? Engineering is full of compromises. I wanted two ‘concentric’ hearts as more interesting patterns would be possible. I achieved equal LED spacing with 16 LEDs in the outer Heart and 14 in the inner one and this “looked about right”. More LEDs may have looked better but would have pushed up the cost and needed a more complicated PCB.

We can drive 30 LEDs from only 11 I/O pins using a process called multiplexing. The appropriate combination of LEDs in a column is switched on for a short time (about 2ms in this case). This process is repeated for each column in turn taking 10ms for a full cycle. Provided the multiplexing is done quickly enough, the persistence of the human eye “fills in the gaps” and we see any combination of LEDs on without any flicker. The minimum practical multiplexing frequency is about 100Hz which is the frequency used by the Heart.

The power supply uses a common 7805 three terminal regulator with bypass capacitors C4 and C5. Diode D1 provides insurance against a reverse polarity power supply. The maximum current drawn by the star is about 140mA with all LEDs on but less than about 50mA for most patterns. The maximum temperature rise of the 7805 when the star is run from a typical 9Vdc unregulated plug-pack is less than 30 degrees which is quite acceptable. It gets a little warmer when run from a 12Vdc unregulated plug-pack though it does not require a heatsink if bolted to the PCB..

Battery Operation

One question asked about the Christmas Star project was “can I run it on batteries?” Of course you can but you have to be careful depending on the actual batteries (and the voltage) used. Four alkaline cells will give about 6V which is fine if you remove the 7805 regulator and fit a wire link from it’s input to it’s output (outside 2 pins). Four NiCd cells are Ok too. Depending on their charge, the voltage will be between about 5.4V and 4.8V. Be very careful with SLA (Sealed Lead Acid) batteries which will charge to about 7V. Remove the regulator but use a 1N4002 diode instead of the link. Do not remove diode D1. The maximum operating supply voltage for the microcontroller is 6V (absolute max is 7V).

The Software

As with the Christmas Star, we are making the basic source code for the Heart available for free (you may download it from our Web site)! An extended version that uses the EEPROM for storage may be available (if I get enough spare time!). Or maybe a reader would like to try. The software is written in the C language using the low cost Dunfield Development Systems Micro/C compiler. There is nothing particularly “smart” or “tricky” about the software – it was written to be easy to understand and to encourage use of small micros. Consequently, there are no interrupt routines and no use of the counter/timers, the UART or the comparator though Micro/C can make use of these resources.

The software is table driven. This means that the display patterns and sequences are determined by data stored in a table (an array of bytes). There is a simple interpreter that scans through the table to perform the specified operations. The defined byte values are listed in the following table. Note that the software for the Heart is a little smarter than for the Star – so it can do more complex pattern sequences.

Byte value or rangeOperation
01 to 30 (0x01 to 0x1e)Turn on LED 1 to 30
33 to 62 (0x21 to 0x3e)Turn off LED 1 to 30
64 to 94 (0x41 to 0x5e)Turn on LED 1 to 30 and do current delay
97 to 126 (0x61 to 0x7e)Turn off LED 1 to 30 and do current delay
128 to 159 (0x80 to 0x9f)Define a subroutine
160 to 195 (0xa0 to 0xbf)Call a subroutine
196 (0xc0)Go back to byte after loop start
197 to 207 (0xc1 to 0xcf)Loop start, count = byte & 0x0f
208 (0xe0)Delay (use last delay count), each count = 50ms
209 to 239 (0xe1 to 0xef)Delay, count = byte & 0x0f, each count = 50ms
252 (0xfc)Return from subroutine
253 (0xfd)All LEDs on
254 (0xfe)All LEDs off
255 (0xff)End of table

 

For more detail: Heart of LEDs using microcontroller

Leave a Comment

You must be logged in to post a comment.

Read previous post:
Atmel atmega128 clock ds1307 tda5410 hard disk using atmega128 microcontroller

Previously called " Corrupted HDD Evaluate under the heading "corrupted hard disks to evaluate the application, I mentioned a couple of hours...

Close
Scroll to top