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

Circuit Documentation

Summary

This circuit is designed to control a traffic light system using an Arduino UNO microcontroller and a touch sensor. The traffic light system consists of three LEDs (Green, Yellow, and Red) that are cycled through different states upon the touch sensor being activated. The Arduino UNO reads the input from the touch sensor and changes the state of the LEDs accordingly. The system operates in a cycle where the first touch activates the Red LED, the second touch activates the Yellow LED, the third touch activates the Green LED, and the fourth touch turns off all LEDs. This cycle repeats with each subsequent touch.

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 LEDs as follows:
 * - First press: Red LED turns on
 * - Second press: Yellow LED turns on
 * - Third press: Green LED turns on
 * - Fourth press: All LEDs turn off
 * - This cycle repeats with each subsequent press
 */

// Pin definitions
const int redPin = 1;    // Traffic Light Red
const int yellowPin = 2;  // Traffic Light Yellow
const int greenPin = 3;   // Traffic Light Green
const int touchPin = 7;   // Touch Sensor IO

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

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

void loop() {
  // Check if the touch sensor is pressed
  if (digitalRead(touchPin) == HIGH) {
    // Debounce delay
    delay(50);
    if (digitalRead(touchPin) == HIGH) {
      // Increment the state
      state = (state + 1) % 4;
      // Update the LEDs based on the current state
      updateLEDs();
      // Wait for the touch sensor to be released
      while (digitalRead(touchPin) == HIGH) {
        delay(10);
      }
    }
  }
}

void updateLEDs() {
  // Reset all LEDs
  digitalWrite(redPin, LOW);
  digitalWrite(yellowPin, LOW);
  digitalWrite(greenPin, LOW);
  // Set the appropriate LED based on the state
  if (state == 1) {
    digitalWrite(redPin, HIGH);
  } else if (state == 2) {
    digitalWrite(yellowPin, HIGH);
  } else if (state == 3) {
    digitalWrite(greenPin, HIGH);
  }
}

The code is structured to run on the Arduino UNO and controls the traffic light LEDs based on the input from the touch sensor. The setup() function initializes the pins, and the loop() function continuously checks for touch sensor input to change the state of the LEDs. The updateLEDs() function is responsible for turning the appropriate LED on based on the current state.