Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Controlled Traffic Light with Joystick Interface

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Traffic Light with Joystick Interface

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a traffic light using a joystick module interfaced with an Arduino UNO microcontroller. The joystick's position determines which LED on the traffic light is illuminated. Moving the joystick up activates the red LED, left for the yellow LED, right for the green LED, and down for all LEDs. When the joystick is in the neutral position, all LEDs are turned off.

Component List

Joystick Module

Arduino UNO

Traffic Light

Wiring Details

Joystick Module

Arduino UNO

Traffic Light

Documented Code

/*
 * This Arduino sketch controls a traffic light using a joystick module.
 * - Moving the joystick up turns on the red LED.
 * - Moving the joystick left turns on the yellow LED.
 * - Moving the joystick right turns on the green LED.
 * - Moving the joystick down turns on all LEDs.
 */

const int redLED = 2;       // Traffic Light Red LED
const int yellowLED = 3;    // Traffic Light Yellow LED
const int greenLED = 4;     // Traffic Light Green LED
const int joystickVRX = A0; // Joystick Horizontal Axis
const int joystickVRY = A1; // Joystick Vertical Axis

void setup() {
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(joystickVRX, INPUT);
  pinMode(joystickVRY, INPUT);
}

void loop() {
  int xValue = analogRead(joystickVRX);
  int yValue = analogRead(joystickVRY);

  if (yValue < 300) { // Joystick moved up
    digitalWrite(redLED, HIGH);
    digitalWrite(yellowLED, LOW);
    digitalWrite(greenLED, LOW);
  } else if (xValue < 300) { // Joystick moved left
    digitalWrite(redLED, LOW);
    digitalWrite(yellowLED, HIGH);
    digitalWrite(greenLED, LOW);
  } else if (xValue > 700) { // Joystick moved right
    digitalWrite(redLED, LOW);
    digitalWrite(yellowLED, LOW);
    digitalWrite(greenLED, HIGH);
  } else if (yValue > 700) { // Joystick moved down
    digitalWrite(redLED, HIGH);
    digitalWrite(yellowLED, HIGH);
    digitalWrite(greenLED, HIGH);
  } else { // Joystick in neutral position
    digitalWrite(redLED, LOW);
    digitalWrite(yellowLED, LOW);
    digitalWrite(greenLED, LOW);
  }
}

The code is structured to continuously read the analog values from the joystick's VRX and VRY pins to determine its position. Depending on the position, the corresponding LED on the traffic light is activated. The setup() function initializes the pins, and the loop() function contains the logic for reading the joystick input and controlling the LEDs.