So, flibby3655

sent me a pedestrian crosswalk signal that was retired from service, (Thanks again!!) see thread:
»
A/C Switcher upperIt was indeed, all there, and had 3 wires coming from it.. Neutral (120VAC) and 2 "hots"... One to light the red "Dont walk" set of LEDs, and one to light the white "Walk" LEDs. Inside, it had a 2-channel driver for the LEDs, one for the white "Walk" lights, and one for the red "Dont walk" lights..
Very cool, but went on the back burner here at Casa D'Jason.. Been quite busy as of late, but finally (some 2 or 3 months later) got around to putting this thing together.
I used some things I had lying around, but I guess you could buy them for pretty cheap. The only things I bought for this project, was an Arduino Nano (~$18-20) and a "2 relay module" ($5 on amazon)... 5V relays, that can switch 120VAC, 10A..
In hindsight, I could have easily used an adafruit.com "Trinket" microcontroller, (can be programmed with the arduino IDE, once you install the libraries, and programmer extensions), and those are $7.99... If you choose to go this route, the same code should work with no modifications.
So.. Pictures!

Cracking it open...

Added a terminal block for the 120V hookups.

Added the relay card, and arduino nano

overall pic of the layout.

A bit closer to the final wireup

where I snuck the little button in

WALK!!!

DONT WALK!!! :-)
Quick note, I will be figuring out how to dim these LEDs.. (just need to sit down and figure out the driver circuits) They are quite bright when viewed in concert, and far too bright for the wall in my billiards room in their current state.. This was daylight viewable from across a street, so yeah.. Its a *little* bright, LOL..
and, the code!!
/*Ped Head Sketch for flibby3655 crosswalk signal...
Presented as open source, so modify, and distribute freely!
This program will pick a random time from 10 to 600 seconds (10 minutes)
to allow elapse, then trigger a walk signal.. 25 seconds later, the walk signal blinks 10 times,
then goes back to red "dont walk" and waits for a new random time to elapse.
The button will interrupt the timer, and initiate an immediate walk cycle.
let me know if this was helpful! jason@dslr.net
-------------------------------------------------------------------------*/
int crossTime = 25000; //Time that crosslight is on (before blinking) 1000 = 1 second. This is set for 25 seconds.
byte pedRed = 4; //assign the lights. Red is on Pin 4
byte pedWht = 3; //White is on pin 3
byte button = 2; //assign the button input point
unsigned long timeout; //container to hold the millisecond time between last walk cycle, and now.
unsigned long rndTime; //container to hold the random number that will initiate the next walk cycle.
unsigned long changeTime; /* time since last walk cycle..
Unsigned (no +/-) long takes 4 bytes of memory, a little bloaty, but hey.. its a simple program.
we want unsigned long, as its good to 4,294,967,295, or 4.3 billion, or ~50 days of milliseconds */
void setup()
{
pinMode(pedRed, OUTPUT); //pin for red light is OUTPUT
pinMode(pedWht, OUTPUT); //pin for white light is OUTPUT
pinMode(button, INPUT); //Button input on pin 2
//Now, lets turn the red off, and fill the "random" number with a starting value...
digitalWrite(pedRed, LOW);
rndTime = 1000; //1 secont starting value.
}
void loop()
{
int state = digitalRead(button); //Check if button is pressed
timeout = (millis() - changeTime); //populate timeout with the difference of then, and now.
if (state == HIGH || timeout > rndTime) //If Button pressed, or timeout is more than rndTime, then...
{
changeLights(); //run the sub to run the "Walk Cycle"
//Or, if neither state == HIGH, or timeout > rndTime, then go back to the top of loop, and check both again!
}
}
//And.. Heres the sub to run the "Walk Cycle! :)
void changeLights()
{
digitalWrite(pedRed, HIGH); //my relays were wired active low, so HIGH = relay (and that color LEDs) off, and LOW = Relay on. Adjust as needed here.
digitalWrite(pedWht, LOW); //Go!
delay(crossTime); //...And the old dude with his walker, finally makes it across...
digitalWrite(pedWht, HIGH); //Set green off, before performing the blink routine below
//Flash the pedGrn, to hurry them the hell up!!
for (int x=0; x<10; x++) //change x<10 to x<whatever for how many times you want the cross signal to blink, before returning to red.
{
digitalWrite(pedWht, LOW); //blink white on
delay(350); //how long to blink on
digitalWrite(pedWht, HIGH); //blink white off
delay(350); //how long to blink white off
}
//done blinking.. Turn red back on, finish this sequence up..
digitalWrite(pedRed, LOW); //No more crossing..
changeTime = millis(); //Record time since last cycle run
rndTime = (random(1, 60) * 10000); //Set new random time to trip the cycle again
//then return to the main loop
}
Thank you, Flibby for the PedHead!
If I had to buy everything I used to control the PedHead, but used a Trinket rather than an arduino Nano, I'd figure it would be about $30-$40 in parts on the high end..
Except for the copious commenting I added to the code, it was a rather simple, but fun project. :-)
So... Did you get in on the PedHead offer? If so, Let me see your PedHeads!!
--
When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.