Arduino UNO Controlled Traffic Light with Touch Sensor Activation
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary of the Circuit
This circuit is designed to simulate a traffic light system controlled by a touch sensor. The system uses an Arduino UNO microcontroller to cycle through the traffic light sequence (red, yellow, green, off) each time the touch sensor is activated. The traffic light system is represented by three LEDs (red, yellow, and green) that are turned on and off according to the state of the touch sensor.
Component List
Touch Sensor
- Name: Touch Sensor
- Pins: IO, VCC, GND
- Description: A sensor that detects touch or proximity to trigger an input signal to the microcontroller.
Arduino UNO
- Name: 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, with digital and analog I/O pins.
Traffic Light
- Name: Traffic Light
- Pins: Green, Yellow, Red, GND
- Description: A set of LEDs that simulate a traffic light, with individual control for each color.
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 to Touch Sensor VCC
- GND: Common ground for Touch Sensor and Traffic Light
- D4: Connected to Traffic Light Green LED
- D3: Connected to Traffic Light Yellow LED
- D2: Connected to Traffic Light Red LED
Traffic Light
- 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
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: 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 microcontroller. It initializes the pins connected to the touch sensor and LEDs, reads the state of the touch sensor, and updates the state of the LEDs based on the sensor input. The updateLeds() function controls which LED is turned on based on the current ledState.