Arduino UNO Controlled Traffic Light System with Joystick Interface

Arduino UNO Traffic Light with Joystick Interface | MakeMindz
🚦 Part of the Traffic & Smart City Projects series — View all on MakeMindz →
Beginner · Traffic
🚦 Beginner Project · Analog Input

Arduino UNO Controlled Traffic Light System with Joystick Interface

✅ Beginner 📅 February 2026 ⏱ 8 min read 🛠 Arduino UNO · Joystick · 3 LEDs

Control a Red, Yellow, and Green traffic light manually using a joystick module and Arduino UNO. Push the joystick in different directions to switch signals — perfect for learning analog input, digital output, and conditional logic. Includes full diagram.json, wiring table, Arduino code, and a Wokwi simulation link.

Try on Wokwi Simulator (Free)

What This Project Does

This project simulates a real-world traffic signal using three LEDs and a joystick module. By reading the joystick's X and Y analog values (0–1023), the Arduino determines which direction the stick is pushed and activates the corresponding traffic light LED. It's one of the cleanest beginner projects for understanding analog-to-digital conversion, conditional logic, and multi-output GPIO control.

Traffic Light
(simulated)
⬅️

Joystick Left

🔴 Red ON
➡️

Joystick Right

🟢 Green ON
⬆️

Joystick Up

🟡 Yellow ON
🔘

Button Press

🔴🟡🟢 All ON

Key Features

🔴 Left → Red signal 🟢 Right → Green signal 🟡 Up → Yellow signal 🔘 Button → All LEDs on 📡 Analog input → digital output 💡 Beginner-friendly code

Joystick Analog Logic Explained

The joystick module outputs two analog voltages corresponding to X-axis and Y-axis position. Arduino's analogRead() converts these to 10-bit values (0–1023). The center position reads approximately 512 on both axes.

X-Axis (HORIZ — pin A0)

0–399
LEFT → 🔴 Red
400–600
Neutral
601–1023
RIGHT → 🟢 Green

Y-Axis (VERT — pin A1)

0–399
UP → 🟡 Yellow
400–600
Neutral
601–1023
No action

Complete Truth Table

Joystick ActionX ValueY ValueRed (pin 2)Yellow (pin 3)Green (pin 4)Signal
⬅️ Left< 400AnyHIGHLOWLOWSTOP
➡️ Right> 600AnyLOWLOWHIGHGO
⬆️ Up400–600< 400LOWHIGHLOWREADY
🔘 ButtonAnyAnyHIGHHIGHHIGHALL ON
⏺ Neutral400–600400–600LOWLOWLOWALL OFF
📌

Note: Red and Green are driven directly by digitalWrite(PIN_RED, x < 400) and digitalWrite(PIN_GREEN, x > 600), so both can technically be on simultaneously if X is very noisy. Yellow is driven by Y-axis up (y < 400). Button press overrides everything via return.


Components Required

🤖
Arduino UNO
Main controller
🕹️
Joystick Module
HORIZ: A0 · VERT: A1 · SEL: D7
🔴
Red LED
Signal: D2
🟡
Yellow LED
Signal: D3
🟢
Green LED
Signal: D4
Resistors (220Ω)
One per LED
🍞
Breadboard
For LED circuit
🔌
Jumper Wires
Male-to-male
🔋
USB Cable
Power + programming


 

Complete Wiring Guide

Joystick Module → Arduino

Joystick PinArduino PinWireNotes
VCC5VRedPower supply
GNDGNDBlackGround
HORIZA0BlueX-axis analog (left/right)
VERTA1GreenY-axis analog (up/down)
SELD7OrangeButton — INPUT_PULLUP, LOW when pressed

LED Circuit → Arduino

LEDAnode (+) via 220ΩCathode (−)Trigger
🔴 Red LEDDigital 2GNDJoystick Left (x < 400)
🟡 Yellow LEDDigital 3GNDJoystick Up (y < 400)
🟢 Green LEDDigital 4GNDJoystick Right (x > 600)
⚠️

Always use 220Ω resistors in series with each LED. Without them, excess current will damage the LEDs and Arduino GPIO pins. In Wokwi, resistors are included automatically when using the LED component.


Step-by-Step Wokwi Setup

  1. 1

    Open Wokwi and Create an Arduino Uno Project

    Go to wokwi.com, click "New Project", and select "Arduino Uno". The Uno board appears on the canvas ready to use.

  2. 2

    Paste diagram.json

    Click the diagram.json tab in Wokwi, select all existing text, and paste the JSON from the section below. The full circuit — Arduino, joystick, and three LEDs with resistors — loads instantly.

  3. 3

    Paste the Arduino Sketch

    Click the sketch.ino tab, select all, and paste the code from the Code section below. No extra libraries are needed.

  4. 4

    Press Play and Test

    Click the green ▶ Play button. The sketch compiles and runs. Click and drag the joystick knob left, right, or up to trigger the LEDs. Click the joystick button to turn all three on.

    Calibration tip: If your physical joystick reads different center values, adjust the thresholds (400 and 600) in the code to match your hardware.


