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

Traffic Light Module

Touch Sensor Module

Wiring Details

Arduino UNO

Traffic Light Module

Touch Sensor Module

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.