Arduino UNO Controlled Traffic Light with Touch Sensor Interaction
View and Edit Project In Cirkit Designer
Traffic Light Control Circuit Documentation
Summary
This circuit is designed to control a traffic light system using an Arduino UNO microcontroller and a touch sensor. The system operates in a cycle where the state of the traffic light changes upon each touch sensor activation. The cycle progresses from red to yellow to green and then turns off all lights before repeating. The Arduino UNO is programmed to handle the input from the touch sensor and control the output to the traffic light LEDs accordingly.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13.
- Purpose: Acts as the central processing unit for the circuit, reading the touch sensor input and controlling the traffic light LEDs.
Traffic Light
- Description: A simple traffic light module with three LEDs (Green, Yellow, Red).
- Pins: Green, Yellow, Red, GND.
- Purpose: Displays the traffic light status as controlled by the Arduino UNO.
Touch Sensor
- Description: A capacitive touch sensor module.
- Pins: IO, VCC, GND.
- Purpose: Serves as the user interface for changing the traffic light status.
Wiring Details
Arduino UNO
- D4 connected to Traffic Light Green LED
- D3 connected to Traffic Light Yellow LED
- D2 connected to Traffic Light Red LED
- GND connected to Traffic Light GND and Touch Sensor GND
- 5V connected to Touch Sensor VCC
- D7 connected to Touch Sensor IO
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
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.
* When the touch sensor is pressed, the red LED turns on. On the next press,
* the yellow LED turns on. On the next press, the green LED turns on. On the
* next press, all LEDs turn off. This cycle repeats with each subsequent press.
*/
const int redLedPin = 2;
const int yellowLedPin = 3;
const int greenLedPin = 4;
const int touchSensorPin = 7;
int currentState = 0;
int lastTouchState = LOW;
void setup() {
pinMode(redLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(touchSensorPin, INPUT);
}
void loop() {
int touchState = digitalRead(touchSensorPin);
if (touchState == HIGH && lastTouchState == LOW) {
currentState = (currentState + 1) % 4;
updateLeds();
delay(200); // Debounce delay
}
lastTouchState = touchState;
}
void updateLeds() {
digitalWrite(redLedPin, currentState == 1 ? HIGH : LOW);
digitalWrite(yellowLedPin, currentState == 2 ? HIGH : LOW);
digitalWrite(greenLedPin, currentState == 3 ? HIGH : LOW);
if (currentState == 0) {
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, LOW);
digitalWrite(greenLedPin, LOW);
}
}
This code is responsible for the logic behind the traffic light control. It sets up the pins connected to the LEDs and the touch sensor as input/output accordingly. In the main loop, it reads the state of the touch sensor and changes the traffic light's state based on the current state. The updateLeds function is used to turn on the appropriate LED based on the current state.