Circuit Documentation
Summary
This circuit is designed to control a traffic light system using an Arduino UNO microcontroller and a touch sensor. The traffic light system consists of three LEDs (Green, Yellow, and Red) that are cycled through different states upon the touch sensor being activated. The Arduino UNO reads the input from the touch sensor and changes the state of the LEDs accordingly. The system operates in a cycle where the first touch activates the Red LED, the second touch activates the Yellow LED, the third touch activates the Green LED, and the fourth touch turns off all LEDs. This cycle repeats with each subsequent touch.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Purpose: Acts as the central processing unit of the circuit, controlling the traffic light and reading the touch sensor input.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13.
Traffic Light
- Description: A module with three LEDs representing a traffic light.
- Purpose: Displays the traffic light status as controlled by the Arduino UNO.
- Pins: Green, Yellow, Red, GND.
Joystick Module
- Description: An input device with two axes of control.
- Purpose: Not directly used in the traffic light control but included in the circuit.
- Pins: SW, VRY, VRX, VCC, GND.
Touch Sensor
- Description: A sensor that detects touch or proximity.
- Purpose: Used to cycle through the traffic light states.
- Pins: IO, VCC, GND.
Wiring Details
Arduino UNO
- 5V connected to the Touch Sensor VCC.
- GND connected to the Traffic Light GND and Touch Sensor GND.
- A0 connected to the Joystick Module VRX.
- A1 connected to the Joystick Module VRY.
- D1 connected to the Traffic Light Red.
- D2 connected to the Traffic Light Yellow.
- D3 connected to the Traffic Light Green.
- D7 connected to the Touch Sensor IO.
Traffic Light
- Green connected to Arduino UNO D3.
- Yellow connected to Arduino UNO D2.
- Red connected to Arduino UNO D1.
- GND connected to Arduino UNO GND.
Joystick Module
- VRX connected to Arduino UNO A0.
- VRY connected to Arduino UNO A1.
- VCC and SW are not connected.
- GND is not connected.
Touch Sensor
- IO connected to Arduino UNO D7.
- VCC connected to Arduino UNO 5V.
- GND connected to Arduino UNO GND.
Documented Code
/*
* This Arduino sketch controls a traffic light system using a touch sensor.
* The traffic light has three LEDs: Green, Yellow, and Red.
* The touch sensor cycles through the LEDs as follows:
* - First press: Red LED turns on
* - Second press: Yellow LED turns on
* - Third press: Green LED turns on
* - Fourth press: All LEDs turn off
* - This cycle repeats with each subsequent press
*/
// Pin definitions
const int redPin = 1; // Traffic Light Red
const int yellowPin = 2; // Traffic Light Yellow
const int greenPin = 3; // Traffic Light Green
const int touchPin = 7; // Touch Sensor IO
// State variable to track the current LED state
int state = 0;
void setup() {
// Initialize the digital pins as outputs
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
// Initialize the touch sensor pin as input
pinMode(touchPin, INPUT);
}
void loop() {
// Check if the touch sensor is pressed
if (digitalRead(touchPin) == HIGH) {
// Debounce delay
delay(50);
if (digitalRead(touchPin) == HIGH) {
// Increment the state
state = (state + 1) % 4;
// Update the LEDs based on the current state
updateLEDs();
// Wait for the touch sensor to be released
while (digitalRead(touchPin) == HIGH) {
delay(10);
}
}
}
}
void updateLEDs() {
// Reset all LEDs
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, LOW);
// Set the appropriate LED based on the state
if (state == 1) {
digitalWrite(redPin, HIGH);
} else if (state == 2) {
digitalWrite(yellowPin, HIGH);
} else if (state == 3) {
digitalWrite(greenPin, HIGH);
}
}
The code is structured to run on the Arduino UNO and controls the traffic light LEDs based on the input from the touch sensor. The setup() function initializes the pins, and the loop() function continuously checks for touch sensor input to change the state of the LEDs. The updateLEDs() function is responsible for turning the appropriate LED on based on the current state.
