Circuit Documentation
Summary
This circuit is designed to control a traffic light using a joystick module interfaced with an Arduino UNO microcontroller. The joystick's movements dictate the state of the traffic light LEDs (Red, Yellow, Green). Moving the joystick up activates the red LED, left for yellow, right for green, and down for all LEDs. The joystick also has a built-in switch that is not used in this application. The circuit is powered by the Arduino's 5V output, and all components share a common ground.
Component List
Joystick Module
- Pins: SW, VRY, VRX, VCC, GND
- Description: A module that provides analog input from two axes (VRX, VRY) and a digital input from a pushbutton (SW).
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.
Wiring Details
Joystick Module
- SW (Switch): Not connected in this circuit.
- VRY (Vertical Axis): Connected to Arduino UNO's A1 (Analog Input).
- VRX (Horizontal Axis): Connected to Arduino UNO's A0 (Analog Input).
- VCC: Connected to Arduino UNO's 5V (Power).
- GND: Connected to Arduino UNO's GND (Ground).
Arduino UNO
- 5V: Provides power to the Joystick Module.
- GND: Common ground for the Joystick Module and Traffic Light.
- A0: Receives horizontal axis data from Joystick Module's VRX.
- A1: Receives vertical axis data from Joystick Module's VRY.
- D2: Controls the Red LED on the Traffic Light.
- D3: Controls the Yellow LED on the Traffic Light.
- D4: Controls the Green LED on the Traffic Light.
Traffic Light
- Green: Controlled by Arduino UNO's D4.
- Yellow: Controlled by Arduino UNO's D3.
- Red: Controlled by Arduino UNO's D2.
- GND: Connected to Arduino UNO's GND.
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 redLED = 2;
const int yellowLED = 3;
const int greenLED = 4;
const int joystickVRX = A0;
const int joystickVRY = A1;
const int joystickSW = 7;
void setup() {
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(joystickSW, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
int xValue = analogRead(joystickVRX);
int yValue = analogRead(joystickVRY);
Serial.print("X: ");
Serial.print(xValue);
Serial.print(" Y: ");
Serial.println(yValue);
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);
}
delay(100);
}
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 switch as an input with an internal pull-up resistor. The loop function reads the analog values from the joystick's VRX and VRY pins to determine its position and sets the traffic light LEDs accordingly. Serial output is provided for debugging purposes.
