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

Arduino UNO Controlled Traffic Light with Joystick Module

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

Circuit Documentation

Summary

This circuit is designed to control a traffic light using an Arduino UNO and a joystick module. The traffic light has three LEDs (red, yellow, and green) that are controlled by the joystick's position. When the joystick is moved in different directions, the corresponding LED lights up on the traffic light. The joystick also has a built-in switch that can be used for additional input if needed.

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 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 redLED = 2;       // Connects to the red LED on the traffic light
const int yellowLED = 3;    // Connects to the yellow LED on the traffic light
const int greenLED = 4;     // Connects to the green LED on the traffic light
const int joystickSW = 7;   // Connects to the switch on the joystick
const int joystickVRX = A0; // Connects to the X-axis on the joystick
const int joystickVRY = A1; // Connects to the Y-axis on the joystick

void setup() {
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(joystickSW, INPUT);
  Serial.begin(9600);
}

void loop() {
  int xValue = analogRead(joystickVRX);
  int yValue = analogRead(joystickVRY);
  Serial.print("X: ");
  Serial.print(xValue);
  Serial.print(" Y: ");
  Serial.println(yValue);

  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);
  }
  delay(100);
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the pins connected to the LEDs and joystick, reads the joystick's analog values, and controls the traffic light LEDs based on the joystick's position. Serial output is provided for debugging purposes.