Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Controlled Traffic Light with Touch Sensor Interaction

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Traffic Light with Touch Sensor Interaction

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 state of the traffic light changes upon each touch sensor activation. The cycle progresses from red to yellow to green and then turns off all lights before repeating. The Arduino UNO is programmed to handle the input from the touch sensor and control the output to the traffic light LEDs accordingly.

Component List

Arduino UNO

Traffic Light

Touch Sensor

Wiring Details

Arduino UNO

Traffic Light

Touch Sensor

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 redLedPin = 2;
const int yellowLedPin = 3;
const int greenLedPin = 4;
const int touchSensorPin = 7;

int currentState = 0;
int lastTouchState = LOW;

void setup() {
  pinMode(redLedPin, OUTPUT);
  pinMode(yellowLedPin, OUTPUT);
  pinMode(greenLedPin, OUTPUT);
  pinMode(touchSensorPin, INPUT);
}

void loop() {
  int touchState = digitalRead(touchSensorPin);
  if (touchState == HIGH && lastTouchState == LOW) {
    currentState = (currentState + 1) % 4;
    updateLeds();
    delay(200); // Debounce delay
  }
  lastTouchState = touchState;
}

void updateLeds() {
  digitalWrite(redLedPin, currentState == 1 ? HIGH : LOW);
  digitalWrite(yellowLedPin, currentState == 2 ? HIGH : LOW);
  digitalWrite(greenLedPin, currentState == 3 ? HIGH : LOW);
  if (currentState == 0) {
    digitalWrite(redLedPin, LOW);
    digitalWrite(yellowLedPin, LOW);
    digitalWrite(greenLedPin, LOW);
  }
}

This code is responsible for the logic behind the traffic light control. It sets up the pins connected to the LEDs and the touch sensor as input/output accordingly. In the main loop, it reads the state of the touch sensor and changes the traffic light's state based on the current state. The updateLeds function is used to turn on the appropriate LED based on the current state.