Circuit Documentation
Summary of the Circuit
This circuit is designed to control a traffic light using an Arduino UNO microcontroller and a joystick module. The joystick's position determines which LED on the traffic light module 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 down.
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 input/output pins, analog inputs, and various power options.
Traffic Light
- Pins: Green, Yellow, Red, GND
- Description: A module with three LEDs (green, yellow, red) that simulates a traffic light.
Wiring Details
Joystick Module
- SW - Connected to Arduino UNO Digital Pin D7
- VRY - Connected to Arduino UNO Analog Pin A1
- VRX - Connected to Arduino UNO Analog Pin A0
- VCC - Connected to Arduino UNO 5V Pin
- GND - Connected to Arduino UNO GND Pin
Arduino UNO
- Digital Pin D7 - Connected to Joystick Module SW
- Analog Pin A1 - Connected to Joystick Module VRY
- Analog Pin A0 - Connected to Joystick Module VRX
- 5V Pin - Provides power to Joystick Module VCC
- GND Pin - Common ground for Joystick Module and Traffic Light
- Digital Pin D4 - Connected to Traffic Light Green LED
- Digital Pin D3 - Connected to Traffic Light Yellow LED
- Digital Pin D2 - Connected to Traffic Light Red LED
Traffic Light
- Green - Connected to Arduino UNO Digital Pin D4
- Yellow - Connected to Arduino UNO Digital Pin D3
- Red - Connected to Arduino UNO Digital Pin D2
- GND - Connected to Arduino UNO GND Pin
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 vrxPin = A0;
const int vryPin = A1;
void setup() {
pinMode(redLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(vrxPin, INPUT);
pinMode(vryPin, INPUT);
}
void loop() {
int vrxValue = analogRead(vrxPin);
int vryValue = analogRead(vryPin);
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);
}
}
This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the pins connected to the traffic light LEDs as outputs and the joystick's analog pins as inputs. The loop function reads the joystick's analog values and turns on the corresponding LEDs based on the joystick's position.
