loading
So you wana learn how to programme a micro controller?

This tutorial has been designed as a next step, following the fantastic tutorial 'Ghetto Programming: Getting started with AVR microprocessor on the cheap.' by The Real Elliot link you should read this before progressing onto this next step.

Today my friends we are going to make a pelican crossing using an Ateml ATTiny2313. This is probably more common in the UK but a pelican crossing allows pedestrians to stop road traffic and cross in a safe manner.

At the end of this project you might like to mess about with the code and get the lights to sequence for your countries equivalent system, or for a junction like a cross roads (intersection).

Step 1: Parts

Ok if you are continuing this project after completing the Ghetto Programming instructable you will need to order a few extra parts. I have a list below which will detail every thing you need for this project. However if you already have the parts (Micro controller, LEDs etc..) then just leave these out. For clarity I have given the part numbers which you can use to order them directly from Rapid Online the company from which I ordered mine.

These are minimum requirements you could order more for backup or expansion of this project.

1x ATTiny2313-20PU (73-4316)
1x 20 pin socket (22-0170)
1x Parallel port plug (15-0510)
1x Breadboard (34-0655)
1x Jumper Links (34-0495)
2x Red Led's (55-0155)
1x Orange (not amber) Led (55-0124)
2x Green Led's (55-0120)
1x White Led *(55-1640)
1x Electronic Buzzer (35-0072)
1x Push to make button (78-0350)
3x 1K Resistors (62-0370)
6x 150ohm Resistors (62-0350)
5x Head Plug (22-0515)
2x Head Socket (22-5114)
1x Battery Box (18-3685)

Rapid Online

In total this came to £17.18 ex vat (approx $35.42) however you might find it cheaper else where but I doubt it.

Rapid Online offers free shipping when you spend over £5 it might be worth looking about for a few goodies and upping the led's and chips for backup if you intend to explore microchip programming further.

As well as the above parts you will need some basic stuff which you may already have...

Wire (probably about 0.5mm stranded wire)
Solder (around 22swg lead free stuff)

You will also need these tools...

Soldering Iron + Stand + Sponge
Solder Sucker/Pump
Side Cutters
Wire Strippers

Once you have all the parts you are ready to assemble your project.

Step 2: Getting Started

I am going to assume you already have the programming cable and software setup from the Ghetto project and jump straight into building the project.

Ok first we are going to lay a few things out connect the pins of the battery the the +ve and -ve lines, plug in the micro controller and the head pins.

To start with you will notice that there are 2 sets of holes running down both sides of the board each row down is interconnected up to the break in the middle of the board, effectively there are 8 strips running down the board. We are only going to use the inner 4 strips on the board. To make the top strips link with the bottom ones we need to connect them using a jumper wire. You can see the orange wires on the image below they are joining the top and bottom.

Now place the battery on the board at the bottom as close to the edge as possible and work out where its pins will rest, ensure the +ve and -ve pins are on different sides of the central divide. Using the a longer jump wire connect the pins to the +ve and -ve strips. (Notice the yellow jump wires in the image below). They are connected because the rows are connected across up to the central divide (this is different to the way the power strips work which are columns not rows).

Ok Now at the very top right of the board push the header pins into the board it should use rows 1-5 then two rows down (8) insert the microchip so it bridges the gap over the centre.

Ensure the micro controller is inserted correctly (the dip/cut semi circle should be nearest pin 8 on the breadboard).

Step 3: Wiring Up the Micro Controller

I used my own wiring for the header pin so make sure you connect your parallel port pins to the right place on the micro controller. (Just follow the instructions on the Ghetto project).

Once its wired up you should have some thing like this... If you do not already have 1k resistors on your programming cable ensure they are installed on your board to protect the parallel port on your computer from being fried.

Step 4: Installing the LEDs

Before we begin ensure all LEDs are connected the right way around. The short lead goes into the -ve supply the long one goes into the micro controller (+ve).

Also ensure you use the 150ohm resistors on the LEDs lay them out as below.

I have jumped the centre divide with resistors and put the -ve pin directly into the -ve rail so that I create a circuit, you could alternatively solder the resistor onto the long wire coming out of the LED.

Step 5: Buzz

