PDA

View Full Version : Help traffic light system using PicBasic Pro



davidweyam
- 29th April 2013, 17:02
Hello

Im ME student and I have to do project in EE department
I spend one week to learn PicBasic Pro but but until now I do not have that experience to WRITE my project

My project is about writing a program to control traffic light on cross road by using PicBasic Pro language

I have 4 traffic light to control 3 led on each that 12 led on total
[red,green,Orange]
also 3 situation that describe the number of car on the road

Normal : 10 cars/min
above Normal:15 cars/min
below Normal: 5 cars/min

so I need to add a sensor to detect the number of car on the road from the number of car I have to define
how much of time should be pause to allow smooth and avoid traffic jam.

---------------------

The idea here that we connected 3×4 (3: light on each traffic light represent the colors Red, Yellow, Green then 4: represent the number of the traffic lights on the cross street) lights to 2 ports of the PIC16f877 PORTB & PORTC …
Traffic light #1 SE took the following: PB0, PB1, PB2 (RED, YELLOW, GREEN)
traffic light #2 SW took the following: PB3, PB4, PB5 (RED, YELLOW, GREEN)
traffic light #3 SN took the following: PB6, PB7, PC0 (RED, YELLOW, GREEN)
traffic light #4 SS took the following: PC1, PC2, PC3 (RED, YELLOW, GREEN)

E east
W west ..

; Define the variable and constant
SS var byte
SW var byte
SN var byte
SE var byte
; Define the I/O of the microcontroller
LEDGS var PORTB.2, LEDYS var PORTB.1, LEDRS var PORTB.0
LEDGW var PORTB.5, LEDYW var PORTB.4, LEDRW var PORTB.3
LEDGN var PORTC.0, LEDYN var PORTB.7, LEDRN var PORTB.6
LEDGE var PORTC.3 LEDYE var PORTC.2, LEDRE var PORTC.1
SS var PORTA.0, SW var PORTA.1, SN var PORTA.2
SE var PORTA.3


I need ur help to write this program

AvionicsMaster1
- 1st May 2013, 04:49
After I thought about this for a while you really only need to control 6 LED outputs as North and South would be the same while East and West would be the same.

I would suggest you use the low volume as the default configuration as it's easier to add time than to subtract time. You'd have to sit down and figure out how long you wanted the low volume to be on and how much you'd have added during medium and high volume.

YOU would have to figure out how to sense volume using a timer of some sorts triggered by car movements. Don't forget PBP only does integers. Set a flag when it's medium volume and a different one when it's high. Use a CASE SELECT to choose which SUB to run.

If you want to impress your professor I'd include a routine to check that NS and EW aren't the same. If they are then you should do the total flashing reds.

Use a flow chart and it shouldn't be too difficult. Best wishes

Jumper
- 1st May 2013, 05:12
Hi,

And since you mention number of cars per minute I suggest you also look into DT's instant interupts so you can set up a real time clock that will run in the background to keep time for you. Easy? Not really but much easier than you would expect. It also depends a little bit on what PIC you will use for the project. Really tiny small ones when talking about memory size might not be up to the task.

davidweyam
- 3rd May 2013, 16:07
After I thought about this for a while you really only need to control 6 LED outputs as North and South would be the same while East and West would be the same.

I would suggest you use the low volume as the default configuration as it's easier to add time than to subtract time. You'd have to sit down and figure out how long you wanted the low volume to be on and how much you'd have added during medium and high volume.

YOU would have to figure out how to sense volume using a timer of some sorts triggered by car movements. Don't forget PBP only does integers. Set a flag when it's medium volume and a different one when it's high. Use a CASE SELECT to choose which SUB to run.

If you want to impress your professor I'd include a routine to check that NS and EW aren't the same. If they are then you should do the total flashing reds.

Use a flow chart and it shouldn't be too difficult. Best wishes

How NS & EW aren't the same ?

and Is this relation right
x= default time in ms
n= number of car / 1 min
f= factor

T= x + n * f
then in the program I write
Pause T

I do not have gd background in PicBasic Pro But I have to do this project
I hope ur help

