Introduction
Ever wanted to build a traffic light but didn’t have the components handy? With Velxio, you can simulate an entire Arduino-based traffic light right in your browser. This project uses three LEDs (red, yellow, green) connected to an Arduino Uno to mimic the classic traffic light sequence: red → yellow → green → yellow → red. It’s a perfect beginner project to learn digital outputs, timing, and sequential logic.
Circuit Walkthrough
Let’s look at the circuit. The diagram below shows the complete wiring:

Components
- Arduino Uno – the brain of the operation.
- Red LED – connected to digital pin 13.
- Yellow LED – connected to digital pin 12.
- Green LED – connected to digital pin 11.
- Resistors – each LED needs a current-limiting resistor (typically 220Ω) in series with its anode. In Velxio, the built-in LEDs already have internal resistors, so you don’t need to add them manually.
Wiring Details
Each LED has two legs: anode (longer leg, marked as pin “A”) and cathode (shorter leg, marked as pin “C”). The wiring is straightforward:
- Red LED: Anode to Arduino pin 13 via a red wire (
#ff0000). Cathode to Arduino GND via a black wire. - Yellow LED: Anode to Arduino pin 12 via a yellow wire (
#ffaa00). Cathode to GND. - Green LED: Anode to Arduino pin 11 via a green wire (
#00ff00). Cathode to GND.
All three LEDs share the same GND connection on the Arduino. This is a common ground configuration.
Code Walkthrough
Now let’s examine the code that makes the lights change. Open the code editor in Velxio:

// Traffic Light Simulator
// Red -> Yellow -> Green -> Yellow -> Red
const int RED_PIN = 13;
const int YELLOW_PIN = 12;
const int GREEN_PIN = 11;
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(YELLOW_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
}
void loop() {
// Red light
digitalWrite(RED_PIN, HIGH);
delay(3000);
digitalWrite(RED_PIN, LOW);
// Yellow light
digitalWrite(YELLOW_PIN, HIGH);
delay(1000);
digitalWrite(YELLOW_PIN, LOW);
// Green light
digitalWrite(GREEN_PIN, HIGH);
delay(3000);
digitalWrite(GREEN_PIN, LOW);
// Yellow light again
digitalWrite(YELLOW_PIN, HIGH);
delay(1000);
digitalWrite(YELLOW_PIN, LOW);
}
How It Works
- Pin Definitions: We define constants for the three pins:
RED_PIN = 13,YELLOW_PIN = 12,GREEN_PIN = 11. These match the wiring. - Setup: In
setup(), we set all three pins asOUTPUTusingpinMode(). This tells the Arduino to send voltage out through these pins. - Loop: The
loop()function runs forever. It follows this sequence:- Turn red LED on (
HIGH), wait 3 seconds, turn it off (LOW). - Turn yellow LED on, wait 1 second, turn it off.
- Turn green LED on, wait 3 seconds, turn it off.
- Turn yellow LED on again, wait 1 second, turn it off.
- Then the loop repeats from the red light.
- Turn red LED on (
This creates the familiar traffic light pattern.
Key Concepts for Students
- Digital Outputs:
digitalWrite(pin, HIGH)sets a pin to 5V (on),LOWsets it to 0V (off). - Timing with
delay():delay(milliseconds)pauses the program. Be careful: whiledelay()runs, the Arduino can’t do anything else. - Sequential Logic: The order of operations matters. The code runs line by line, so the lights change in a predictable sequence.
- Common Ground: All LEDs share the same ground connection. This is typical in digital circuits.
Common Pitfalls and Debugging Tips
- Wrong Pin Numbers: Double-check that the pin numbers in the code match the wiring. If the red LED is on pin 13 but you wrote
12, it won’t light. - LED Orientation: LEDs are polarized. The anode (long leg) must connect to the Arduino pin, and the cathode (short leg) to GND. In Velxio, the LED component is correctly oriented by default.
- Missing Resistors: In real life, always use a current-limiting resistor (220Ω–1kΩ) in series with each LED to prevent damage. Velxio’s built-in LEDs include resistors, but if you use custom components, add them.
delay()Blocks: If you want to add buttons or sensors later,delay()will freeze the program. Consider usingmillis()for non-blocking timing.
Suggested Extensions
Once you have the basic traffic light working, try these enhancements:
- Add a Pedestrian Button: Use a push button to request a walk signal. When pressed, the traffic light changes to red, then a white LED (pedestrian walk) lights up.
- Use
millis()Instead ofdelay(): Rewrite the code to usemillis()for timing. This allows the Arduino to check for button presses while waiting. - Add a Buzzer: Connect a piezo buzzer to a pin and make it beep when the green light is about to turn yellow.
- Simulate a Crosswalk: Add two more LEDs (red and green) for a pedestrian crossing, and coordinate them with the traffic lights.
Try It Yourself
Ready to build your own traffic light? Open the example in Velxio and start experimenting:
Open Traffic Light Example on Velxio
You can edit the code, change the timing, or add more LEDs. The simulator runs entirely in your browser – no downloads, no hardware. Use the toolbar to compile and run your code:


If you need to add new components, open the component picker:

And if you want to use libraries, the Library Manager is just a click away:

Happy simulating!