Circuit Documentation
Summary
This circuit is designed to control a traffic light system using a joystick module and an Arduino UNO. The joystick module is used to determine the direction of movement, which in turn controls the state of the traffic light LEDs (Red, Yellow, Green). The Arduino UNO reads the joystick inputs and sets the appropriate LEDs based on the joystick's position.
Component List
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
Traffic Light
- Description: A module with three LEDs (Green, Yellow, Red) and a ground pin.
- Pins: Green, Yellow, Red, GND
Joystick Module
- Description: A module with a joystick that provides analog outputs for X and Y axes and a digital output for the switch.
- Pins: SW, VRY, VRX, VCC, GND
Wiring Details
Arduino UNO
- 5V connected to Joystick Module VCC
- GND connected to Joystick Module GND
- A0 connected to Joystick Module VRX
- A1 connected to Joystick Module VRY
- GND connected to Traffic Light GND
- D7 connected to Joystick Module SW
- D4 connected to Traffic Light Green
- D3 connected to Traffic Light Yellow
- D2 connected to Traffic Light Red
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
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 initializes the pins for the joystick and the traffic light LEDs. It reads the joystick's X and Y values and sets the LEDs accordingly. The joystick's switch is not used in this sketch.
