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

Arduino UNO Controlled Traffic Light with Touch Sensor Activation

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

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: red, yellow, green, and off. The Arduino UNO reads the state of the touch sensor and lights up the corresponding LED on the traffic light module.

Component List

Touch Sensor

Arduino UNO

Traffic Light Module

Wiring Details

Touch Sensor

Arduino UNO

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 IO
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);
  if (touchState == HIGH && lastTouchState == LOW) {
    state = (state + 1) % 4;
    updateLEDs();
    delay(200); // Debounce delay
  }
  lastTouchState = touchState;
}

void updateLEDs() {
  digitalWrite(redPin, state == 1 ? HIGH : LOW);
  digitalWrite(yellowPin, state == 2 ? HIGH : LOW);
  digitalWrite(greenPin, state == 3 ? HIGH : LOW);
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It sets up the necessary pins for input and output and contains a main loop that reads the touch sensor state. When a touch is detected, it cycles through the traffic light states and updates the LEDs accordingly. The updateLEDs function is responsible for turning the appropriate LED on or off based on the current state.