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

Arduino-Controlled Traffic Light System with Joystick Interaction

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

Traffic Light Control Circuit Documentation

Summary

This circuit is designed to control a traffic light system using an Arduino UNO microcontroller and a joystick module. The traffic light system consists of three LEDs (red, yellow, and green) that represent the traffic signals. The joystick module is used to change the state of the traffic lights: moving the joystick up turns on the red LED, moving it left turns on the yellow LED, moving it right turns on the green LED, and moving it down turns on all LEDs. The circuit is powered by the Arduino UNO, which also processes the input from the joystick and drives the traffic light LEDs accordingly.

Component List

Traffic Light

Arduino UNO

Joystick Module

Wiring Details

Traffic Light

Arduino UNO

Joystick Module

Documented Code

/*
 * This Arduino sketch controls a traffic light system using a joystick module.
 * When the joystick is moved up, the red LED turns on.
 * When the joystick is moved left, the yellow LED turns on.
 * When the joystick is moved right, the green LED turns on.
 * When the joystick is moved down, all LEDs turn on.
 */

const int redLEDPin = 2;
const int yellowLEDPin = 3;
const int greenLEDPin = 4;
const int joystickSWPin = 7;
const int joystickVRXPin = A0;
const int joystickVRYPin = A1;

void setup() {
  pinMode(redLEDPin, OUTPUT);
  pinMode(yellowLEDPin, OUTPUT);
  pinMode(greenLEDPin, OUTPUT);
  pinMode(joystickSWPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  int vrxValue = analogRead(joystickVRXPin);
  int vryValue = analogRead(joystickVRYPin);
  bool swValue = digitalRead(joystickSWPin);

  if (vryValue < 300) { // Joystick moved up
    digitalWrite(redLEDPin, HIGH);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(greenLEDPin, LOW);
  } else if (vrxValue < 300) { // Joystick moved left
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, HIGH);
    digitalWrite(greenLEDPin, LOW);
  } else if (vrxValue > 700) { // Joystick moved right
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(greenLEDPin, HIGH);
  } else if (vryValue > 700) { // Joystick moved down
    digitalWrite(redLEDPin, HIGH);
    digitalWrite(yellowLEDPin, HIGH);
    digitalWrite(greenLEDPin, HIGH);
  } else { // Joystick in neutral position
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(greenLEDPin, LOW);
  }

  delay(100); // Small delay for debounce
}

This code is saved as sketch.ino and should be uploaded to the Arduino UNO microcontroller to operate the traffic light system as described.