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 System Documentation

Summary

The circuit described herein 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 activates the red light, left for the yellow light, right for the green light, and down for all lights. The system is programmed to respond to the joystick's position and update the traffic lights 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.
 */

// Pin definitions
const int redLedPin = 2;
const int yellowLedPin = 3;
const int greenLedPin = 4;
const int joystickXPin = A0;
const int joystickYPin = A1;
const int joystickSwPin = 7;

void setup() {
  // Initialize LED pins as outputs
  pinMode(redLedPin, OUTPUT);
  pinMode(yellowLedPin, OUTPUT);
  pinMode(greenLedPin, OUTPUT);
  // Initialize joystick switch pin as input
  pinMode(joystickSwPin, INPUT);
  // Start serial communication for debugging
  Serial.begin(9600);
}

void loop() {
  // Read joystick values
  int xValue = analogRead(joystickXPin);
  int yValue = analogRead(joystickYPin);
  int swValue = digitalRead(joystickSwPin);

  // Debugging output
  Serial.print("X: ");
  Serial.print(xValue);
  Serial.print(" Y: ");
  Serial.print(yValue);
  Serial.print(" SW: ");
  Serial.println(swValue);

  // Determine LED states based on joystick position
  if (yValue < 300) { // Joystick moved up
    digitalWrite(redLedPin, HIGH);
    digitalWrite(yellowLedPin, LOW);
    digitalWrite(greenLedPin, LOW);
  } else if (xValue < 300) { // Joystick moved left
    digitalWrite(redLedPin, LOW);
    digitalWrite(yellowLedPin, HIGH);
    digitalWrite(greenLedPin, LOW);
  } else if (xValue > 700) { // Joystick moved right
    digitalWrite(redLedPin, LOW);
    digitalWrite(yellowLedPin, LOW);
    digitalWrite(greenLedPin, HIGH);
  } else if (yValue > 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);
  }

  // Small delay to avoid bouncing
  delay(100);
}

This code is responsible for reading the joystick's position and updating the state of the traffic lights accordingly. It includes serial communication for debugging purposes, allowing the user to monitor the joystick's values in real-time.