Saturday, January 22, 2011

Project 4 - Interactive Traffic Lights

Project 4 adds a few new components to the ones used in Project 3 - an additional red and green LED, more resistors, and a pushbutton.

I wired up the circuit but made a few changes from the ones seen on page 39. First, rather than move the existing red, green, and yellow LED wiring from its original positions in Project 3, I left them alone and instead inserted the new red and green LEDs to digital pins 12 and 11, respectively.

The pushbutton was connected to digital pin 2 as specified in the wiring diagram, and I removed the GND jumper wire (from the digital GND pin) and ran two wires, one from 5V+ and the other from GND (both in the Power section of the Arduino UNO). (If anyone can explain why the GND couldn't be left alone, please let me know... if you wire V+ (5 or 3.3) from the Power section, does that require that you also use the GND pin under the Power section? This wasn't explained...)

One other thing you might notice if you look carefully at the wiring diagram for Project 3 and compare it to Project 4 is the placement of the resistors. I didn't catch this at first, but in Project 3 the resistors are all wired up on the anode side of the LEDs... but in Project 4 they are wired up on the cathode side of the LEDs. My basic understanding of electronics tells me this isn't an issue... the resistance is applied in the circuit whether it's sitting in front of or behind of the LEDs. Current just "feels" the resistance and doesn't "care" whether the resistor is on the anode or cathode side of an LED. (Maybe I'm wrong, but the circuit does work with the LEDs left on the anode side of all the LEDs.)

Finally, I chose to use the author's supplied code this time rather than type it all in... all I had to do was go in and fix the integer variable values for the pins (see first screen capture). The other change to the author's code was the removal of the yellow light after the pedestrian light goes from green to red. In the USA, when the crosswalk starts blinking (warning pedestrians that it will change to Don't Walk) and finally turns to red, there's usually a slight pause before the traffic light (for cars) turns green. There is no yellow light that pops up for the cars, so I removed this from the code and the video below will demonstrate how the new code works. Note also in the video that just after the pedestrian light turns red, the pushbutton is disabled for 5 seconds - I push it a few times to try and trigger it but no luck.

The questions I encountered (and described above - use of Power section GND versus the digital pin GND and the placement of resistors on anode or cathode side of LEDs) are ones I will try and find answers to... I'd hate to damage my Uno by wiring up something improperly in future projects.

(Update: I ran down the checklist of items on page 49 to make certain I had an understanding of the list of Subjects/Concepts - all good.)


  1. Ground is ground I put my meter on it to see for sure. There is continuity between all the ground pins.

    I was short on resistors (too lazy to dig through the resistor box more truthfully) when I did this one, but from having done Mr. Platt's (Experiment 18), I knew I could get around that by connecting my ground rail to the Arduino's ground via a single resistor (I used 1K). Then I just connected all the cathodes to the ground rail and wired the pins to the anodes.

    This made the circuit faster and easier to wire, but it's not, I am told, best practice because when more than one of the LEDs is on, they appear slightly dimmer as did the 7 segment displays in Platt EX 18. Still when working within the limited confines of the breadboard, sometimes it's worth it to save a bit of space.

    I have one of the little prototyping shields as you mentioned, but I didn't like it so much for the experiments in this book. I like to build a circuit, then move an inch or so down the board and build the next one, leaving the first intact.

    So I bought a new breadboard for my Arduino experiments and I mounted it, and the Arduino to a strip of pegboard that I cut down to 10" x 3". I bought some 6" and 12" jumpers from Sparkfun, so I can easily connect a circuit to the Arduino even if it's at the far end of the breadboard.

  2. That's a nice trick with using a single resistor to make the ground connection... will have to remember that.

    Glad to hear the two GND pins on the Arduino are the same thing... makes me wonder why they did that (taking up a pin that could also have been used for something else).

    BTW, if you happened to have done Exp 33 or Exp 36 in the Make: Electronics book and took any photos or videos, please let me know... I'd love to be able to share them on the other blog.

  3. Jim,

    You'll find that Analog GND and digital GND are separated as they have been designed for different signal types and hence different noise characteristics. Digital 'expects' 0V and 5V (in reality I think the Atmel has anything under 1.3V as LOW) whereas the analog can expect anywhere between 0V and 5V. In good circuit design they are brought back together at the power regulator.

    In an ideal world, it shouldn't matter, but when is the world ever ideal :)

    Resistors above or below the LED's won't matter at all, they both experience the same amount of current.