Of course, the Arduino can't switch anything high voltage nor high amperage. So you'll need to use a relay. I am a big fan of the cheap relay boards like these. For a regular stop light, you'll need three individuals or a four in one. I used a four in one relay board and a two in one separate board for the crosswalk lights. I stuffed it all in a plastic enclosure box. Don't undertake the high voltage part of this project without a firm understanding of the risks involved. This post isn't about high voltage relays or how to integrate them with the Arduino, so I'll assume you know how to do that. Follow along if you want to build a stop light simulator with 5mm LEDs, the same principles apply.
ATtiny 85 |
Since the ATtiny chips run off 5v I planned on using a commodity USB power supply. Since the ATtiny85 has an internal clock chip, it's easier to build a circuit (no external crystal). My original stop light controller was powered by an Arduino Micro (about $20). So I wanted this new controller to be smaller and cheaper. My total cost to replace the Micro was about $3.
Since I used only 5 outputs and no inputs for my light controller, the ATtiny85 is about the smallest and cheapest of the Atmel chips that will do the job.
First, to program the chip. I used a programmer shield, but you can use some hookup wire and do it yourself or build your own shield. Follow these directions if you want to take that route.
Program it! |
"
int Walk = 3;
int DontWalk = 4;
int Green = 0;
int Yellow = 1;
int Red = 2;
void setup()
{
pinMode(Walk, OUTPUT);
pinMode(DontWalk, OUTPUT);
pinMode(Green, OUTPUT);
pinMode(Yellow, OUTPUT);
pinMode(Red, OUTPUT);
}
void loop()
{
//HIGH = ON, LOW = OFF
digitalWrite(Walk, LOW);
digitalWrite(DontWalk, LOW);
digitalWrite(Green, LOW);
digitalWrite(Yellow, LOW);
digitalWrite(Red, LOW);
digitalWrite(Green, HIGH);
digitalWrite(Walk, HIGH);
delay(800);
digitalWrite(Walk, LOW);
digitalWrite(DontWalk, HIGH);
delay(50);
digitalWrite(DontWalk, LOW);
delay(50);
digitalWrite(DontWalk, HIGH);
delay(50);
digitalWrite(DontWalk, LOW);
delay(50);
digitalWrite(DontWalk, HIGH);
delay(50);
digitalWrite(DontWalk, LOW);
delay(50);
digitalWrite(DontWalk, HIGH);
delay(50);
digitalWrite(DontWalk, LOW);
delay(50);
digitalWrite(DontWalk, HIGH);
delay(200);
digitalWrite(Green, LOW);
digitalWrite(Yellow, HIGH);
delay(350);
digitalWrite(Yellow, LOW);
digitalWrite(Red, HIGH);
delay(1200);
}
"
Now to breadboard it. Follow this pinout guide to wire it up. Here I used LEDs to take the place of the relay outputs to see if it looked like a stop light and to test my timings. Since my relays are triggered by a "high" signal, when the LED is on, the relay would be triggered to send the high voltage to the light.
It works! Now to solder.
Top of the board |
Bottom, my lackluster soldering skills... |
Here is the final, ready to be buttoned up project.
Provided you don't need a bunch of inputs/outputs the ATtiny might be a cost, and perhaps more importantly size, effective solution.
Here's the Fritzing diagram:
No comments:
Post a Comment