Hello, i'm an EET student getting close to the end of my degree. I love the analog portion of EET, but can't stand the digital portion. I don't enjoy building logic gates etc... to achieve what could be done with programming. We have a final project worth a fair bit of our grade. They want us to build this traffic light system out of a multitude of logic gates/leds/ and a clock signal. I approached my teacher and pitched using an arduino nano on a breadboard to run everything and eliminate all these nasty gates and extra wiring. For my substitute of multisim gates i'll be using a Fritzing diagram.
Requirements 1hz clock timer
2 green/2 yellow/2 red lights
a pedestrian light simulated by led.
My problem is i've just joined an arduino club and started basic code usage. I would like to circumvent all this extra logic gate nonsense that my fellow students are doing. My teacher is on board if i can implement it. I just need a little help in how i should structure this in the code (i'm fine with wiring) and considerations i may over look in concern to an arduino
You have a project to do. Great.
It might be appropriate for the Arduino. Great.
You have no requirements. Not so good.
Or, if you do, you failed to share them.
There must be something like 422 million projects on the internet involving traffic lights and the Arduino - none of them really worth a damn because they are unrealistic, but you can learn from other people's mistakes.
How are YOU intending to make a better traffic light system?
I just need a little help in how i should structure this in the code
Start with the example in the IDE
Blink will show you the basics of how an Arduino program is structured and needs no extra hardware.
Unfortunately the delay() command block program execution while the delay occurs, so have a look at BlinkWithoutDelay. This uses millis() for timing and lets the program run freely. That is important if you are to implement a pedestrian button which could be pressed at any time so delay() will not do the job.
Get some basic LED controller programs under your belt using the millis() timing technique before think about adding pedestrian control.
green 1, yellow 1, red 1, pedestrian, green 2, yellow 2, red 2, cycle back over.
So, regardless of whether or not there are any cars going one direction, you plan to have the lights come on for fixed lengths of time. Then, regardless of whether or not there are any pedestrians around, you'll give them either way more time than needed to stroll across the road or nowhere near enough time to sprint like crazy across the road. Then, you'll allow the other, possibly non-existent, traffic to flow, again for a fixed amount of time.
And, no provisions for right or left turning traffic.
You might as well just use digitalWrite() and delay() and forget about anything like a realistic traffic light.
EET_Student:
For my substitute of multisim gates i'll be using a Fritzing diagram.
Seriously? You're electronics student? Nearing degree? And you don't even know how to draw a real circuit diagram or see at a glance why Fritzing is a no-go for any even remotely serious work? Getting a Fritzing for circuit diagram would be pretty much an automatic Fail if I would have to to grade the project.
EET_Student:
green 1, yellow 1, red 1, pedestrian, green 2, yellow 2, red 2, cycle back over.
These requirements are not even secondary school project worthy. Indeed just a list of digitalWrite() and delay() calls in loop() would do the job just fine.
Either you're not an EET student or the level of education in your part of the world is outright TERRIBLE.
green 1, yellow 1, red 1, pedestrian, green 2, yellow 2, red 2, cycle back over.
That list makes it look like only 1 LED is on at a time. Is that really the case ? What sort of junction are the traffic lights controlling, a cross junction, a T junction or maybe no junction at all just a narrow road where cars from one direction at a time are allowed to pass.
Do they still teach about FLOW CHARTS at school?
Sit down and imagine you are at the lights (even better go look at one) and look at the sequence, then put it down as a flow chart.
It is what they use to do when i was taught digital (long time ago and we had to build the computer from a kit).
Saying you have this led and that led is not instructive, better to say i have 3 sets of lights on a strip of road traffic goes in one direction only and one of the light is a pedestrian set.
The lights consist of a pole on each side of the road with the following, red on top, green on bottom and amber in the middle.
Then go on to explain what will be the sequence of events when.
A. A car approaches.
B. A car approaches but a pedestrian pushes the button to cross.
C. Its a cross road and two cars approach.
I realize you are at school but surely they let you out in the real world once in a while?
Daz
P.s. from the above you can see how others can begin to help you i hope.
Do a search on this forum for state machine tutorial. One of the projects is a traffic light like you describe. You'll learn about state machines too, although this is a very simple state machine.
Tough crowd! Keep in mind that the specs for this hypothetical traffic light system were dictated by the instructor, to be implemented with DISCRETE GATES, to demonstrate that the student can work with them. It's clearly not meant to be a real world traffic control system.
It's trivial with an Arduino. Give credit to the OP for convincing his professor to let him do it that way.