Arduino Coding Fundamentals: The Traffic Light

The result of J. Schaffer's (ACES '18) introduction to AutoDesk's EAGLE PCB Layout Application in the Winter of 2017 yielded a simple, but highly-effective, Printed Circuit Board (PCB), for a Traffic Light. We are the fortunate recipients of his design work as you're going to use this device to develop great Arduino coding skills.


51. Create the project, TLExercise51. Determine the value of the second parameter of the Arduino's analogWrite(pin,value) function that results in the red LED's brightness level that is consistent with the yellow and green LEDs. Test it in sequence with the other two LEDs, using an efficient code strategy, to confirm. Think.

50. Pulse-Width Modulation. You're acutely aware that the red LED appears brighter than the yellow or the green (a quick check of any LED datasheet confirms the reason) in this exercise we'll begin to explore how we can address the issue. First, Apple's Breathing LED.

  1. Use TL(11,12,13,GND). Open the Fade sketch (File > Examples > Basics). Change the led variable to 11. Upload the sketch and observe the effect the code has on the red LED.
  2. A few blogs have attempted to provide code for Apple's "patent" on the breathing LED effect. Try them out on pin 11 with the red LED. Sean Voisen, Breathing LED Circuit.

4. Variables

3. #define directive

2. A close examination of the Arduino pins suggests an optimum location for single Traffic Light.

1. (Hard code everything, no directives, no variables) (pinMode(), digitalWrite(), delay()) Insert your Traffic Light device into digital pins 4-7, facing outwards.

  1. Create a new sketch (it should have your changes from the previous step) and Save As TLExercise1 in your (personal) Arduino Project folder.
  2. Using the most basic programming concepts, do your best to develop the same sequence of lights that cycle through on a traffic light. Use reasonable delay intervals between states.

0. Go to File > Examples > Basics and open the BareMinimum sketch. Modify the comments to reflect our ACES conventions and save the sketch to your Desktop. At the Finder level, locate the BareMinimum.ino file on your Desktop, copy it, and use it to replace the file by the same name inside the Examples folder of your Arduino application.

Before you get to the software side of these exercises you'll need to solder up your Traffic Light. Your Parts Kit consists of the following components,

Solder the PCB together making sure to orient the LEDs, and male headers, correctly. To confirm you have a working Traffic Light, insert the device into your Arduino into pins 11,12,13 & GND. Upload the Blink Example. The green light should be flashing.