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

Arduino UNO Controlled Traffic Light with Joystick Module

Image of Arduino UNO Controlled Traffic Light with Joystick Module

Circuit Documentation

Summary

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. 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 read by the Arduino but not used in the current code.

Component List

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Purpose: Acts as the central controller for the circuit, reading joystick inputs and controlling the traffic light LEDs.

Traffic Light

  • Description: A simple module with three LEDs (Green, Yellow, Red).
  • Purpose: Represents a traffic light controlled by the Arduino based on the joystick input.

Joystick Module

  • Description: An input device with two axes of control (VRX and VRY) and a pushbutton switch (SW).
  • Purpose: Provides user input to the Arduino to control the traffic light LEDs.

Wiring Details

Arduino UNO

  • 5V connected to Joystick Module VCC for power.
  • GND connected to Joystick Module GND and Traffic Light GND for common ground.
  • A0 connected to Joystick Module VRX for horizontal axis input.
  • A1 connected to Joystick Module VRY for vertical axis input.
  • D2 connected to Traffic Light Red LED control.
  • D3 connected to Traffic Light Yellow LED control.
  • D4 connected to Traffic Light Green LED control.
  • D7 connected to Joystick Module SW (unused in current code).

Traffic Light

  • Green connected to Arduino UNO D4.
  • Yellow connected to Arduino UNO D3.
  • Red connected to Arduino UNO D2.
  • GND connected to Arduino UNO GND.

Joystick Module

  • VCC connected to Arduino UNO 5V.
  • GND connected to Arduino UNO GND.
  • VRX connected to Arduino UNO A0.
  • VRY connected to Arduino UNO A1.
  • SW connected to Arduino UNO D7 (unused in current code).

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;

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);
}

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 saved as sketch.ino and is intended to be uploaded to the Arduino UNO microcontroller.