This project was done at the university of the Algarve (ualg) as a part of the Microprocessors module on the Electrical and Electronic Engineering degree under the supervision of professor António Silva.
The Concept/FunctionalityThe concept of the project is to simulate (on a small scale) the control of two pairs of traffic lights applied to a crossroads with sensors to detect the presence of pedestrians that need to cross the road using the materials listed above.
- Inputs: 2 pingers that measure the proximity of the pedestrians (for the sake of the experiment we consider 10cm of proximity).
- Outputs: 6 leds, representing the red, green and yellow traffic lights for two sets of lights.
The code implements a finite state machine (FSM) for better functionality and simplicity.
(as each pair of traffic lights will always have the same lights on and as the pedestrians light sequence derives directly from the road traffic lights it is not necessary to represent every single light involved in a real crossroad).
The Planning and ThinkingBefore creating a project like this, the proper procedure is to first plan everything out, (like flowcharts and state diagrams). And then when starting to create the project to keep doing things step by step and testing everything before moving on to the next step.
The way we solved the problem was to start by creating the state diagrams and flowcharts and then the code for the lights without considering the pedestrian crossing and focusing only on the order of the lights for the cars. This was not very difficult as it just involved defining the light output states and defining times between each transition.
Afterwards when everything was working perfectly, we moved on to the pedestrian crossing. the solution we eventually came up with was to simply create a way to alter the times between each transition and maintain the same order of states of LEDs. this made for a functional and safe way for the traffic to remain efficient. So to do this we simply added an extra state for each rotation of lights where the time would be altered so that the green light would go out faster (these additional states only come in to action if a pedestrian is present).
The CodeThe C code uses a FSM method, and this project is a very good example of the advantages of an FSM and we recommend trying to recreate this project if you are interested in learning about making a finite state machine code.
The code also uses the millis() function instead of delays as this is a much more efficent way to implement delays.
Two ping functions are created which are very similar to those seen on the official arduino website at: https://www.arduino.cc/en/Tutorial/Ping but at the end of each function are a few more lines of code to use the distance calculated to mark the presence or non-presence of a pedestrian.
And then for the implementation of the FSM two more functions are created, one to define the outputs for each state and one to define which state is next and the conditions to change to the next state.
The code can be analyzed for a much better understanding, especially if you read the comments that describe all the steps.
The CircuitThis project can be re-created with the components listed above, but a more complex and life-like representation of the crossroads can be easily achieved using more LEDs in parallel to the existing ones (pedestrian lights and the lights on opposite sides of the same road can be connected to the already implemented LEDs).
Video - simulation of the project on breadboardAdvantages of using a Finite state Machine (FSM)- Simple and fast to make
- Easy to test
- Well developed techniques due to being relatively old
- Quite flexible, they can be applied to various things in various different ways
- Low processor overhead
- Easy to analyze when someone else reads it
Comments
Please log in or sign up to comment.