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

Arduino UNO Joystick-Controlled Traffic Light System

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

Circuit Documentation

Summary

This circuit is designed to control a traffic light system using a joystick module and an Arduino UNO. The joystick module allows the user to control the state of the traffic lights (red, yellow, and green LEDs) based on the direction the joystick is moved.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Traffic Light

    • Description: A module with three LEDs (Green, Yellow, Red) and a ground pin.
    • Pins: Green, Yellow, Red, GND
  3. Joystick Module

    • Description: A module with a joystick that provides analog outputs for X and Y axes and a digital output for a button press.
    • Pins: SW, VRY, VRX, VCC, GND
  4. Comment

    • Description: Placeholder for comments or notes in the circuit.
    • Pins: None

Wiring Details

Arduino UNO

Traffic Light

Joystick Module

Code Documentation

/*
 * 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 VRX_PIN = A0; // Joystick X-axis
const int VRY_PIN = A1; // Joystick Y-axis
const int SW_PIN = 7;   // Joystick button (not used)
const int RED_LED_PIN = 2;   // Red LED
const int YELLOW_LED_PIN = 3; // Yellow LED
const int GREEN_LED_PIN = 4;  // Green LED

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Set LED pins as outputs
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(YELLOW_LED_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);

  // Set joystick button pin as input
  pinMode(SW_PIN, INPUT);
}

void loop() {
  // Read joystick values
  int xValue = analogRead(VRX_PIN);
  int yValue = analogRead(VRY_PIN);

  // Determine joystick direction
  if (yValue < 300) { // Joystick moved up
    digitalWrite(RED_LED_PIN, HIGH);
    digitalWrite(YELLOW_LED_PIN, LOW);
    digitalWrite(GREEN_LED_PIN, LOW);
  } else if (xValue < 300) { // Joystick moved left
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(YELLOW_LED_PIN, HIGH);
    digitalWrite(GREEN_LED_PIN, LOW);
  } else if (xValue > 700) { // Joystick moved right
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(YELLOW_LED_PIN, LOW);
    digitalWrite(GREEN_LED_PIN, HIGH);
  } else if (yValue > 700) { // Joystick moved down
    digitalWrite(RED_LED_PIN, HIGH);
    digitalWrite(YELLOW_LED_PIN, HIGH);
    digitalWrite(GREEN_LED_PIN, HIGH);
  } else { // Joystick in neutral position
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(YELLOW_LED_PIN, LOW);
    digitalWrite(GREEN_LED_PIN, LOW);
  }

  // Small delay to stabilize readings
  delay(100);
}

This code initializes the pins for the joystick and the traffic light LEDs. It reads the joystick's X and Y values and turns on the corresponding LED based on the joystick's direction. The joystick button is not used in this sketch.