Ok in the same way that you connected the LED's add the buzzer you don't need a resistor however if you find the noise annoying a 150ohm resistor will reduce the volume a bit.

Step 6: Inputs and Outputs

In this step we are going to connect up the outputs to the appropriate pins to get you going.

There are 6 LEDs and 1 buzzer as outputs and 1 button as input. Thats 8 pins on the chip. The best way to deal with this is to connect all the LEDs except the white one to the right hand side of the chip to ports PB0 - PB4 (see diagram)

The white LED will be connected to PD4 and the buzzer to PD3. Finally the switch will be connected to PD5.

Step 7: Home Run

Now you have it all wired up, if your microchip is still programmed from the LED flashing Ghetto project you will probably notice that the white wait LED is flashing on and off. This means its all working.

Ok next step assumes you already know how to program it from the Ghetto project.

The code below is clearly commented and there are options which I will go through in the next step. For now just load up the code and press the button!


Step 8: Preferences

In the code you have just programmed will make the lights changing very quickly but there are a set of options at the top of the file which you can edit to your own preferences.

Here is what each one does...
#define PWRSTTIME 1
In the case that power is lost the the traffic lights it makes sence for the lights to stop all traffic in case of confusion whilst a pedestrian is crossing. This preference allows you to set how long the lights stay red for before sequencing to green. (This example shows 1 second)
#define WAITTIME 1
This is the amount of time the traffic lights will wait after the button is pressed before sequencing to red. (This exampe shows 1 second)
#define CROSSTIME 1
This is the amount of time the lights will stay red to let pedestrians cross before sequencing back to green. (This example shows 1 second)
#define BEEPON 1
This states whether the beeper should sound of not 1 is on 0 is off. (It can be annoying to you and others to have this set to 1 when testing)
#define BEEPOSC 1
This defines whether the beeper should oscillate on and off. 1 is on and 0 is off.
#define AMBEROSC 1
This defines whether the amber light should oscillate on red & amber. 1 is on and 0 is always on.
#define REDONOSC 1
This defines whether the red light should be on whilst the amber light is oscilating. 1 is on 0 is off.
#define AMBEROSCNO 2
This sets how many times the amber light should oscillate. This example shows 2 oscillations (on, off, on off)
#define WALKOSC 1
This defines whether the walk light should oscillate on red & amber. 1 is on and 0 is always on.
#define WALKOSCNO 2
This sets how many times the walk light should oscillate. This example shows 2 oscillations (on, off, on, off)

Step 9: And They All Lived Happily Ever After... the End.

Ok well thats it if you want to learn more about the code read through and you will notice the '//' this indicates a comment and I have used these comments to explain what is going on.

However if you need more help or guidance I have a few links and resources below...

Before I go I would like to thank The Real Elliot for his Ghetto Programming tutorial which is what inspired me to create this project. Micah Carrick for his tutorials which helped me learn how to read inputs and thanks to you for reading this tutorial. The AVR Freaks community who helped me in the planning of this project you were a really big help. My friend Tom P who answered a few questions and also finally Paul who taught me electronics at Court More Secondary when I was young.

Links & Resources
AVR-LibC - This is the AVR-LibC programming language guide
ATTiny2313 PDF - This is the PDF documentation for the ATTiny2313 microcontroller which is used in this. It has a good pin out diagram.
Rapid Online - UK Retailer for the parts I used today
Digikey - US Retailer for the parts I used today
Electronics Information - Electronics information for beginners this site is amazing a great place to look for information about soldering, electronic components, resistor colour codes etc...
AVR Freaks - AVR Freaks is a great web community for AVR micro controller stuff.

