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 in a cycle where the touch sensor's input is used to switch between the traffic light states: off, red, yellow, and green. Each state is represented by an LED on the traffic light module. The Arduino UNO reads the input from the touch sensor and controls the state of each LED accordingly.

Component List

Arduino UNO

Touch Sensor

Traffic Light Module

Wiring Details

Arduino UNO

Touch Sensor

Traffic Light 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 touchPin = 7; // Pin connected to touch sensor
const int redPin = 2;   // Pin connected to red LED
const int yellowPin = 3; // Pin connected to yellow LED
const int greenPin = 4;  // Pin connected to 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);

  // Check for touch sensor press
  if (touchState == HIGH && lastTouchState == LOW) {
    state = (state + 1) % 4; // Cycle through states 0 to 3
    updateLEDs();
  }

  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 written for the Arduino UNO and is responsible for reading the state of the touch sensor and controlling the LEDs on the traffic light module. The setup() function initializes the pins and sets the initial state of the LEDs to off. The loop() function continuously checks the state of the touch sensor and updates the LEDs accordingly. The updateLEDs() function sets the appropriate LED states based on the current value of the state variable.