Illuminated Cubes Using Atmega

Illuminated Cubes

Illuminated Cubes

This project is a follow up of the Illuminated Presents project that I posted earlier. My wife really liked the Illuminated Presents but kept them as Cubes and did not put a bow around it to turn them into presents. Because of this success I created a second one – called Illuminate Cubes since that is what they are – but now using different Cube sizes.

This version has the same functions as the previous project:

  • Control 2 Cubes at the same time using one PIC12F617 microcontroller. The microcontroller software was written in the JAL programming language
  • Switch the Cubes on and off using a push button
  • Randomly change the color of the Cubes by fade-in and fade-out of the colors red and green
  • Switch off the Cubes when the battery voltage drops below 3.0 Volt. This will prevent the rechargeable batteries from being discharged too much

After fading-in one color, the LED stays on for a time somewhere between 15 seconds and 30 seconds. Since I still had the unused blue LED I added the feature that both Cubes will turn blue when the on-time is exactly 20 seconds. This does not happen very often since the random time is generated in timer ticks of 40 milliseconds as described later.

The fading-in and fading-out uses Pulse Width Modulation (PWM) as explained in my previous project. Since the Cubes are of different sizes, I used 3 LEDs for the big Cube and 1 LED for the smaller Cube. In order to make both Cubes shine with the same brightness, I limited the maximum on-time of the PWM of both Cubes. Since the Cubes where a bit brighter than required, this brightness limitation also extends the operation of the – rechargeable – batteries.

Step 1: The Mechanical Work

The Mechanical Work

For making the Cubes I used the same milk white acrylic plastic and for the rest of the set-up I used MDF. As to prevent that you see the shape of the LED in the Cubes when the LED is on, I put a cover on top of the LEDs that diffuses the light from the LED. This time I made the cover by creating small Cubes using the same acrylic plastic. In the pictures you see the results.

Step 2: The Electronics

The Electronics 1

The schematic diagram shows the electronic components you need. Since I am using more LEDs for the bigger Cube I needed some transistors to drive them since the PIC cannot drive three LEDs on one port. The electronics is powered by a 3 AA(A) rechargeable batteries and can be powered on or off by pressing the reset switch.

You need the following electronic components for this project:

  • 1 * PIC microcontroller 12F617 with socket
  • 2 * Ceramic capacitors: 2 * 100nF
  • Resistors: 1 * 33k, 3 * 4k7, 4 * 68 Ohm, 8 * 22 Ohm
  • 4 * RGB LEDs, high brightness
  • 3 * BC558 transistor or equivalent
  • 1 * push button switch

You can build the circuit on a breadboard and does not require much space, as can be seen in the picture. You may wonder why the resistor values for controlling the maximum current through the LEDs are so low. This is because of the low supply voltage of 3.6 Volt in combination with the voltage drop that each LED has, which depends on the color per LED. With these resistor values and when the brightness it at its maximum the maximum current of the whole system is around 40 mA. I limited the maximum on-time as mentioned earlier so for this version the maximum current is less than 20 mA.

Step 3: The Software

The software performs the following tasks:

  • When the device is reset by the push button it will turn the device on if it was off or it turns the device off if it was on. Off means putting the PIC12F617 into sleep mode in which it hardly consumes any power.
  • Generate the PWM signal to control the brightness of the LEDs. This is done using a timer and an interrupt service routine that controls the pins of the PIC12F617 who on their turn the LEDs on and off.
  • Fade-in and fade-out the LEDs and keep them on for a random time between 15 and 30 seconds. If the random time equals 20 seconds, both LEDs will turn blue for 20 seconds after which the normal red-green fade-in and fade-out pattern is used.
  • During operation the PIC will measure the supply voltage using its on-board Analog to Digital Converter (ADC). When this voltage drops below 3.0 V, it will switch the LEDs off and will put the PIC into sleep mode again. The PIC could still operate well at 3.0 V but it is not good for the rechargeable batteries to be completely drained.

As mentioned earlier the PWM signal is created using a timer that uses an interrupt service routine as to keep a stable PWM signal. The fading-in and fading-out of the LEDs including the time the LEDs are on, is controlled by the main program. This main program uses a timer tick of 40 milliseconds, derived from the same timer that creates the PWM signal.

Since I did not use any specific JAL libraries for this project this time I had to make a random generator using a linear feedback shift register for generating the random on time and random off time of the LEDs.

The JAL source file and the Intel Hex file for programming the PIC are attached. I renamed the extension of the source file from ‘.jal’ to ‘.txt’ as to be able to upload it to Instructables.

Step 4: The Final Result

The final result can be seen in this video.

If you are interested in using the PIC microcontroller with JAL – a Pascal like programming language – visit the JAL website.

You can also watch the video on how to start with JAL.

Read more: Illuminated Cubes

Leave a Comment

Your email address will not be published. Required fields are marked *