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

Arduino UNO Controlled Traffic Light System with Touch Sensor

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

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 red, yellow, and green LEDs. The system operates by cycling through the traffic light sequence (red, yellow, green, off) each time the touch sensor is activated. The Arduino UNO is programmed to detect touch sensor inputs and control 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 the touch sensor
const int redPin = 2;   // Pin connected to the red LED
const int yellowPin = 3; // Pin connected to the yellow LED
const int greenPin = 4;  // Pin connected to the green LED

int touchState = 0; // Current state of the touch sensor
int lastTouchState = 0; // Previous state of the touch sensor
int ledState = 0; // State of the LEDs (0: all off, 1: red, 2: yellow, 3: green)

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() {
  touchState = digitalRead(touchPin);
  if (touchState == HIGH && lastTouchState == LOW) {
    ledState = (ledState + 1) % 4;
    updateLEDs();
  }
  lastTouchState = touchState;
}

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

Filename: sketch.ino

Description: The code defines the operation of the traffic light system. It sets up the pins connected to the touch sensor and LEDs as input and outputs, respectively. In the main loop, it reads the state of the touch sensor and cycles through the LED states. The updateLEDs function controls the LEDs based on the current state.