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 of the Circuit

This circuit is designed to control a traffic light using an Arduino UNO and a joystick module. The joystick's movements control the state of the traffic light LEDs (Red, Yellow, Green). Moving the joystick up turns on the red LED, moving it left turns on the yellow LED, and moving it right turns on the green LED. Moving the joystick down turns on all LEDs. The joystick also has a switch that is not used in this circuit.

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

// Pin definitions
const int redLedPin = 2;
const int yellowLedPin = 3;
const int greenLedPin = 4;
const int vrxPin = A0;
const int vryPin = A1;
const int swPin = 7; // Not used in this circuit

void setup() {
  // Initialize LED pins as outputs
  pinMode(redLedPin, OUTPUT);
  pinMode(yellowLedPin, OUTPUT);
  pinMode(greenLedPin, OUTPUT);
  // Initialize joystick pins
  pinMode(vrxPin, INPUT);
  pinMode(vryPin, INPUT);
  pinMode(swPin, INPUT); // Not used in this circuit
}

void loop() {
  int vrxValue = analogRead(vrxPin);
  int vryValue = analogRead(vryPin);

  // Joystick moved up
  if (vryValue < 300) {
    digitalWrite(redLedPin, HIGH);
    digitalWrite(yellowLedPin, LOW);
    digitalWrite(greenLedPin, LOW);
  }
  // Joystick moved down
  else if (vryValue > 700) {
    digitalWrite(redLedPin, HIGH);
    digitalWrite(yellowLedPin, HIGH);
    digitalWrite(greenLedPin, HIGH);
  }
  // Joystick moved left
  else if (vrxValue < 300) {
    digitalWrite(redLedPin, LOW);
    digitalWrite(yellowLedPin, HIGH);
    digitalWrite(greenLedPin, LOW);
  }
  // Joystick moved right
  else if (vrxValue > 700) {
    digitalWrite(redLedPin, LOW);
    digitalWrite(yellowLedPin, LOW);
    digitalWrite(greenLedPin, HIGH);
  }
  // Joystick in neutral position
  else {
    digitalWrite(redLedPin, LOW);
    digitalWrite(yellowLedPin, LOW);
    digitalWrite(greenLedPin, LOW);
  }
  delay(100); // Small delay for debounce
}

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 (SW) is initialized but not used in the logic of this sketch.