Arduino UNO Controlled Traffic Light with Touch Sensor Activation
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 system transitions through the traffic light states: red, yellow, green, and then all 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 processing unit for the circuit, controlling the traffic light LEDs and reading input from the touch sensor.
Touch Sensor
- Description: A capacitive touch sensor module.
- Pins: IO, VCC, GND.
- Purpose: Provides user input to the system to change the state of the traffic lights.
Traffic Light
- Description: A module with three LEDs representing a traffic light.
- Pins: Green, Yellow, Red, GND.
- Purpose: Displays the traffic light state as controlled by the Arduino UNO.
Wiring Details
Arduino UNO
- 5V: Provides power to the touch sensor.
- GND: Common ground for the Arduino UNO, touch sensor, and traffic light module.
- D7: Connected to the touch sensor IO pin to read touch input.
- D2: Connected to the traffic light's Red LED.
- D3: Connected to the traffic light's Yellow LED.
- D4: Connected to the traffic light's Green LED.
Touch Sensor
- IO: Receives touch input and is connected to Arduino UNO's D7 pin.
- VCC: Connected to Arduino UNO's 5V pin for power.
- GND: Connected to the common ground.
Traffic Light
- Green: Connected to Arduino UNO's D4 pin.
- Yellow: Connected to Arduino UNO's D3 pin.
- Red: Connected to Arduino UNO's D2 pin.
- GND: Connected to the common ground.
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 touch sensor IO
const int redLedPin = 2; // Pin connected to red LED
const int yellowLedPin = 3; // Pin connected to yellow LED
const int greenLedPin = 4; // Pin connected to 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: all off, 1: red, 2: yellow, 3: green)
void setup() {
pinMode(touchPin, INPUT);
pinMode(redLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, LOW);
digitalWrite(greenLedPin, LOW);
}
void loop() {
touchState = digitalRead(touchPin);
if (touchState == HIGH && lastTouchState == LOW) {
ledState = (ledState + 1) % 4;
updateLeds();
}
lastTouchState = touchState;
}
void updateLeds() {
digitalWrite(redLedPin, ledState == 1 ? HIGH : LOW);
digitalWrite(yellowLedPin, ledState == 2 ? HIGH : LOW);
digitalWrite(greenLedPin, ledState == 3 ? HIGH : LOW);
}
This code is written for the Arduino UNO and is responsible for reading the state of the touch sensor and controlling the traffic light LEDs accordingly. The setup() function initializes the pins and sets the initial state of the LEDs to off. The loop() function continuously checks the state of the touch sensor and updates the LED states based on the current cycle position. The updateLeds() function turns on the appropriate LED based on the ledState variable.