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 traffic light has three LEDs (red, yellow, and green) that are controlled based on the movement of the joystick. When the joystick is moved up, the red LED is turned on. Moving the joystick left turns on the yellow LED, and moving it right turns on the green LED. Pushing the joystick down will turn on all LEDs. The circuit is powered by the 5V output from the Arduino UNO, and a common ground is shared between all components.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Purpose: Acts as the central processing unit of the circuit, reading joystick inputs and controlling the traffic light LEDs.
Traffic Light
- Description: A module with three LEDs (Green, Yellow, Red).
- Purpose: Represents a traffic light, with each LED being controlled by the Arduino to simulate traffic light behavior.
Joystick Module
- Description: An input device with two axes of control and a pushbutton switch.
- 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 Traffic Light GND and Joystick module GND for common ground.
- A0 connected to Joystick module VRX for X-axis input.
- A1 connected to Joystick module VRY for Y-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 for pushbutton input.
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.
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.
*/
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);
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 designed to be uploaded to the Arduino UNO microcontroller. It initializes the pins connected to the traffic light LEDs and the joystick module as inputs and outputs. In the main loop, it reads the analog values from the joystick's VRX and VRY pins to determine the direction of the joystick movement and sets the state of the traffic light LEDs accordingly.
