Circuit Documentation
Summary of the Circuit
This circuit is designed to control a traffic light using an Arduino UNO and a joystick module. The joystick's movements control the state of the traffic light LEDs (Red, Yellow, Green). Moving the joystick up turns on the red LED, moving it left turns on the yellow LED, and moving it right turns on the green LED. Moving the joystick down turns on all LEDs. The joystick also has a switch that is not used in this circuit.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Purpose: Acts as the central controller for the circuit, reading joystick inputs and controlling the traffic light LEDs.
Traffic Light
- Description: A simple traffic light module with three LEDs (Green, Yellow, Red).
- Purpose: Displays the traffic light status based on the joystick input.
Joystick Module
- Description: A module with two potentiometers that vary with the joystick's position on two axes (VRX and VRY) and a pushbutton switch (SW).
- 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 Joystick module GND and Traffic Light GND for common ground.
- A0 connected to Joystick module VRX to read the horizontal axis.
- A1 connected to Joystick module VRY to read the vertical axis.
- 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 (unused in this circuit).
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 (unused in this circuit).
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.
*/
// Pin definitions
const int redLedPin = 2;
const int yellowLedPin = 3;
const int greenLedPin = 4;
const int vrxPin = A0;
const int vryPin = A1;
const int swPin = 7; // Not used in this circuit
void setup() {
// Initialize LED pins as outputs
pinMode(redLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
// Initialize joystick pins
pinMode(vrxPin, INPUT);
pinMode(vryPin, INPUT);
pinMode(swPin, INPUT); // Not used in this circuit
}
void loop() {
int vrxValue = analogRead(vrxPin);
int vryValue = analogRead(vryPin);
// Joystick moved up
if (vryValue < 300) {
digitalWrite(redLedPin, HIGH);
digitalWrite(yellowLedPin, LOW);
digitalWrite(greenLedPin, LOW);
}
// Joystick moved down
else if (vryValue > 700) {
digitalWrite(redLedPin, HIGH);
digitalWrite(yellowLedPin, HIGH);
digitalWrite(greenLedPin, HIGH);
}
// Joystick moved left
else if (vrxValue < 300) {
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, HIGH);
digitalWrite(greenLedPin, LOW);
}
// Joystick moved right
else if (vrxValue > 700) {
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, LOW);
digitalWrite(greenLedPin, HIGH);
}
// Joystick in neutral position
else {
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 joystick and traffic light LEDs, reads the joystick's analog values, and sets the LEDs accordingly. The joystick's switch (SW) is initialized but not used in the logic of this sketch.