and thanks you for your suggestion :)

davidweyam
- 3rd May 2013, 16:10
Hi,

And since you mention number of cars per minute I suggest you also look into DT's instant interupts so you can set up a real time clock that will run in the background to keep time for you. Easy? Not really but much easier than you would expect. It also depends a little bit on what PIC you will use for the project. Really tiny small ones when talking about memory size might not be up to the task.

thanks for ur reply

I use Pic 16F877a

davidweyam
- 4th May 2013, 15:01
I want your help.............................................. ................................

Jumper
- 4th May 2013, 15:27
Hi,

I suggest you start with:

Properly document the HW with schematics.
Make sure you can flash each LED in a simple program to make sure the PIC is running and that you can control each LED
And that you can read the sensor you have mentioned.


When that is done (which normally is the hardest part of a project) then you make a flow chart of what you want the software to do. Do you want to use delays or a real time clock with timers.

I am sure there are many people here that will help you correct the code but I doubt anyone will write your school project for free. Also I don't think it is a great idea if you get the code and HW setup here... and then even cant answer the most simple question when challenged by your teacher. Code is really a personal skill and if I were your teacher I would ask to make sure you know what you have done and not copied a already finished project from internet.

Oh.. by the way you might end up learning something that can be useful in the future..

so show us your best efforts and we will all help... ask for help when you get stuck and we will all help .. but dont ask us to do your homework

at least that is how I look at it

AvionicsMaster1
- 4th May 2013, 17:08
Ditto. I'm thinking we can point in the right direction but no one will write code unless they get a credit card number.

As for NS and EW, if you're traveling on a road and come to a light controlled intersection more than likely the oncoming traffic has the same color of lights displayed to them. You didn't say you had to control left turn lanes so I'm assuming you only have to control the major travel lanes. Only an insurance agent would want perpendicular paths to be the same. You also said you didn't have to build any circuitry so just recognizing that the N and S would be the same as well as E and W would be the same will save you some time in programming.

The whole rate thing for car measurement kinda throws me off. Usually you monitor how many cars are stacked up and adjust accordingly. If you did the car/minute you'd have to turn the sensors off during the stopped periods and turn them on at some point to measure traffic flow rates. You'd also have to take into account traffic legal speed during the sensed periods.

Jumper is correct in that you really need to get each LED blinking or at least turning on and off when you think they should. This ensures you can control them and that you've connected the PIC correctly.

Next step would be to post some code and/or schematic and you'll be overjoyed at the response. Though, as you're claiming to be an ME student, I'm surprised you haven't asked for a schematic.

Anyway, just my thoughts.

andywpg
- 4th May 2013, 21:21
Hi,

but dont ask us to do your homework

at least that is how I look at it

That was my first thought when I read the first post - I graduated already, I don't want to do someone ELSE'S homework!

BobK
- 7th May 2013, 02:28
Hi David,

It looks like you are way in over your head with this project. I really have to ask the question I haven't seen asked yet but what are you studying in school? Has your instructor run the class through any training on programming?

Anyway, I want to push you in the right direction. Goto http://www.ecrostech.com/General/TrafficLights/Steps.htm
and look at the little video of their demo board. ALSO READ THE INFORMATION ON THE MAIN PAGE. It will also tell you that you have along ways to go with your project. It points out some of the things the other members here have pointed out to you regarding trying to just light an LED with your chip. Even though the demo board was built around a different family of microcontrollers it is adaptable to the 16F877A chip you are wanting to use. And at a great cost. $15.00 for the demo board with parts less the micro.

After looking at the demo board working did you notice the North/South and East/West lights working? Kinda neat huh?

One of my first projects was building a traffic light from a PICBASIC book I bought on-line. It was great. I did a traffic control project for my home town back in 2001 and really got into the electronics of traffic lights. I found alot of things on-line. You need some time to explore.

Anyway, go to that site and spend some time looking through it. Put your thoughts together and try things in small steps and work your way up.

If it helps, Nuts and Volts magazine ran a series on learning to work with PICs that might help. They also put the articles together in book form.

I'm looking forward to watching your progress here. Now get to work!

BobK