mood lamp - part 3 - schematics

Ready to get to the real stuff? In comes the schematics!

All these have been done with Fritzing, a circuit design tool for Arduino users and beginners in general.
While it is still in alpha phase and therefore has quite a few annoying bugs, it is definitely usable and easy to use.

Anyway, here is the breadboard view of the design:


Here is a deep link the file in full resolution for easier viewing.

A little hint to new Fritzing users: save often, and manually back up the sketch's file after each save, as you might loose all the wiring after a crash. I'm speaking of experience here. OK, back to topic.

The layout looks very different to the picture of the breadboard from part 1.
This is caused by two thing:

  1. I tried to make it look cleaner than the actual implemention on the breadboard.
  2. Some parts are currently not in the Fritzing library.
So, let's look at the differences:
  • The most important difference are the 7 segment LED displays. These were not available at all in the library, so I had to use "mystery" parts. These are the black boxes at the top, featuring a question mark. The mystery parts have all their pins on one side of the part, while the physical ones I use have them on two sides (top and bottom). This actually made wiring in Fritzing a lot easier and cleaner.
  • The RGB LED has been substituted by 3 individual LEDs in the appropriate colors.
  • The linear sliding potentiometer has been substituted by a linear rotary shaft potentiometer.
  • The pictured resistors are not exactly the same value I used, but they should be close enough to work as well (unless I made a mistake in Fritzing that is, which I did, read below).
All the connections are the same as in the breadboard implementation (and in the code).

Let's look at the bottom part first:



  • The 3 LEDs (which equal the RGB LED on the breadboard) are connected to ground with their cathodes, and to digital pins 9 to 11 with their anodes, which are PWM capable and control the brightness of each color using that feature. Between the anodes and the Arduino pins are the obligatory current limiting resistors. While the picture shows 220k ohm parts (a mistake), I actually use 220 ohm resistors! Although using 220k ohm will not damage anything, you will not get any light at all!
  • The potentiometer is connected to ground with one leg, and to +5V with the other. The wiper is connected to analog input pin 0. This forms a voltage divider as explained here. Simplified, this means that the wiper gets "closer" to +5V or ground if you turn the knob (or slide the slider) in one direction or the other, and therefore the voltage reading changes.
  • The buttons are connected as described in part 2, but I'll give it another shot from the Arduino's perspective:
    Above the buttons, there are two "pull up" resistors (in the picture they have 22k ohm, which is OK. I use 19,5k ohm, just because I had them laying around. Anything 10-25k ohm will work just fine). The resistors are connected to +5V on the one side, and to an analog pin on the Arduino on the other. The overall voltage over a resistor is +5V, so it "pulls up" the input pin of the Arduino to +5V as well, resulting in a maximum reading for the pin (1023 in the Arduino's case).
    UPDATE: I learned that you can use the analog pins exactly the same like the digital pins, using digitialRead and digitalWrite. Yes, even output is possible, and there is no need to use analogRead on input mode. (Even the build-in pullups should work exactly like the digital input pins, but I didn't test that.)
    Now, take a close look at the buttons: They are connected directly to the same analog pins of the Arduino. The resistors are not between the buttons and the pins, put between the buttons and the +5V pin. On the other side, the buttons are connected to ground. When you press a buttons and the connection in the button closes, two things happen:


    1. The input pin on the Arduino get "pulled" to ground, because it is directly connected to the button, which is connected to ground. This results in a reading of 0.
    2. The +5V is connected to ground as well, with just the resistor between ground and the +5V pin. All current is going through the button to ground. We chose a high resistance for the resistor to limit this current, to not waste power or risk damaging the Arduino. The same goes for the case when the button is open (unpressed), the resistors will limit the current to a tiny value, and almost no power is wasted (for a 22k ohm resistor that's 1.15 mW, assuming no resistance in the Arduino's input pins. Each LED uses about 20 times that much power.)


So much for the input of the mood lamp , if you still got any question leave me a comment.

On to the juicy part, the 7 segment displays!



  • The black boxes on top are simply supplements for the 7 segment LED displays, which are not available in the Fritzing library at the moment. The actual parts are used have half of their pins on top, and the other half on the bottom of the casing. The boxes don't, what makes wiring them up a lot cleaner. I used the same pin outs though, from 1 on the bottom left to 10 on the bottom right.

    Of the 10 pins, only 8 are used here. 7 pins are used to control the individual LEDs that are hidden in the display. The 8th pin is common cathode of the LEDs, which is connected to a transistor (more on that later). The 2 unused pins are for the decimal dot that available in my displays, and a second pin to ground.

    The vertical lines of gray wire simply replicate the 7 control pins of each display element down to two more rows of the breadboard, to make the wiring easier and to look cleaner.
    Each control pin of the first display element is connected to the same control pin of the other three elements by the seemingly continuous horizontal wires in green, white, orange, yellow and blue (e.g. pin1 on element 1 is connected to pin 1 of elements 2, 3 and 4).

  • On the lower left of the breadboard, there are 7 resistors (680 ohm) connected to the 7 control pins of display element 1 (and therefore to the control pins of the all the other elements as well). On the other end, the resistors connect to 7 digital pins of the Arduino (pin 2 to 7 and pin 13). As with the LEDs, these resistors are simply current limiting resistors, protecting the LEDs inside the display elements.

    Now we can control the individual bars of the 7 segment displays with the Arduino via the digital pins. If the display elements were all connected to ground, all four would light up the same. That is not what we want. Transistors to the rescue!
     
  • Transistors work like digital switches, by applying the right voltage (and amperage) on one of the pins (called base), current can flow through the other two pins (called collector and emitter).
    In this case I used NPN transistors, which are opened by applying positive voltage to the base. This leads to the following circuit:

    The emitter pin is connected directly to ground. The collector pin is connected to the ground pin.When the transistor is not triggered, the connection to ground is broken and no current can flow, and the display element remains dark. When the transistor is triggered via the base pin, the connection "closes" and current can flow from the Arduino pins through the display element and back to ground, lighting up the LEDs in the display. Neat, isn't it?

    The 4 transistor's bases are connected to the Arduino's digital pins 0,1,8 and 12 through resistors (pictured: 4.7k ohm, I use 5.1k ohm), limiting the current flowing through each base.
    By switching only one display element on via the transistors, and setting the output on the control pins to the desired values, we can show a number on the display.
    Thanks to persistence of vision, if we switch off the display element, change the control pins' values, and switch the next display element on, we can make it look like as if all display elements where on at the same time, and still show different numbers on each display! How sweet is that?
As a final goody, here is a schematic view of the whole thing. It's pretty bad though, partly because of me, but mostly because Fritzing's auto routing and export is pretty bad at the moment. I needed to re-route pretty much everything, and it didn't want to export the labels and left seams between parts and connectors.
I will make the Fritzing file available later on, along with the last part of the series (and the code).


Deep link

This concludes the hardware part. Wow, long post. Thank you for reading it all.
The next, and final, part will be the Arduino sketch code, but it needs a bit of a clean up first.

Update:
Part 4 is available: mood lamp - part 4 - the code

1 comments for this post

This high power led mood light is based on PIC16F628 and the ability of this mcu to produce PWM pulses. Varying pulse width we can produce millions of color combinations using only the three basic colors.

Posted on June 21, 2011 at 4:46 AM  

Post a Comment