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

Arduino UNO Controlled Traffic Light System with Touch Sensor Interaction

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

Traffic Light Control System Documentation

Summary

The circuit described herein is designed to control a traffic light system using a touch sensor. The system operates on a simple state machine logic, where each touch toggles the traffic light through a sequence of states: all off, red on, yellow on, green on, and then back to all off. An Arduino UNO microcontroller is used to read the state of the touch sensor and control the traffic light LEDs accordingly.

Component List

Touch Sensor

Traffic Light

Arduino UNO

Wiring Details

Touch Sensor

Traffic Light

Arduino UNO

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 the touch sensor
const int redPin = 2;   // Pin connected to the red LED
const int yellowPin = 3; // Pin connected to the yellow LED
const int greenPin = 4;  // Pin connected to the 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() {
  switch (state) {
    case 0:
      digitalWrite(redPin, LOW);
      digitalWrite(yellowPin, LOW);
      digitalWrite(greenPin, LOW);
      break;
    case 1:
      digitalWrite(redPin, HIGH);
      digitalWrite(yellowPin, LOW);
      digitalWrite(greenPin, LOW);
      break;
    case 2:
      digitalWrite(redPin, LOW);
      digitalWrite(yellowPin, HIGH);
      digitalWrite(greenPin, LOW);
      break;
    case 3:
      digitalWrite(redPin, LOW);
      digitalWrite(yellowPin, LOW);
      digitalWrite(greenPin, HIGH);
      break;
  }
}

This code is saved as sketch.ino and is intended to be uploaded to the Arduino UNO microcontroller. It initializes the pins connected to the touch sensor and traffic light LEDs, reads the state of the touch sensor, and updates the LEDs based on the current state. The updateLEDs() function is responsible for turning the appropriate LEDs on or off depending on the value of the state variable.