Traffic Lights LEDLevel: beginner
As we have seen in our first LED tutorial, it is very easy to make a LED to flash. Here we will simulate a traffic light behaviour with 3 LEDs. You can refer to our first LED tutorial on how make a flashing LED.
Remember LED driving voltage of the LED is typically within the range of 2.2-3.4V, but the Basic Commander has a driving voltage of 5v. To avoid damage to the LED, we need to add one resistor (R1, R2, R3) for each one of the LEDs.
On the Education Board, connect the 3 resistors to pin 4, 5 and 6 respectively. Then the Red, Green and Yellow LED to the same ports as the resistors. Remember to use the long lead (positive) to connect to pins and the short lead to ground as shown on fig. above. Finish with the jumper wire for each LED connecting to the common ground.
Here is the circuit diagram for the traffic lights.
Making them flash
To make the LED to flash on the Education Board, we will modify the LED program. First we turn the red LED light on and keep the other two off. Then we keep it on for 3 sec (3000ms) before swtich to yellow. When it turns yellow, we keep it on for 1 sec like in the traffic light. Finally, we switch green light on and turn off the red and yellow. We use the Pause command to give the effect of blinking. In this example, we use the Do-Loop to continuously keep the traffic lights flashing until the power is off. Again, you need to change the pin number if your components are on different pin or port.
Sub MAIN() Do High 4 ' turn on red on pin 4 Low 5 ' turn off yellow on pin 5 Low 6 ' turn off green on pin 6 Pause 3000 ' wait 3000 ms (3 sec) Low 4 High 5 ' turn on yellow Low 6 Pause 1000 ' keep it on briefly Low 4 Low 5 High 6 ' turn on green Pause 3000 ' keep it on for 3 sec Loop End sub
Putting them together
Now we are ready to test the code with the circuit. Remember to turn the power swtich on the Education Board to position 2 after downloading the code to the Basic Commnader. If it does not work, one way to debug your program is to test one small portion at a time. For example, test one LED at a time. If it still doesn't work, check the hardware and make sure the wires are connected correctly.
All parts are included in the Explorer Kit.
What is next?
This is one way to write a program in innoBasic for the LED traffic lights. If you have another way to mimic a flashing traffic light, we love to hear from you. Submit your code and comments to or post your suggestions on our Forum.
FAQ | Terms & Conditions | Contact Us