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

Arduino-Controlled Traffic Light System with Joystick Interface

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

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 has three LEDs (Red, Yellow, Green) that are controlled based on the joystick's position. The joystick's movements in different directions control which LED is turned on. The circuit is powered by the Arduino UNO, which also processes the input from the joystick to control the traffic light.

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 joystickVRXPin = A0;
const int joystickVRYPin = A1;

void setup() {
  // Initialize LED pins as outputs
  pinMode(redLEDPin, OUTPUT);
  pinMode(yellowLEDPin, OUTPUT);
  pinMode(greenLEDPin, OUTPUT);
  // Initialize joystick pins as inputs
  pinMode(joystickVRXPin, INPUT);
  pinMode(joystickVRYPin, INPUT);
}

void loop() {
  // Read joystick values
  int xValue = analogRead(joystickVRXPin);
  int yValue = analogRead(joystickVRYPin);

  // Determine joystick direction
  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);
  }
}

The code is written in Arduino sketch format (.ino) and is designed to be uploaded to the Arduino UNO microcontroller. It initializes the pins connected to the traffic light LEDs as outputs and the joystick's analog pins as inputs. The loop function continuously reads the joystick's position and turns on the corresponding LED(s) based on the direction the joystick is moved.