diagram.json — Complete Circuit

Paste this into the diagram.json tab in Wokwi to instantly load the full circuit — Arduino Uno, joystick module, and three LEDs with resistors, all pre-wired.

JSON — diagram.json
{
  "version": 1,
  "author": "MakeMindz",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-uno", "id": "uno", "top": 100, "left": 0, "attrs": {} },
    { "type": "wokwi-analog-joystick", "id": "joystick", "top": 40, "left": -220, "attrs": {} },
    { "type": "wokwi-led", "id": "led-red", "top": -60, "left": 80, "attrs": { "color": "red" } },
    { "type": "wokwi-led", "id": "led-yellow", "top": -60, "left": 140, "attrs": { "color": "yellow" } },
    { "type": "wokwi-led", "id": "led-green", "top": -60, "left": 200, "attrs": { "color": "green" } },
    { "type": "wokwi-resistor", "id": "r1", "top": 20, "left": 80, "attrs": { "value": "220" } },
    { "type": "wokwi-resistor", "id": "r2", "top": 20, "left": 140, "attrs": { "value": "220" } },
    { "type": "wokwi-resistor", "id": "r3", "top": 20, "left": 200, "attrs": { "value": "220" } }
  ],
  "connections": [
    [ "joystick:VCC",   "uno:5V",          "red",    [] ],
    [ "joystick:GND",   "uno:GND",         "black",  [] ],
    [ "joystick:HORIZ", "uno:A0",          "blue",   [] ],
    [ "joystick:VERT",  "uno:A1",          "green",  [] ],
    [ "joystick:SEL",   "uno:7",           "orange", [] ],
    [ "uno:2",          "r1:1",            "red",    [] ],
    [ "r1:2",           "led-red:A",       "red",    [] ],
    [ "led-red:C",      "uno:GND",         "black",  [] ],
    [ "uno:3",          "r2:1",            "yellow", [] ],
    [ "r2:2",           "led-yellow:A",    "yellow", [] ],
    [ "led-yellow:C",   "uno:GND",         "black",  [] ],
    [ "uno:4",          "r3:1",            "green",  [] ],
    [ "r3:2",           "led-green:A",     "green",  [] ],
    [ "led-green:C",    "uno:GND",         "black",  [] ]
  ]
}

How to use: In Wokwi, click the diagram.json tab at the top of the editor, select all text, and paste. The circuit loads instantly with all connections ready.


Arduino Code — Complete Sketch

Paste this into the Wokwi code editor or Arduino IDE. No additional libraries needed — just the built-in Arduino functions.

Arduino C++ — sketch.ino
const int PIN_RED    = 2;
const int PIN_YELLOW = 3;
const int PIN_GREEN  = 4;
const int PIN_HORIZ  = A0;
const int PIN_VERT   = A1;
const int PIN_SEL    = 7;

void setup() {
  pinMode(PIN_RED,    OUTPUT);
  pinMode(PIN_YELLOW, OUTPUT);
  pinMode(PIN_GREEN,  OUTPUT);
  pinMode(PIN_SEL,    INPUT_PULLUP);  // joystick button
}

void loop() {
  int x = analogRead(PIN_HORIZ);  // 0-1023, center ~512
  int y = analogRead(PIN_VERT);   // 0-1023, center ~512
  bool pressed = (digitalRead(PIN_SEL) == LOW);

  // Push button -> all LEDs on
  if (pressed) {
    digitalWrite(PIN_RED,    HIGH);
    digitalWrite(PIN_YELLOW, HIGH);
    digitalWrite(PIN_GREEN,  HIGH);
    return;
  }

  // Left/right -> Red or Green
  digitalWrite(PIN_RED,   x < 400);   // joystick left
  digitalWrite(PIN_GREEN, x > 600);   // joystick right

  // Up -> Yellow
  digitalWrite(PIN_YELLOW, y < 400);  // joystick up
}
🚀

Extend it: Add a Serial.begin(9600) in setup and Serial.println(x) in loop to watch live joystick values in the Serial Monitor — great for calibrating thresholds.


Ways to Extend This Project

Countdown timer on 7-segment or LCD
Pedestrian crossing push-button
Buzzer alert on signal change
IoT smart traffic monitoring (ESP32)
Auto mode using HC-SR04 traffic sensor
Second joystick for dual-junction control

More Arduino & IoT Projects on MakeMindz

Comments

try for free