Arduino-Controlled Traffic Light System 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 that changes the state of the traffic light LEDs (Red, Yellow, Green) based on touch sensor input. When the touch sensor is activated, the circuit transitions through the traffic light states: Red, Yellow, Green, and then Off. This cycle repeats with each subsequent touch sensor activation.
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 controller for the traffic light system, processing input from the touch sensor and controlling the output to 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 states as controlled by the Arduino UNO.
Touch Sensor
- Description: A capacitive touch sensor module.
- Pins: IO, VCC, GND.
- Purpose: Provides input to the Arduino UNO to change the state of the traffic light LEDs.
Wiring Details
Arduino UNO
- D4: Connected to the Green LED of the Traffic Light.
- D3: Connected to the Yellow LED of the Traffic Light.
- D2: Connected to the Red LED of the Traffic Light.
- GND: Connected to the GND pin of the Traffic Light and the GND pin of the Touch Sensor.
- 5V: Connected to the VCC pin of the Touch Sensor.
- D7: Connected to the IO pin of the Touch Sensor.
Traffic Light
- Green: Connected to D4 on the Arduino UNO.
- Yellow: Connected to D3 on the Arduino UNO.
- Red: Connected to D2 on the Arduino UNO.
- GND: Connected to GND on the Arduino UNO.
Touch Sensor
- IO: Connected to D7 on the Arduino UNO.
- VCC: Connected to 5V on the Arduino UNO.
- GND: Connected to GND on the Arduino UNO.
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; // Red LED connected to D2
const int yellowLedPin = 3; // Yellow LED connected to D3
const int greenLedPin = 4; // Green LED connected to D4
const int touchSensorPin = 7; // Touch sensor connected to D7
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);
// Detect touch sensor input and change the state of the LEDs
if (touchState == HIGH && lastTouchState == LOW) {
currentState = (currentState + 1) % 4;
updateLeds();
delay(200); // Debounce delay
}
lastTouchState = touchState;
}
void updateLeds() {
// Update the state of the LEDs based on the current state
digitalWrite(redLedPin, currentState == 1 ? HIGH : LOW);
digitalWrite(yellowLedPin, currentState == 2 ? HIGH : LOW);
digitalWrite(greenLedPin, currentState == 3 ? HIGH : LOW);
if (currentState == 0) {
// Turn off all LEDs
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 LEDs and the touch sensor, then enters a loop where it reads the state of the touch sensor. When a touch is detected, it cycles through the traffic light states and updates the LEDs accordingly. The updateLeds function is responsible for turning the appropriate LED on or off based on the current state.