ATtiny85 Toy Traffic Light

by simon.w.nordberg in Circuits > Arduino

5226 Views, 36 Favorites, 0 Comments

ATtiny85 Toy Traffic Light

551c0055182470406f000001.jpeg
2015-03-17 02.58.35.jpg

This is a toy traffic light i made for a friends son! Using only a few parts and an ATtiny85!

Materials

Materials used:

3 LED's (red, yellow and green).

3 Resistors.

3 AA batteries.

1 3 AA battery holder.

1 Switch.

1 ATtiny85.

1 8 pin dip socket.

1 Small piece of bread board.

1 Arduino Leonardo (doesn't have to be a Leonardo).

1 Breadboard and jumpers.

A few pieces of wood

1 inch dowel

Tools used:

Basic woodworking tools.

Wirecutter/stripper.

Soldering iron.

Hot glue gun.

Spray paint.

Breadboard

Skärmavbild 2015-03-17 kl. 03.23.03.png
2015-03-17 03.08.39.jpg

This is the circuit on a breadboard. Always test your circuit on a breadboard before you build it!

I used 65 Ohm resistors. Your circuit might require another resistor value so use Ohm's law to calculate your resistor value.

To learn how to program the ATtiny85 and upload your sketch, check out: http://dev.mikamai.com/post/78652180658/how-to-program-an-attiny85-or-attiny45-with-an

I used an Arduino Leonardo for this.

Code

I am not a programmer so this is really basic stuff. There might be a better way of doing it. Please comment if you have any suggestions or improvements!

I don't know if traffic light signals are the same over the world, but here in Sweden it goes like this: Red, Red AND Yellow, Green, Yellow, and back to Red.

The code just cycles through the LEDs forever (or until turned off).

This is the final code I uploaded to the ATtiny85 so the pinmodes described here are for the ATtiny85 since it only has 5 outputs.

//Traffic light toy sketch for ATtiny85. by: Simon Nordberg.

void setup() {

pinMode(0, OUTPUT); //Red LED.

pinMode(1, OUTPUT); //Yellow LED.

pinMode(2, OUTPUT); //Green LED. }

//Looping forever

void loop() {

digitalWrite(0, HIGH); // Turn on red LED.

delay(3000); //Waits for 3 sec.

digitalWrite(1, HIGH); //Turn on yellow LED.

delay(2000); //Waits for 2 sec.

digitalWrite(0, LOW); //Turn off red LED.

digitalWrite(1, LOW); //Turn off yellow LED.

digitalWrite(2, HIGH); //Turn on green LED.

delay(5000); //Waits for 5 sec.

digitalWrite(2, LOW); //Turn off green LED.

digitalWrite(1, HIGH); //Turn on yellow LED.

delay(2000); //Waits for 2 sec.

digitalWrite(1, LOW); //Turn off yellow LED.

}

Building

Base: Drill out the base and carve out enough room the fit the batteries, circuit and the switch.


Pole: Drill a hole through the dowel to fit the LED wires through.

Head: Drill 3 holes in the head to fit the LEDs. Drill a hole through the bottom of the head and insert the LEDs from the bottom.

Assembly: Glue the head to the pole and the pole the the base. Before attaching the batteries, Solder the wires to the circuit board.

With a bit of planning, all this fits together nicely! :)

You're Done!

551c035f1824708e6e000002.jpeg

That's it! Enjoy building your toy traffic light!