Project showcase
Traffic Advisor (arrow stick)

Traffic Advisor (arrow stick) © CC BY

8 light, rear of vehicle traffic advisor controller, with 4 modes and 14 patterns.

  • 796 views
  • 0 comments
  • 2 respects

Components and supplies

Necessary tools and machines

About this project

UPDATE: I used some strip lights and a relay board to install the original project into my truck. the code has not changed, the video below is the controller, this video the full install.

I wanted to see how hard it would be to make this.

this is a traffic advisor controller.

it controls 8 light segments and has a small led readout to show you what pattern is currently being used.

a power light to show that power is on.

6 buttons that do various actions

button 1: left arrow

button 2: center out

button 3: right arrow

button 4: warning patterns

button 5: switch warning pattern

button 6: turn off lights/ save warning pattern

there are the 3 directional patterns and 10 warning patterns.

any mode can be activated at any time with no delay.

warning patterns are:

1:even / odd fast flash

2: half and half

3: half and half with fast flash

4: 2 by 2

5: 2 by 2 parallel

6: out flash

7: 3 out center

8: outboard

9:inboard

10: even / odd slow

Code

CodeC/C++
.INO
#include <EEPROM.h>
int warning_button = A5;
int left_button = 2;
int center_button = 4;
int right_button = 3;
int off_button = A0;
int pattern_button = A2;
int statuslight = 13;
int LEDright[] = {5, 6, 7, 8, 9, 10, 11, 12};
int LEDleft[] = {12, 11, 10, 9, 8, 7, 6, 5};
int centerleft[] = {9, 10, 11, 12};
int centerright[] = {8, 7, 6, 5};
int light = 0;
int counter = 1;
int pattern_count = 0;
int warning_count = EEPROM.read(0);
long lasttimer = 0;
static long timer = 200;
static long timer2 = 300;
static long switch_timer = 4000;
#define LEFTside 0x0
#define RIGHTside 0x1
byte whichLED = LEFTside;
byte LEFT_state = LOW;
byte RIGHT_state = LOW;
unsigned long switchDelay = 1000;
unsigned long switchDelay2 = 500;
unsigned long strobeDelay = 75;
unsigned long strobeWait = strobeDelay;
unsigned long waitUntilSwitch = switchDelay;
unsigned long sequenceStartTime;
//----------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  for (int i = 0; i < 8; i++) {
    pinMode(LEDright[i], OUTPUT);
  }
  pinMode(statuslight, OUTPUT);
  pinMode(warning_button, INPUT_PULLUP);
  pinMode(left_button, INPUT_PULLUP);
  pinMode(center_button, INPUT_PULLUP);
  pinMode(right_button, INPUT_PULLUP);
  pinMode(off_button, INPUT_PULLUP);
  pinMode(pattern_button, INPUT_PULLUP);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
}
//------------------------------------------------------------------------
void loop() {
  digitalWrite(13, HIGH);
  delayMicroseconds(10); // Approximately 10% duty cycle @ 1KHz
  digitalWrite(13, LOW);
  delayMicroseconds(1000 - 10);
  if (digitalRead(pattern_button) == HIGH)
  {
    delay(500);
    warning_count++;
    if (warning_count > 10) {
      warning_count = 1;
    }
  }
  if (digitalRead(warning_button) == HIGH)
  {
    delay(50);
    pattern_count = 1; 
  }
  if (digitalRead(left_button) == HIGH)
  {
    delay(50);
    pattern_count = 2;
  }
  if (digitalRead(center_button) == HIGH)
  {
    delay(50);
    pattern_count = 3;
  }
  if (digitalRead(right_button) == HIGH)
  {
    delay(50);
    pattern_count = 4;
  }
  if (digitalRead(off_button) == HIGH)
  {
    delay(50);
    pattern_count = 0;
    EEPROM.update(0,warning_count);
  }
  switch (pattern_count) {
    case 0:
      pattern_off();
      break;
    case 1:
      traffic_left();
      break;
    case 2:
      traffic_center();
      break;
    case 3:
      traffic_right();
      break;
    case 4:
      traffic_warning();
      break;
  }
}
void pattern_off() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
}
void traffic_left() {
  unsigned long currenttimer = millis();
  if (currenttimer - lasttimer >= timer) {
    lasttimer = currenttimer;
    for (int i = 0; i <= 7; i++) {
      digitalWrite(LEDright[i], LOW);
    }
    digitalWrite(LEDleft[light], LOW);
    light = light + counter;
    if (light > 7) {
      light = 0;
      counter = 1;
    }
    digitalWrite(LEDleft[light], HIGH);
  }
}
void traffic_center() {
  unsigned long currenttimer = millis();
  if (currenttimer - lasttimer >= timer2) {
    lasttimer = currenttimer;
    for (int i = 0; i <= 7; i++) {
      digitalWrite(LEDright[i], LOW);
    }
    digitalWrite(centerright[light], LOW);
    digitalWrite(centerleft[light], LOW);
    light = light + counter;
    if (light > 3) {
      light = 0;
      counter = 1;
    }
    digitalWrite(centerright[light], HIGH);
    digitalWrite(centerleft[light], HIGH);
  }
}
void traffic_right() {
  unsigned long currenttimer = millis();
  if (currenttimer - lasttimer >= timer) {
    lasttimer = currenttimer;
    for (int i = 0; i <= 7; i++) {
      digitalWrite(LEDright[i], LOW);
    }
    digitalWrite(LEDright[light], LOW);
    light = light + counter;
    if (light > 7) {
      light = 0;
      counter = 1;
    }
    digitalWrite(LEDright[light], HIGH);
  }
}
void traffic_warning() {
  switch (warning_count) {
    case 1:
      even_odd_flash();
      break;
    case 2:
      half_half();
      break;
    case 3:
      half_half_flash();
      break;
    case 4:
      two_by_two();
      break;
    case 5:
      two_by_two_parallel();
      break;
    case 6:
      out_flash();
      break;
    case 7:
      one_center();
      break;
    case 8:
      outboard();
      break;
    case 9:
      inboard();
      break;
    case 10:
      even_odd();
      break;
  }
}
void even_odd_flash() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  digitalWrite(12, LEFT_state);
  digitalWrite(11, RIGHT_state);
  digitalWrite(10, LEFT_state);
  digitalWrite(9, RIGHT_state);
  digitalWrite(8, LEFT_state);
  digitalWrite(7, RIGHT_state);
  digitalWrite(6, LEFT_state);
  digitalWrite(5, RIGHT_state);
  if ((long)(millis() - waitUntilSwitch) >= 0) {
    LEFT_state = LOW;
    RIGHT_state = LOW;
    whichLED = !whichLED;
    waitUntilSwitch += switchDelay;
  }
  if ((long)(millis() - strobeWait) >= 0) {
    if (whichLED == LEFTside)
      LEFT_state = !LEFT_state;
    if (whichLED == RIGHTside)
      RIGHT_state = !RIGHT_state;
    strobeWait += strobeDelay;
  }
}
void half_half_flash() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  digitalWrite(12, LEFT_state);
  digitalWrite(11, LEFT_state);
  digitalWrite(10, LEFT_state);
  digitalWrite(9, LEFT_state);
  digitalWrite(8, RIGHT_state);
  digitalWrite(7, RIGHT_state);
  digitalWrite(6, RIGHT_state);
  digitalWrite(5, RIGHT_state);
  if ((long)(millis() - waitUntilSwitch) >= 0) {
    LEFT_state = LOW;
    RIGHT_state = LOW;
    whichLED = !whichLED;
    waitUntilSwitch += switchDelay2;
  }
  if ((long)(millis() - strobeWait) >= 0) {
    if (whichLED == LEFTside)
      LEFT_state = !LEFT_state;
    if (whichLED == RIGHTside)
      RIGHT_state = !RIGHT_state;
    strobeWait += strobeDelay;
  }
}
void half_half() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 250)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    digitalWrite(6, LOW);
    digitalWrite(5, LOW);
  }
  else if (time < 500)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    digitalWrite(8, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
  }
  else sequenceStartTime = millis();
}
void out_flash() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 150)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
  }
  else if (time < 300)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(5, LOW);
  }
  else sequenceStartTime = millis();
}
void two_by_two() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 150)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
  }
  else if (time < 300)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(5, LOW);
  }
  else sequenceStartTime = millis();
}
void two_by_two_parallel() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 150)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, LOW);
    digitalWrite(9, LOW);
    digitalWrite(8, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(5, LOW);
  }
  else if (time < 300)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
  }
  else sequenceStartTime = millis();
}
void one_center() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 500)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(9, LOW);
    digitalWrite(8, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(6, LOW);
    digitalWrite(5, LOW);
  }
  else if (time < 1000)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
  }
  else sequenceStartTime = millis();
}
void outboard() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 200)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(5, LOW);
  }
  else if (time < 400)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(5, HIGH);
  }
  else sequenceStartTime = millis();
}
void inboard() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 200)
  {
    digitalWrite(11, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(6, HIGH);
  }
  else if (time < 400)
  {
    digitalWrite(11, LOW);
    digitalWrite(10, LOW);
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(6, LOW);
  }
  else sequenceStartTime = millis();
}
void even_odd() {
  for (int i = 0; i <= 7; i++) {
    digitalWrite(LEDright[i], LOW);
  }
  long time = millis() - sequenceStartTime;
  if (time < 300)
  {
    digitalWrite(12, HIGH);
    digitalWrite(11, LOW);
    digitalWrite(10, HIGH);
    digitalWrite(9, LOW);
    digitalWrite(8, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(5, LOW);
  }
  else if (time < 600)
  {
    digitalWrite(12, LOW);
    digitalWrite(11, HIGH);
    digitalWrite(10, LOW);
    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(5, HIGH);
  }
  else sequenceStartTime = millis();
}

Schematics

schematic
Schematic testing sheet 1 20200328204449 wm7oryju81

Comments

Similar projects you might like

Traffic Monitor- Monitors traffic on the Go

Project tutorial by Patel Darshil

  • 7,135 views
  • 0 comments
  • 13 respects

Let's Build an SN76489 USB MIDI Synth With Arduino Nano

Project tutorial by tyrkelko

  • 1,569 views
  • 1 comment
  • 5 respects

Arduino Controlled Traffic Lights for Kids Without Delay()

Project showcase by stemmayhem

  • 7,137 views
  • 8 comments
  • 42 respects

Intersection with Traffic Lights

Project showcase by Lucky_G

  • 4,156 views
  • 0 comments
  • 14 respects

Smart Traffic Light

Project showcase by Fady Tarek

  • 12,247 views
  • 9 comments
  • 24 respects

Traffic Lights Controlled by Arduino

Project showcase by lmsousa

  • 8,467 views
  • 2 comments
  • 21 respects
Add projectSign up / Login