Thanks for reading, and have fun!
<p>please send me the code of traffic light controller for the 8051...140301csr069@cutm.ac.in thanx</p>
<p>I'm making a traffic light project using parallel port instead of using a microcontroller. And I should use Assembly language to code the program. Is it possible?? Reply ASAP. Thank youuuuuuuuu!!!! :)</p>
Adnanqurban143@gmail.com <br>Contact me i would be greatfull. Want to discuss about this project because i am doing it too.
<p>Greetings,</p><p>I only have one issue - Instead of using LEDs, I am interested in making it using 3 bulbs. How do I do that?</p><p>Second, I am looking to make 4 way traffic lights, how can that be achieved? </p><p>With Best Regards</p>
hi..i m making the traffic lights project using the 8051 micocontroller..can u help me with the assembly language program code for this project.:)
i have made this project. <br>you can contact me at mukesh_9134@yahoo.in <br>
hi.. i happen to be doing the same project but as my assignment..iam asking for the codes for the 8051...dakajohnc2@gmail.com.thanx
i just started microcontroller course. any of u help me with a material for beginners? please, i will really appreciate it. thank u.<br>
Jameco.com is the cheapest
<strong>thnx for helping ..My question is that can i use usb port (serial) instead of parallal&nbsp; port ?</strong><br />
Oh ! Thank you very much ;-D
Technically, it's not a microprocessor, but a microcontroller ;-) And about the traffic lights, that's weird. I thought the protocole was the same in every countries of the european union, i mean : - red goes directly to green (no orange) - green goes orange - orange geos red (red -> green ; green -> orange -> red ) Is it really different ( red -> orange -> green ; green -> orange -> red ) in UK ??
i thought that as well, haha. i was looking at it thinking "this was featured, and he didnt even get the traffic pattern right....." didnt realize it was different other places.
NOPE not that sequence here we go red,red+amber,green,flashing green,amber,red(same sequence as UK)
FYI in the US it's yellow instead of orange. Same sequence, though.
same here,yellow instead of amber
I have corrected all instances of microchip,microprocessor etc... to microcontroller just for you! Thanks for pointing that out. :D
Oh ! Thank you very much ;-D
In the UK it is the same, you are right.As you said it probably is the same in all countries of the EU. i.e. red - green, green - orange - red
Nice tutorial your algorithm's really easy to follow. Traffic lights were one of my first projects using micro-controllers.
Glad you enjoyed it.
Hi, please can u help me with de code in c in trafic ligths using 8051 microntroller and 7 segment displayand the trafic light module, please thank you very muchhhh
What is de coding? and are u just a bot?
wow! nice project
Cool im getting started into programming and im just reading these to learn <br/><br/>but heres and idea make it like this<br/><br/><hr/>when the train comes close to the crossing somehow the train useing a microconntroller slows down and the crossing uses motors or something finds out that the train is coming up and plays the better and closes the arms would be a fun build<br/><br/>what do you think<br/>
Yeah its a good idea you would need to use a sensor and some motors but I am about to release a new article for Arduino of the same project, perhaps thats a better place to start as its far simpler code wise.
yea another fun idea would be to get a rc helicopter or make one and have sensors on the bottem so when its low it goes higher and when its too high it goes down in the sence hovering unmanned unpiolted small size helicopter?
Hang on a second, in the UK we're doing...<br/><br/><strong>red, red &amp; amber, green, amber, red.</strong> &acirc;&euro;&rdquo; <em>right?</em><br/><br/>Since my train-set days I dreamed of making traffic lights but couldn't conceive of how... since getting to Arduino..!! oh yeah! It's the business.<br/>
thats the same sequence where I live
Thanks for that I don't drive and I tried to do it from mine and my families memory. To be honest its not that important its about the programming but thanks perhapse I will get around to editing it.
Thanks for the feedback the light sequence may be wrong although I did try to ensure it was correct. However as a point of notice there are different sequences for different systems in the UK normal traffic lights follow a Red - red & amber - green sequence where as pelican crossings follow a red - red and flashing amber and green sequence. I tried to make the project adaptable for different situations as UK citizens may be aware some times the crossing beeps some times its a continuous sound
No, actually it seems correct.<br/><br/>That's interresting. I was not aware there was a 4 states sequence used in various countries. And contrary to what i tought, it's not the same in all countries of the EU ...<br/><br/>&quot;Red + Yellow/Amber/Orange&quot; == &quot;prepare your engine&quot; :-)<br/>
You sure can hold a grudge. An entirely childish and needless grudge, might I add.

About This Instructable

56,106views

79favorites

License:

More by unknowndomain:Arduino: Making a set of traffic lights Micro controller programming: Making a set of traffic lights 
Add instructable to: