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

Arduino UNO Controlled Traffic Light with Joystick Interface

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

Circuit Documentation

Summary of the Circuit

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, when pressed, turns on all the LEDs. The Arduino UNO reads the analog values from the joystick's potentiometers to determine its position and controls the LEDs accordingly.

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 redLedPin = 2;
const int yellowLedPin = 3;
const int greenLedPin = 4;
const int joystickXPin = A0;
const int joystickYPin = A1;
const int joystickButtonPin = 7;

void setup() {
  pinMode(redLedPin, OUTPUT);
  pinMode(yellowLedPin, OUTPUT);
  pinMode(greenLedPin, OUTPUT);
  pinMode(joystickButtonPin, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  int xValue = analogRead(joystickXPin);
  int yValue = analogRead(joystickYPin);
  bool buttonPressed = digitalRead(joystickButtonPin) == LOW;

  // Reset all LEDs
  digitalWrite(redLedPin, LOW);
  digitalWrite(yellowLedPin, LOW);
  digitalWrite(greenLedPin, LOW);

  if (yValue < 300) { // Joystick moved up
    digitalWrite(redLedPin, HIGH);
  } else if (xValue < 300) { // Joystick moved left
    digitalWrite(yellowLedPin, HIGH);
  } else if (xValue > 700) { // Joystick moved right
    digitalWrite(greenLedPin, HIGH);
  } else if (yValue > 700) { // Joystick moved down
    digitalWrite(redLedPin, HIGH);
    digitalWrite(yellowLedPin, HIGH);
    digitalWrite(greenLedPin, HIGH);
  }

  delay(100); // Small delay for debounce
}

This code is saved in a file named "norlis afni 2 point 0.ino". It initializes the pins connected to the traffic light LEDs and the joystick module. In the main loop, it reads the analog values from the joystick to determine its position and sets the corresponding LED pins to HIGH to turn on the LEDs. The joystick's switch is used to turn on all LEDs when pressed. The code includes a small delay to debounce the joystick input.