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

Arduino UNO Controlled Traffic Light System with Joystick Interface

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

Traffic Light Control System Documentation

Summary

The circuit described in this documentation is designed to control a traffic light system using an Arduino UNO microcontroller and a joystick module. The joystick's movements control the activation of the traffic light's LEDs: moving the joystick up activates the red LED, left for the yellow LED, and right for the green LED. Moving the joystick down activates all LEDs. The circuit utilizes digital and analog input/output pins on the Arduino to interface with the traffic light and joystick module.

Component List

Arduino UNO

Traffic Light

Joystick Module

Wiring Details

Arduino UNO

Traffic Light

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.
 */

// Pin definitions
const int VRX_PIN = A0; // Joystick X-axis
const int VRY_PIN = A1; // Joystick Y-axis
const int SW_PIN = 7;   // Joystick button (not used)
const int RED_LED_PIN = 2;   // Red LED
const int YELLOW_LED_PIN = 3; // Yellow LED
const int GREEN_LED_PIN = 4;  // Green LED

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Set LED pins as outputs
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(YELLOW_LED_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);

  // Set joystick button pin as input
  pinMode(SW_PIN, INPUT);
}

void loop() {
  // Read joystick values
  int xValue = analogRead(VRX_PIN);
  int yValue = analogRead(VRY_PIN);

  // Determine joystick direction
  if (yValue < 300) { // Joystick moved up
    digitalWrite(RED_LED_PIN, HIGH);
    digitalWrite(YELLOW_LED_PIN, LOW);
    digitalWrite(GREEN_LED_PIN, LOW);
  } else if (xValue < 300) { // Joystick moved left
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(YELLOW_LED_PIN, HIGH);
    digitalWrite(GREEN_LED_PIN, LOW);
  } else if (xValue > 700) { // Joystick moved right
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(YELLOW_LED_PIN, LOW);
    digitalWrite(GREEN_LED_PIN, HIGH);
  } else if (yValue > 700) { // Joystick moved down
    digitalWrite(RED_LED_PIN, HIGH);
    digitalWrite(YELLOW_LED_PIN, HIGH);
    digitalWrite(GREEN_LED_PIN, HIGH);
  } else { // Joystick in neutral position
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(YELLOW_LED_PIN, LOW);
    digitalWrite(GREEN_LED_PIN, LOW);
  }

  // Small delay to stabilize readings
  delay(100);
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the pins connected to the joystick and traffic light LEDs, reads the joystick's analog values, and sets the LEDs accordingly. The joystick's switch is not used in this application.