Arduino UNO 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 by cycling through the traffic light states (red, yellow, green, off) in response to touch sensor inputs. The circuit includes the Arduino UNO as the main controller, a traffic light module with red, yellow, and green LEDs, and a touch sensor module for user input.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Purpose: Acts as the central processing unit for the traffic light control system, reading touch sensor inputs and controlling the state of the traffic light LEDs.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13.
Traffic Light Module
- Description: A module with three LEDs (Green, Yellow, Red) representing a traffic light.
- Purpose: Displays the current state of the traffic light as controlled by the Arduino UNO.
- Pins: Green, Yellow, Red, GND.
Touch Sensor Module
- Description: A capacitive touch sensor module.
- Purpose: Provides a user interface to change the state of the traffic light system.
- Pins: IO, VCC, GND.
Wiring Details
Arduino UNO
- 5V connected to the VCC pin of the touch sensor module.
- GND connected to the GND pins of both the touch sensor module and the traffic light module.
- D7 connected to the IO pin of the touch sensor module.
- D2 connected to the Red pin of the traffic light module.
- D3 connected to the Yellow pin of the traffic light module.
- D4 connected to the Green pin of the traffic light module.
Traffic Light Module
- Green connected to Arduino UNO D4.
- Yellow connected to Arduino UNO D3.
- Red connected to Arduino UNO D2.
- GND connected to Arduino UNO GND.
Touch Sensor Module
- IO connected to Arduino UNO D7.
- VCC connected to Arduino UNO 5V.
- 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 touchSensorPin = 7; // Pin connected to the touch sensor
const int redLEDPin = 2; // Pin connected to the red LED
const int yellowLEDPin = 3; // Pin connected to the yellow LED
const int greenLEDPin = 4; // Pin connected to the green LED
int currentState = 0; // Current state of the traffic light
int lastTouchState = LOW; // Last state of the touch sensor
void setup() {
pinMode(touchSensorPin, INPUT);
pinMode(redLEDPin, OUTPUT);
pinMode(yellowLEDPin, OUTPUT);
pinMode(greenLEDPin, OUTPUT);
digitalWrite(redLEDPin, LOW);
digitalWrite(yellowLEDPin, LOW);
digitalWrite(greenLEDPin, LOW);
}
void loop() {
int touchState = digitalRead(touchSensorPin);
// Check for touch sensor press
if (touchState == HIGH && lastTouchState == LOW) {
currentState = (currentState + 1) % 4;
updateLEDs();
}
lastTouchState = touchState;
}
void updateLEDs() {
switch (currentState) {
case 0:
digitalWrite(redLEDPin, LOW);
digitalWrite(yellowLEDPin, LOW);
digitalWrite(greenLEDPin, LOW);
break;
case 1:
digitalWrite(redLEDPin, HIGH);
digitalWrite(yellowLEDPin, LOW);
digitalWrite(greenLEDPin, LOW);
break;
case 2:
digitalWrite(redLEDPin, LOW);
digitalWrite(yellowLEDPin, HIGH);
digitalWrite(greenLEDPin, LOW);
break;
case 3:
digitalWrite(redLEDPin, LOW);
digitalWrite(yellowLEDPin, LOW);
digitalWrite(greenLEDPin, HIGH);
break;
}
}
This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the pins connected to the touch sensor and LEDs as input and outputs, respectively. The loop function reads the state of the touch sensor and cycles through the traffic light states accordingly. The updateLEDs function sets the appropriate LED pins to HIGH or LOW based on the current state.