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

Arduino-Controlled Traffic Light System with Touch Sensor Interaction

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Traffic Light System 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 that changes the state of the traffic light LEDs (Red, Yellow, Green) based on touch sensor input. When the touch sensor is activated, the circuit transitions through the traffic light states: Red, Yellow, Green, and then Off. This cycle repeats with each subsequent touch sensor activation.

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;    // Red LED connected to D2
const int yellowLedPin = 3; // Yellow LED connected to D3
const int greenLedPin = 4;  // Green LED connected to D4
const int touchSensorPin = 7; // Touch sensor connected to D7

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);

  // Detect touch sensor input and change the state of the LEDs
  if (touchState == HIGH && lastTouchState == LOW) {
    currentState = (currentState + 1) % 4;
    updateLeds();
    delay(200); // Debounce delay
  }

  lastTouchState = touchState;
}

void updateLeds() {
  // Update the state of the LEDs based on the current state
  digitalWrite(redLedPin, currentState == 1 ? HIGH : LOW);
  digitalWrite(yellowLedPin, currentState == 2 ? HIGH : LOW);
  digitalWrite(greenLedPin, currentState == 3 ? HIGH : LOW);
  if (currentState == 0) {
    // Turn off all LEDs
    digitalWrite(redLedPin, LOW);
    digitalWrite(yellowLedPin, LOW);
    digitalWrite(greenLedPin, LOW);
  }
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the pins connected to the LEDs and the touch sensor, then enters a loop where it reads the state of the touch sensor. When a touch is detected, it cycles through the traffic light states and updates the LEDs accordingly. The updateLeds function is responsible for turning the appropriate LED on or off based on the current state.