Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO Controlled Traffic Light System with Joystick Interface

Image of Arduino UNO Controlled Traffic Light System with Joystick Interface

Traffic Light Control System Documentation

Summary

This document describes a traffic light control system that is designed to operate a set of traffic lights using an Arduino UNO microcontroller and a joystick module. The system allows the user to control the traffic lights by moving the joystick in different directions. Each direction corresponds to a different state of the traffic lights:

  • Moving the joystick up turns on the red light.
  • Moving the joystick left turns on the yellow light.
  • Moving the joystick right turns on the green light.
  • Moving the joystick down turns on all lights.

The system is designed for educational purposes to demonstrate basic input handling and output control using an Arduino.

Component List

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Purpose: Acts as the central processing unit for the traffic light control system, reading inputs from the joystick and controlling the output to the traffic lights.

Traffic Light

  • Description: A simple traffic light module with three LEDs (Green, Yellow, Red).
  • Purpose: Represents a traffic light system with three states controlled by the Arduino UNO.

Joystick Module

  • Description: An input module with a two-axis joystick and a push button.
  • Purpose: Provides user input to the Arduino UNO to control the traffic light states.

Wiring Details

Arduino UNO

  • A0: Connected to the VRX pin of the Joystick module (X-axis).
  • A1: Connected to the VRY pin of the Joystick module (Y-axis).
  • GND: Common ground with the Traffic Light and Joystick module.
  • D7: Connected to the SW pin of the Joystick module (not used in the current code).
  • D4: Connected to the Green LED of the Traffic Light.
  • D3: Connected to the Yellow LED of the Traffic Light.
  • D2: Connected to the Red LED of the Traffic Light.

Traffic Light

  • Green: Connected to D4 on the Arduino UNO.
  • Yellow: Connected to D3 on the Arduino UNO.
  • Red: Connected to D2 on the Arduino UNO.
  • GND: Connected to GND on the Arduino UNO.

Joystick Module

  • VRX: Connected to A0 on the Arduino UNO (X-axis).
  • VRY: Connected to A1 on the Arduino UNO (Y-axis).
  • SW: Connected to D7 on the Arduino UNO (not used in the current code).
  • GND: Connected to GND on the Arduino UNO.

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 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 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 input in the loop() function, and sets the LEDs accordingly. The joystick's switch (SW) is not used in this application.