Arduino-Controlled Traffic Light System with Joystick Interaction
View and Edit Project In Cirkit Designer
Traffic Light Control Circuit Documentation
Summary
This circuit is designed to control a traffic light system using an Arduino UNO microcontroller and a joystick module. The traffic light system consists of three LEDs (red, yellow, and green) that represent the traffic signals. The joystick module is used to change the state of the traffic lights: moving the joystick up turns on the red LED, moving it left turns on the yellow LED, moving it right turns on the green LED, and moving it down turns on all LEDs. The circuit is powered by the Arduino UNO, which also processes the input from the joystick and drives the traffic light LEDs accordingly.
Component List
Traffic Light
- Description: A set of LEDs representing a traffic light.
- Pins: Green, Yellow, Red, GND
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
Joystick Module
- Description: An input device that includes an analog stick and a push button.
- Pins: SW, VRY, VRX, VCC, GND
Wiring Details
Traffic Light
- Green LED: Connected to Arduino UNO pin D4
- Yellow LED: Connected to Arduino UNO pin D3
- Red LED: Connected to Arduino UNO pin D2
- GND: Connected to Arduino UNO GND
Arduino UNO
- 5V: Provides power to the Joystick module VCC
- GND: Common ground for Traffic Light and Joystick module
- D2: Controls the Red LED of the Traffic Light
- D3: Controls the Yellow LED of the Traffic Light
- D4: Controls the Green LED of the Traffic Light
- A0: Reads the VRX value from the Joystick module
- A1: Reads the VRY value from the Joystick module
- D7: Reads the SW (switch) value from the Joystick module
Joystick Module
- VCC: Connected to Arduino UNO 5V
- GND: Connected to Arduino UNO GND
- VRX: Connected to Arduino UNO pin A0
- VRY: Connected to Arduino UNO pin A1
- SW: Connected to Arduino UNO pin D7
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.
*/
const int redLEDPin = 2;
const int yellowLEDPin = 3;
const int greenLEDPin = 4;
const int joystickSWPin = 7;
const int joystickVRXPin = A0;
const int joystickVRYPin = A1;
void setup() {
pinMode(redLEDPin, OUTPUT);
pinMode(yellowLEDPin, OUTPUT);
pinMode(greenLEDPin, OUTPUT);
pinMode(joystickSWPin, INPUT);
Serial.begin(9600);
}
void loop() {
int vrxValue = analogRead(joystickVRXPin);
int vryValue = analogRead(joystickVRYPin);
bool swValue = digitalRead(joystickSWPin);
if (vryValue < 300) { // Joystick moved up
digitalWrite(redLEDPin, HIGH);
digitalWrite(yellowLEDPin, LOW);
digitalWrite(greenLEDPin, LOW);
} else if (vrxValue < 300) { // Joystick moved left
digitalWrite(redLEDPin, LOW);
digitalWrite(yellowLEDPin, HIGH);
digitalWrite(greenLEDPin, LOW);
} else if (vrxValue > 700) { // Joystick moved right
digitalWrite(redLEDPin, LOW);
digitalWrite(yellowLEDPin, LOW);
digitalWrite(greenLEDPin, HIGH);
} else if (vryValue > 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 for debounce
}
This code is saved as sketch.ino and should be uploaded to the Arduino UNO microcontroller to operate the traffic light system as described.