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

Arduino UNO Controlled Traffic Light with Touch Sensor Interaction

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

Traffic Light Control System Documentation

Summary

This document describes a traffic light control system designed using an Arduino UNO microcontroller, a touch sensor, and a traffic light module with three LEDs (Red, Yellow, Green). The system operates by cycling through the traffic light states (Red, Yellow, Green, Off) in response to touch sensor inputs. Each press of the touch sensor advances the traffic light to the next state in the sequence.

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 touchPin = 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; // Variable to store the current state of the LEDs
int lastTouchState = LOW; // Variable to store the last state of the touch sensor

void setup() {
  pinMode(touchPin, INPUT); // Set touch sensor pin as input
  pinMode(redLEDPin, OUTPUT); // Set red LED pin as output
  pinMode(yellowLEDPin, OUTPUT); // Set yellow LED pin as output
  pinMode(greenLEDPin, OUTPUT); // Set green LED pin as output
  digitalWrite(redLEDPin, LOW); // Ensure red LED is off
  digitalWrite(yellowLEDPin, LOW); // Ensure yellow LED is off
  digitalWrite(greenLEDPin, LOW); // Ensure green LED is off
}

void loop() {
  int touchState = digitalRead(touchPin); // Read the state of the touch sensor

  if (touchState == HIGH && lastTouchState == LOW) {
    // If the touch sensor is pressed
    currentState = (currentState + 1) % 4; // Move to the next state
    updateLEDs(); // Update the LEDs based on the current state
  }

  lastTouchState = touchState; // Update the last touch state
}

void updateLEDs() {
  // Turn off all LEDs
  digitalWrite(redLEDPin, LOW);
  digitalWrite(yellowLEDPin, LOW);
  digitalWrite(greenLEDPin, LOW);

  // Turn on the appropriate LED based on the current state
  if (currentState == 1) {
    digitalWrite(redLEDPin, HIGH);
  } else if (currentState == 2) {
    digitalWrite(yellowLEDPin, HIGH);
  } else if (currentState == 3) {
    digitalWrite(greenLEDPin, HIGH);
  }
}

This code is saved in a file named sketch.ino. It is designed to be uploaded to the Arduino UNO microcontroller to control the traffic light system.