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

Arduino UNO Controlled Traffic Light with Touch Sensor

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

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 Arduino UNO is programmed to detect touch events and switch the corresponding traffic light LED on or off based on the current state of the system.

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;    // Pin connected to Red LED
const int yellowLEDPin = 3; // Pin connected to Yellow LED
const int greenLEDPin = 4;  // Pin connected to Green LED
const int touchPin = 7;     // Pin connected to Touch Sensor

int currentState = 0;       // Current state of the traffic light
int lastTouchState = LOW;   // Previous state of the touch sensor

void setup() {
  pinMode(redLEDPin, OUTPUT);
  pinMode(yellowLEDPin, OUTPUT);
  pinMode(greenLEDPin, OUTPUT);
  pinMode(touchPin, INPUT);
  digitalWrite(redLEDPin, LOW);
  digitalWrite(yellowLEDPin, LOW);
  digitalWrite(greenLEDPin, LOW);
}

void loop() {
  int touchState = digitalRead(touchPin);

  // Check for touch sensor press
  if (touchState == HIGH && lastTouchState == LOW) {
    currentState = (currentState + 1) % 4;
    updateTrafficLight();
  }

  lastTouchState = touchState;
}

void updateTrafficLight() {
  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 responsible for the operation of the traffic light system. It initializes the pins connected to the LEDs and the touch sensor, reads the state of the touch sensor, and updates the traffic light LEDs accordingly. The updateTrafficLight function controls which LED is turned on based on the current state, which is cycled through each time the touch sensor is pressed.