Circuit Documentation
Summary of the Circuit
This circuit is designed to control a traffic light using a joystick module interfaced with an Arduino UNO microcontroller. The joystick's position determines which LED on the traffic light is illuminated. Moving the joystick up activates the red LED, left for the yellow LED, right for the green LED, and down for all LEDs. When the joystick is in the neutral position, all LEDs are turned off.
Component List
Joystick Module
- Pins: SW, VRY, VRX, VCC, GND
- Description: A module that provides analog input based on the X (VRX) and Y (VRY) axes movement and a digital input (SW) when pressed.
Arduino UNO
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13
- Description: A microcontroller board based on the ATmega328P, with digital and analog I/O pins.
Traffic Light
- Pins: Green, Yellow, Red, GND
- Description: A module with three LEDs representing a traffic light's green, yellow, and red lights.
Wiring Details
Joystick Module
- SW (Switch): Connected to Arduino UNO's Digital Pin D7.
- VRY (Vertical Axis): Connected to Arduino UNO's Analog Pin A1.
- VRX (Horizontal Axis): Connected to Arduino UNO's Analog Pin A0.
- VCC: Connected to Arduino UNO's 5V output.
- GND: Connected to Arduino UNO's Ground.
Arduino UNO
- Digital Pin D7: Connected to Joystick Module's SW.
- Analog Pin A1: Connected to Joystick Module's VRY.
- Analog Pin A0: Connected to Joystick Module's VRX.
- 5V Output: Provides power to the Joystick Module.
- Ground: Common ground for Joystick Module and Traffic Light.
- Digital Pin D4: Connected to Traffic Light's Green LED.
- Digital Pin D3: Connected to Traffic Light's Yellow LED.
- Digital Pin D2: Connected to Traffic Light's Red LED.
Traffic Light
- Green LED: Controlled by Arduino UNO's Digital Pin D4.
- Yellow LED: Controlled by Arduino UNO's Digital Pin D3.
- Red LED: Controlled by Arduino UNO's Digital Pin D2.
- GND: Connected to Arduino UNO's Ground.
Documented Code
/*
* This Arduino sketch controls a traffic light using a joystick module.
* - Moving the joystick up turns on the red LED.
* - Moving the joystick left turns on the yellow LED.
* - Moving the joystick right turns on the green LED.
* - Moving the joystick down turns on all LEDs.
*/
const int redLED = 2; // Traffic Light Red LED
const int yellowLED = 3; // Traffic Light Yellow LED
const int greenLED = 4; // Traffic Light Green LED
const int joystickVRX = A0; // Joystick Horizontal Axis
const int joystickVRY = A1; // Joystick Vertical Axis
void setup() {
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(joystickVRX, INPUT);
pinMode(joystickVRY, INPUT);
}
void loop() {
int xValue = analogRead(joystickVRX);
int yValue = analogRead(joystickVRY);
if (yValue < 300) { // Joystick moved up
digitalWrite(redLED, HIGH);
digitalWrite(yellowLED, LOW);
digitalWrite(greenLED, LOW);
} else if (xValue < 300) { // Joystick moved left
digitalWrite(redLED, LOW);
digitalWrite(yellowLED, HIGH);
digitalWrite(greenLED, LOW);
} else if (xValue > 700) { // Joystick moved right
digitalWrite(redLED, LOW);
digitalWrite(yellowLED, LOW);
digitalWrite(greenLED, HIGH);
} else if (yValue > 700) { // Joystick moved down
digitalWrite(redLED, HIGH);
digitalWrite(yellowLED, HIGH);
digitalWrite(greenLED, HIGH);
} else { // Joystick in neutral position
digitalWrite(redLED, LOW);
digitalWrite(yellowLED, LOW);
digitalWrite(greenLED, LOW);
}
}
The code is structured to continuously read the analog values from the joystick's VRX and VRY pins to determine its position. Depending on the position, the corresponding LED on the traffic light is activated. The setup() function initializes the pins, and the loop() function contains the logic for reading the joystick input and controlling the LEDs.
