PLC traffic Light

Steven Clark

Member
Join Date
Sep 2020
Location
Alberta
Posts
8
Hi all, I am having a problem programming a single traffic light, one red, one green, and one yellow light. I am not a student needing home work help, but an electrician wanting to learn PLCs. I recently bought a Schneider Electric M221 TM221C24R plc. I am using the new EcoStruxure Machine Expert Basic software. I have seen many online videos with timers being used with the DN EN and TT bits. But in the software I am using the timers only have one input and one output. Is there another way to program this. The online Schneider Electric Manual is useless. Thanks for the help
 
But in the software I am using the timers only have one input and one output.
That's not entirely true. While the timer instruction may have only a single boolean input and a single boolean output, it also requires a numeric preset value and it maintains an numeric accumulated value. It also has a numeric timebase that, depending on brand and model, may or may not be settable by the programmer. And if your brand and model doesn't directly support the TT boolean, that value is equal to EN And Not DN.
You could program the traffic light sequence as a series of cascading timer instructions. Alternatively you could use a single timer and comparison functions against the accumulated value to define the status of the individual lights.
 
Well, there's infinite way to program a process. I'm not familiar with the programming software but it seems they have Ladder as well. So, can you tell us how the timer instruction works with that PLC?

I would also say that traffic light is more complex than it seems and if you are just starting out that would be a bit overwhelming as you are battle multiple learning curve at once. Is there any particular reason you pick that PLC? Of course, if that's what's used a lot locally it would make sense, otherwise, I would recommend to start out with Allen Bradley. You can pick up a used micrologix for cheap.
 
Then timer has an
IN which is enable
Q which is timer output
3 types TON TOF TP
Time preset

It doesn't seem to have a TT timing bit or EN timing bit which the other traffic plc programs i looked at needed. The reason I picked square d is because my electrical wholesaler sells them. I have sent an email to them this morning, but I haven't got a response yet.
 
The equivalent of Timer_Instance.EN is when the logic controlling IN is true.
The equivalent of Timer_Instance.TT is when IN is true and Q is false.
The equivalent of Timer_Instance.DN is whatever tag you assign to the Q node of the timer.
 
Perhaps the best way is just use a TON timer for each stage although a bit lengthy it will give you a little more practice. there are a number of ways to sequence by using either internal bits or a word with values.
one example is to use a word as a sequencer then compare the word value to drive the outputs.
here is a simple two bank one but you will need to convert it into your plc particular language, as I said it could be reduced in size and it does control two sets of lights i.e. a crossroads, no doubt there will be loads of replies nah you can reduce this to x blocks ........ But you are learning and the more code and types of functions you use the better, also, being able to follow the logic rather than trying to decipher, loops, indirect addressing, pointers etc.
Also try other simple projects like a simple pick & place for example two cylinders (Up/Down, Back/Forward) a gripper, proximity switches for position, prox for part in pick nest & place nest, you could simulate this no need for real I/O just use internal bits and write the code that simulates it i.e. if a cylinder is driven forward then run a timer and set the forward proximity & reset the back proximity).
 
Last edited:
Just had a thought I have never used Schneider but for clarity, see attached simple ladder of the above FBD
 
Thanks for all the replies. I finally got the program to work. If anybody ever programs in EcoStruxure Machine Expert Basic, you would need to use 3 TON Timers, using the DN bits on timers. I had to use 3 internal relays to simulate the 3 EN bits on timer. If anybody wants a copy, I could try posting diagram
 
The traffic light example is a great one for teaching people about KISS (keep it simple, stupid). 3 timers works great for something with 3 states. Easy to follow and troubleshoot. but what if you had 30 states to represent, and maybe the transition from one state to another was not simply based on time? 30 timers becomes a lot of code, and easy to make mistakes with.

If you want to take this to the next level, try doing the same exercise using only one timer and an integer register to keep track of what state you're in. You can use a move or assign instruction (haven't used the Machine Expert software much) to adjust the timer Preset value depending on what state you're in. When the timer expires, add one to your state register.

It will be more code doing it this way if you only had 3 states, but less than if you had a lot.

Some PLCs have instructions built in for doing this kind of logic. They are often called sequencers or drum instructions.
 
Want to make it like real traffic lights, then the timing may need variables to alter the timing, for example times of day where one side may have longer green time than the other to ease traffic flow, also think about pedestrian crossings at lights, filters etc. A friend of mine used to program them, the hardware looked like half a cray 2 computer, sensors to monitor traffic flow and adjust the timings, possible communications to a control centre to allow timing adjustment etc.
 
Want to make it like real traffic lights, then the timing may need variables to alter the timing, for example times of day where one side may have longer green time than the other to ease traffic flow, also think about pedestrian crossings at lights, filters etc. A friend of mine used to program them, the hardware looked like half a cray 2 computer, sensors to monitor traffic flow and adjust the timings, possible communications to a control centre to allow timing adjustment etc.

I’ve heard most newer units no longer use PLCs and are proprietary microcontrollers.
 
In the UK they rarely use a PLC as such that's why I quoted half a cray 2 in my last post, however, there is no reason why they could not use a standard one, I believe that the hardware they use tends to be bespoke, my friend is no longer with us so cannot be sure of what was or is used today.
 

Similar Topics

Hey Folks I've done some browsing along the forum for some help in a matter. It would seem the question has been asked many times but it just...
Replies
41
Views
16,872
Hey guys am doin ME project based on PLC. The title is "Density based Traffic Light using PLC". Am using 3 sensors. Am having a little probs in...
Replies
4
Views
2,237
I am trying to simplify my program to not use the GEQ and LES functions. Can I substitute timers for this?
Replies
8
Views
5,094
Hi Experts, Any manual or steps on how to use the Wireshark app to determine the network traffic on our plant bus network?:confused: I'm having...
Replies
3
Views
2,526
Hello everyone... I am new to the PLC world and I would really love it if you gave me some interest about the problem I am dealing with for about...
Replies
15
Views
4,076
Back
Top Bottom