Project showcase
2-Way Intersection with Pedestrian Walk Cycle

2-Way Intersection with Pedestrian Walk Cycle © GPL3+

Pedestrian walk cycle will only occur when both lights are red AND button has been pressed.

  • 3,879 views
  • 2 comments
  • 8 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
Tested on the Uno, but easily converted for other Arduino boards
×1
09590 01
LED (generic)
3 RED, 2 Yellow, 2 Green, and 1 White
×8
Mfr 25fbf52 221r sml
Resistor 221 ohm
Current Limiting resistors, use minimum 220 ohms
×8
Mfr 25frf52 1k sml
Resistor 1k ohm
×1
Mfr 25frf52 10k sml
Resistor 10k ohm
Used as a Pull-Down resistor on button
×1
Omron b3f 1000 image 75px
SparkFun Pushbutton switch 12mm
Acts as "Walk Requested" push button
×1

About this project

This is a two-way traffic system (USA) that has a main and an auxillary lighting circuit. Once the walk button is pressed, the program waits till both circuits return to red before performing a WALK/DON'T WALK cycle. A software reset guarantees that main will get the green light first after the walk cycle completes.

Code

Two-Way Intersection with Intellegent Pedestrian Walk CycleArduino
Two-Way traffic system (USA) that has a MAIN and an AUXILLARY lighting circuit. Once the Walk button is pressed, the program waits till both circuits return to RED before performing a WALK/DON"T WALK cycle. A software reset guarantees that MAIN will get the green light first after Walk Cycle completes.
/* 2017 Falcom Digital Imaging L.L.C. for
    Dean Institute of Technology PLC Class Use

    Setup Variables for Walk Cycle Components.
  You use "const int" if you want to reference a value by name -
  you use it just like any ordinary int, but you cannot change the value.
  This does not use any RAM.*/
int WalkRequest = 0;  // Variable used to store the state of the Walk Push Button
const int WalkButton = 2;
const int RedPedLED = 6;
const int WhitePedLED = 7;

//  Setup Variables for Station 1 Traffic Light Components
const int Red1LED = 8;
const int Yellow1LED = 9;
const int Green1LED = 10;

//  Setup Variables for Station 2 Traffic Light Components
const int Red2LED = 11;
const int Yellow2LED = 12;
const int Green2LED = 13;

// variables that will change:
volatile int buttonState = 0;  // variable for monitoring the pushbutton status.
/* A variable should be declared volatile whenever its value can be changed
  by something beyond the control of the code section in which it appears,
  such as a concurrently executing thread.
  In the Arduino, the only place that this is likely to occur is in sections
  of code associated with interrupts, called an interrupt service routine (ISR)  */




void setup() {
  pinMode(RedPedLED, OUTPUT);  //  Sets all LED's as OUTPUT
  pinMode(WhitePedLED, OUTPUT);
  pinMode(Red1LED, OUTPUT);
  pinMode(Yellow1LED, OUTPUT);
  pinMode(Green1LED, OUTPUT);
  pinMode(Red2LED, OUTPUT);
  pinMode(Yellow2LED, OUTPUT);
  pinMode(Green2LED, OUTPUT);
  pinMode(WalkButton, INPUT);  //  Sets Push Button as INPUT

  attachInterrupt(0, pin_ISR, CHANGE);  //  "Watches" in the background for a button press
  /* Attach an interrupt to the ISR vector to monitor Push Button.
    Number 0 (for digital pin 2) or number 1 (for digital pin 3) are used.
    Interrupts are useful for making things happen automatically in
    microcontroller programs,and can help solve timing problems.
    Good tasks for using an interrupt may include reading
    a rotary encoder, or monitoring user input */

  // Set Initial state of all red LED to HIGH
  digitalWrite (Red1LED, HIGH);
  digitalWrite (Red2LED, HIGH);
  digitalWrite (RedPedLED, HIGH);
}




void loop() {
  // put your main code here, to run repeatedly:

  // Station 1 Timing
  delay(2500);  //  2.5 Seconds of Red
  digitalWrite(Red1LED, LOW);  //  Sets Red1 OFF Green ON
  digitalWrite(Green1LED, HIGH);
  delay(15000);  // 15 Seconds of Green
  digitalWrite(Green1LED, LOW);  //  Sets Green1 OFF Yellow ON
  digitalWrite(Yellow1LED, HIGH);
  delay(3500);  // 3.5 Seconds of Yellow
  digitalWrite(Yellow1LED, LOW);  //  Sets Yellow1 OFF Red ON
  digitalWrite(Red1LED, HIGH);

  if (WalkRequest == 1) {  //  If the button has been pressed
    WalkCycle();  //  Exit main loop and run WalkCycle () function
  }



  // Station 2 Timing
  delay(2500);  //  2.5 Seconds of Red
  digitalWrite(Red2LED, LOW); digitalWrite(Green2LED, HIGH);  //  Sets Red2 OFF Green ON
  delay(15000);  // 15 Seconds of Green
  digitalWrite(Green2LED, LOW); digitalWrite(Yellow2LED, HIGH);  //  Sets Green2 OFF Yellow ON
  delay(3500);  // 3.5 Seconds of Yellow
  digitalWrite(Yellow2LED, LOW); digitalWrite(Red2LED, HIGH);  //  Sets Yellow2 OFF Red ON

  if (WalkRequest == 1) {  //  If the button has been pressed
    WalkCycle();  //  Exit main loop and run WalkCycle () function
  }
}



void WalkCycle() {
  delay(3500);  //  3.5 Second delay before "WALK" begins
  digitalWrite (WhitePedLED, HIGH); digitalWrite (RedPedLED, LOW);  // Turn on White Pedestrian Light
  delay (15000);  // 15 Second delay to allow crossing street
  digitalWrite (WhitePedLED, LOW); digitalWrite(WalkButton, LOW);  // Turn off White Pedestrian Light
  delay(250);
  for (int x = 0; x < 5; x++) {  // Flash White Ped LED 5X
    digitalWrite(WhitePedLED, HIGH);
    delay(250);
    digitalWrite(WhitePedLED, LOW);
    delay(250);
  }
  digitalWrite(RedPedLED, HIGH);
  WalkRequest = 0; //  Reset Push Button
  asm volatile ("  jmp 0");  // Soft-reset of sketch. Makes sure Station 1 "MAIN" always gets Green after a walk cycle
}




void pin_ISR() {
  buttonState = digitalRead(WalkButton);
  (WalkRequest = 1);  //  Walk button has been pressed
  // digitalWrite(WhitePedLED, buttonState);  // Test Light for Interrupt use only during testing!
}

Schematics

trafficsystemwithwalk_r6RVpUxvk5.jpg
Trafficsystemwithwalk r6rvpuxvk5

Comments

Similar projects you might like

Weather Clock

Project showcase by Tittiamo

  • 11,459 views
  • 9 comments
  • 27 respects

GPS Datalogger, Spatial Analysis, and Azure IoT Hub.

Project tutorial by Shawn Cruise

  • 21,525 views
  • 4 comments
  • 79 respects

Arduino Pedestrian Crossing Traffic Lights

by NatalMakers

  • 6,186 views
  • 0 comments
  • 21 respects

Morse Code Transmitter - Light Signal

Project showcase by Alireza Karkon

  • 2,746 views
  • 1 comment
  • 7 respects

LED Dice

Project showcase by Team ONYX

  • 9,710 views
  • 1 comment
  • 18 respects

Test DHT22 Sensors with Arduino and MATLAB

Project tutorial by dancili

  • 6,135 views
  • 4 comments
  • 22 respects
Add projectSign up / Login