Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO Touch-Activated Traffic Light Controller

Image of Arduino UNO Touch-Activated Traffic Light Controller

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 activation changes the state of the traffic light from red to yellow to green and then off. The circuit uses the Arduino UNO's digital pins to interface with the touch sensor and to control the individual LEDs of the traffic light.

Component List

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Pins Used: IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13.
  • Purpose: Acts as the central processing unit for the circuit, reading the touch sensor input and controlling the traffic light LEDs.

Touch Sensor

  • Description: A capacitive touch sensor module.
  • Pins Used: IO, VCC, GND.
  • Purpose: Provides user input to the system to change the state of the traffic light.

Traffic Light

  • Description: A module with three LEDs representing the green, yellow, and red lights of a traffic signal.
  • Pins Used: Green, Yellow, Red, GND.
  • Purpose: Displays the traffic light state as controlled by the Arduino UNO.

Wiring Details

Arduino UNO

  • 5V connected to the VCC of the touch sensor.
  • GND connected to the GND of the traffic light and the GND of the touch sensor.
  • D7 connected to the IO of the touch sensor.
  • D4 connected to the Green LED of the traffic light.
  • D3 connected to the Yellow LED of the traffic light.
  • D2 connected to the Red LED of the traffic light.

Touch Sensor

  • VCC connected to the 5V of the Arduino UNO.
  • GND connected to the GND of the Arduino UNO.
  • IO connected to the D7 of the Arduino UNO.

Traffic Light

  • Green connected to the D4 of the Arduino UNO.
  • Yellow connected to the D3 of the Arduino UNO.
  • Red connected to the D2 of the Arduino UNO.
  • GND connected to the GND of the Arduino UNO.

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: 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();
    delay(200); // Debounce delay
  }
  lastTouchState = touchState;
}

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

This code is written for the Arduino UNO and is responsible for reading the state of the touch sensor and updating the traffic light LEDs accordingly. The setup() function initializes the pins and sets the initial state of the LEDs to off. The loop() function continuously checks the state of the touch sensor and updates the LEDs based on the current state. The updateLEDs() function sets the appropriate LED to on based on the ledState variable, which cycles through the values 0 to 3, representing the off, red, yellow, and green states, respectively.