Arduino UNO Controlled Traffic Light System with Joystick Interface
View and Edit Project In Cirkit Designer
Traffic Light Control System Documentation
Summary
This document describes a circuit designed to control a traffic light system using an Arduino UNO and a joystick module. The traffic light system consists of three LEDs (Green, Yellow, and Red) that are controlled by the position of the joystick. The joystick module provides analog input to the Arduino, which then drives the LEDs based on the joystick's position. The system is designed to respond to the following joystick movements:
- Move joystick up: Red LED turns on
- Move joystick left: Yellow LED turns on
- Move joystick right: Green LED turns on
- Move joystick down: All LEDs turn on
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Purpose: Acts as the central controller for the traffic light system, reading inputs from the joystick module and driving the traffic light LEDs.
Traffic Light
- Description: A simple traffic light module with three LEDs (Green, Yellow, Red).
- Purpose: Represents a traffic light, with each LED controlled by the Arduino to display the traffic signal.
Joystick Module
- Description: An input module with a two-axis analog joystick and a pushbutton.
- Purpose: Provides user input to the Arduino to control the traffic light LEDs.
Wiring Details
Arduino UNO
- 5V: Provides power to the joystick module.
- GND: Common ground for the Arduino, joystick module, and traffic light.
- A0: Connected to the VRX pin of the joystick module to read the horizontal position.
- A1: Connected to the VRY pin of the joystick module to read the vertical position.
- D7: Connected to the SW pin of the joystick module to read the pushbutton state.
- 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: Controlled by Arduino pin D4.
- Yellow: Controlled by Arduino pin D3.
- Red: Controlled by Arduino pin D2.
- GND: Shared ground with the Arduino.
Joystick Module
- SW: Connected to Arduino pin D7 to detect button presses.
- VRY: Connected to Arduino pin A1 to read the vertical position.
- VRX: Connected to Arduino pin A0 to read the horizontal position.
- VCC: Powered by Arduino's 5V output.
- GND: Shared ground with the Arduino.
Documented Code
/*
* This Arduino sketch controls a traffic light system using a joystick module.
* The traffic light has three LEDs: Green, Yellow, and Red. The joystick
* module is used to control the LEDs as follows:
* - Move joystick up: Red LED turns on
* - Move joystick left: Yellow LED turns on
* - Move joystick right: Green LED turns on
* - Move joystick down: All LEDs turn on
*/
// Pin definitions
const int greenLEDPin = 4;
const int yellowLEDPin = 3;
const int redLEDPin = 2;
const int joystickVRXPin = A0;
const int joystickVRYPin = A1;
const int joystickSWPin = 7;
void setup() {
// Initialize the LED pins as outputs
pinMode(greenLEDPin, OUTPUT);
pinMode(yellowLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
// Initialize the joystick pins
pinMode(joystickVRXPin, INPUT);
pinMode(joystickVRYPin, INPUT);
pinMode(joystickSWPin, INPUT_PULLUP);
}
void loop() {
int xValue = analogRead(joystickVRXPin);
int yValue = analogRead(joystickVRYPin);
// Check joystick position
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);
}
delay(100); // Small delay to avoid flickering
}
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's analog values, and sets the LEDs accordingly. The delay(100) function call is used to prevent flickering of the LEDs by introducing a small delay in the loop.