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

Arduino UNO Controlled Traffic Light with Servo Barrier

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Traffic Light with Servo Barrier

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a set of LEDs and a servo motor using an Arduino UNO microcontroller. The circuit includes a red LED and a green LED, each with a current-limiting resistor, and a Tower Pro SG90 servo motor. The system is powered by a 9V battery, which is stepped down to 5V by the Arduino UNO to power the servo motor. The red and green LEDs are controlled by digital pins on the Arduino, which also sends a control signal to the servo motor. The code for the Arduino is written to simulate a traffic light system with a barrier, where the red LED represents the stop signal and the green LED represents the go signal. The servo motor acts as a barrier that raises and lowers in sync with the LEDs.

Component List

LEDs

Resistors

Microcontroller

Servo Motor

Power Source

Wiring Details

Red LED

Green LED

Resistors

Arduino UNO

Tower Pro SG90 servo

Battery 9V

Documented Code

#include <Servo.h>

// Define pins for the LEDs and servo motor
const int redLed = 6;
const int greenLed = 7;
const int servoPin = 9;

Servo myServo;  // Create a Servo object

void setup() {
  // Initialize the LEDs
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  
  // Attach the servo to pin 9
  myServo.attach(servoPin);
  
  // Start with the red light on and the barrier raised
  digitalWrite(redLed, HIGH);
  digitalWrite(greenLed, LOW);
  myServo.write(90); // Barrier raised position
}

void loop() {
  // Simulate red light for 5 seconds
  digitalWrite(redLed, HIGH);
  digitalWrite(greenLed, LOW);
  myServo.write(90);  // Keep barrier raised
  delay(5000);  // Wait for 5 seconds
  
  // Simulate green light for 5 seconds
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, HIGH);
  myServo.write(0);  // Lower the barrier
  delay(5000);  // Wait for 5 seconds
}

The code above is written for the Arduino UNO and is responsible for controlling the LEDs and servo motor. It sets up the pins, initializes the servo, and then enters a loop where it alternates between the red and green LEDs, simulating a traffic light with a barrier. The servo motor's position is controlled in sync with the LEDs, raising the barrier when the red LED is on and lowering it when the green LED is on.