coding

My partners and I have been working on this code, our skills for coding is kind of limited so we wonder if could have help with suggestions. The main purpose is to simulate a Traffic light intersection. We are using ultrasonic sensors to count the incoming traffic approaching the intersection. Depending which lane have heavier flow, the green light will be prioritize with longer time. and then alternate the lanes, until it resets. We also have a code for a simulation of an emergency vehicle approaching the intersection. We used an RF transmitter and Receiver sensors to send the incoming signal of the E. Vehicle. The Arduino is going to receive the signal and flash LEDs blue and white. This is the signal for the approach of the E.vehicle.
We got the car counting working, and everything involve around that part of the code.
our main concern is the blue and white LEDs not flash long enough, like it kind of get the signal but it doesn't last as we desire to be.

This is my code if anyone of you all have any suggestions, why it won't work correctly please fell free to advice.

Final_code.ino (8.95 KB)

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

and then alternate the lanes, until it resets.

Until what resets?

We used an RF transmitter and Receiver sensors to send the incoming signal of the E. Vehicle.

That there is an oncoming emergency vehicle is ALL that you will learn. How far away it is, what its speed is, which direction it is coming from, and which direction it wants to go are not things you will learn from just a radio.

In the USA, almost every place that tried to implement priority light control for emergency vehicles have removed the equipment and programming, because the systems had nowhere near enough information, like your system, and the implementations caused more problems than they solved.

We are using ultrasonic sensors to count the incoming traffic approaching the intersection.

You are obviously not scaling this for full size vehicles. Ultrasonic sensors just don't have the range to count the number of approaching vehicles far enough back from the traffic light to provide meaningful information.

Before you write another line of code, go study a real traffic light. The priority is assigned based on how long a vehicle has sat waiting for a green light and on long-term counting of vehicle traffic in each lane. It has little to do with traffic flow right now.

rodluiton01:
This is my code if anyone of you all have any suggestions, why it won't work correctly please fell free to advice.

Please use the AutoFormat tool to indent your code so it is easy to read and to see where the different code blocks start and end.

For this sort of program you should NOT be using WHILE or delay() and both block the Arduino until they complete. Allow loop() to do the repetition - that's what it is for. And use millis() to manage timing without blocking in as illustrated in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

There should be absolutely no need for a reset() function.

...R