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 where the touch sensor's input is used to switch between the traffic light states: red, yellow, green, and off. The Arduino UNO reads the state of the touch sensor and lights up the corresponding LED on the traffic light module.
Component List
Touch Sensor
- Pins: IO, VCC, GND
- Description: A sensor that detects touch input and sends a signal to the microcontroller.
Arduino UNO
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13
- Description: A microcontroller board based on the ATmega328P. It has digital input/output pins, analog inputs, a USB connection for programming, and power management features.
Traffic Light Module
- Pins: Green, Yellow, Red, GND
- Description: A module with three LEDs representing a traffic light. Each LED can be controlled individually to simulate traffic light states.
Wiring Details
Touch Sensor
- IO: Connected to Arduino UNO Digital Pin D7
- VCC: Connected to Arduino UNO 5V
- GND: Connected to Arduino UNO GND
Arduino UNO
- D7: Connected to Touch Sensor IO
- 5V: Power supply for Touch Sensor
- GND: Common ground for Touch Sensor and Traffic Light Module
- D4: Connected to Traffic Light Green LED
- D3: Connected to Traffic Light Yellow LED
- D2: Connected to Traffic Light Red LED
Traffic Light Module
- Green: Controlled by Arduino UNO Digital Pin D4
- Yellow: Controlled by Arduino UNO Digital Pin D3
- Red: Controlled by Arduino UNO Digital Pin D2
- 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 touchPin = 7; // Pin connected to touch sensor IO
const int redPin = 2; // Pin connected to red LED
const int yellowPin = 3; // Pin connected to yellow LED
const int greenPin = 4; // Pin connected to green LED
int state = 0; // Variable to hold the current state
int lastTouchState = LOW; // Variable to hold the last touch state
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() {
int touchState = digitalRead(touchPin);
if (touchState == HIGH && lastTouchState == LOW) {
state = (state + 1) % 4;
updateLEDs();
delay(200); // Debounce delay
}
lastTouchState = touchState;
}
void updateLEDs() {
digitalWrite(redPin, state == 1 ? HIGH : LOW);
digitalWrite(yellowPin, state == 2 ? HIGH : LOW);
digitalWrite(greenPin, state == 3 ? HIGH : LOW);
}
This code is designed to be uploaded to the Arduino UNO microcontroller. It sets up the necessary pins for input and output and contains a main loop that reads the touch sensor state. 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.