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

Summary

This document describes a traffic light control system designed using an Arduino UNO microcontroller. The system utilizes a touch sensor to cycle through the traffic light states, which include Red, Yellow, and Green LEDs. The touch sensor allows the user to change the state of the traffic lights with each press, cycling through Red, Yellow, Green, and then turning all LEDs off before repeating the cycle.

Component List

Arduino UNO

Traffic Light

Joystick Module

Touch Sensor

Wiring Details

Arduino UNO

Traffic Light

Joystick Module

Touch Sensor

Documented Code

/*
 * This Arduino sketch controls a traffic light system using a touch sensor.
 * The traffic light has three LEDs: Green, Yellow, and Red.
 * The touch sensor cycles through the following states with each press:
 * - First press: Red LED turns on
 * - Second press: Yellow LED turns on
 * - Third press: Green LED turns on
 * - Fourth press: All LEDs turn off
 * - The cycle repeats with each subsequent press
 */

// Pin definitions
const int greenPin = 4;
const int yellowPin = 3;
const int redPin = 2;
const int touchPin = 7;

// State variable to keep track of the current LED state
int state = 0;

void setup() {
  // Initialize the digital pins as outputs
  pinMode(greenPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(redPin, OUTPUT);
  // Initialize the touch sensor pin as input
  pinMode(touchPin, INPUT);
}

void loop() {
  // Read the touch sensor value
  int touchValue = digitalRead(touchPin);
  // Check if the touch sensor is pressed
  if (touchValue == HIGH) {
    // Debounce delay
    delay(50);
    // Wait for the touch sensor to be released
    while (digitalRead(touchPin) == HIGH);
    // Cycle through the states
    state = (state + 1) % 4;
    // Update the LEDs based on the current state
    switch (state) {
      case 0:
        digitalWrite(redPin, HIGH);
        digitalWrite(yellowPin, LOW);
        digitalWrite(greenPin, LOW);
        break;
      case 1:
        digitalWrite(redPin, LOW);
        digitalWrite(yellowPin, HIGH);
        digitalWrite(greenPin, LOW);
        break;
      case 2:
        digitalWrite(redPin, LOW);
        digitalWrite(yellowPin, LOW);
        digitalWrite(greenPin, HIGH);
        break;
      case 3:
        digitalWrite(redPin, LOW);
        digitalWrite(yellowPin, LOW);
        digitalWrite(greenPin, LOW);
        break;
    }
    // Small delay to avoid multiple detections
    delay(200);
  }
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It sets up the necessary pins as inputs and outputs and contains the main loop that reads the touch sensor and cycles through the traffic light states.