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 touch sensor's activation toggles between the red, yellow, and green lights of the traffic light module. The cycle progresses through the following states with each touch sensor activation: red on, yellow on, green on, and all off. The Arduino UNO is programmed to handle the touch sensor input and control the traffic light outputs 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 touch sensor input and controlling the traffic light LEDs.
Touch Sensor
- Description: A capacitive touch sensor module.
- Pins: IO, VCC, GND.
- Purpose: Provides user input to the system to cycle through the traffic light states.
Traffic Light
- Description: A module with three LEDs representing a traffic light.
- Pins: Green, Yellow, Red, GND.
- Purpose: Displays the traffic light states as controlled by the Arduino UNO.
Wiring Details
Arduino UNO
- 5V connected to Touch Sensor VCC.
- GND connected to Touch Sensor GND and Traffic Light GND.
- D7 connected to Touch Sensor IO.
- D2 connected to Traffic Light Red.
- D3 connected to Traffic Light Yellow.
- D4 connected to Traffic Light Green.
Touch Sensor
- VCC connected to Arduino UNO 5V.
- GND connected to Arduino UNO GND.
- IO connected to Arduino UNO D7.
Traffic Light
- GND connected to Arduino UNO GND.
- Green connected to Arduino UNO D4.
- Yellow connected to Arduino UNO D3.
- Red connected to Arduino UNO D2.
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 touchPin = 7; // Pin connected to the touch sensor
const int redPin = 2; // Pin connected to the red LED
const int yellowPin = 3; // Pin connected to the yellow LED
const int greenPin = 4; // Pin connected to the green LED
int touchState = 0; // Current state of the touch sensor
int lastTouchState = 0; // Previous state of the touch sensor
int ledState = 0; // State of the LEDs (0: off, 1: red, 2: yellow, 3: green)
void setup() {
pinMode(touchPin, INPUT);
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, LOW);
}
void loop() {
touchState = digitalRead(touchPin);
if (touchState == HIGH && lastTouchState == LOW) {
ledState = (ledState + 1) % 4;
updateLEDs();
delay(200); // Debounce delay
}
lastTouchState = touchState;
}
void updateLEDs() {
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, LOW);
if (ledState == 1) {
digitalWrite(redPin, HIGH);
} else if (ledState == 2) {
digitalWrite(yellowPin, HIGH);
} else if (ledState == 3) {
digitalWrite(greenPin, HIGH);
}
}
Filename: sketch.ino
This code is responsible for reading the state of the touch sensor and toggling the traffic light LEDs accordingly. The setup() function initializes the pins, and the loop() function continuously checks the sensor state and updates the LEDs. The updateLEDs() function turns off all LEDs and then turns on the appropriate LED based on the current state.
