The traffic intersection model uses an Arduino to control a streetlight, traffic lights, pedestrian lights, and parking lot gate simultaneously. In the team of three, my role in the project was to design the circuitry, wire the breadboard, write the cooperative multitasking (similar to multithreading) functions in the code, and model the traffic light LED encasings for 3D printing. C++ was used to program the Arduino.
The project makes use of LEDs, photoresistors, servos, and buttons to simulate a T-shaped intersection. My goal in the project was to make a model that demonstrates attention to detail and my commitment to quality; I believe I achieved both goals with the success of this traffic intersection model.
Before creating the physical circuitry, I planned and simulated it using TinkerCAD's circuit modeling tool. Mapping the layout of the breadboard and digitally testing the code with the circuit helped streamline the design process. Potential issues, like incorrect wirings, were caught in advance, minimizing the probability of damaged components from short circuits or other causes.
I meticulously wired the breadboard afterwards, focusing on making it neat yet functional to make troubleshooting easier, given the number of connections. I used a drill to twist bundles of wire together. My careful approach proved instrumental in finishing the project, as the traffic light LEDs initially did not work as intended, and I had to troubleshoot the circuit and make adjustments to the wiring.
In a traffic intersection, the streetlights, pedestrian signals, traffic lights, and any other electrical components usually operate simultaneously; the traffic lights do not wait for a nearby parking lot gate to finish opening, and a streetlight does not wait for the pedestrian signal to finish counting down to zero. I implemented multithreading in the C++ code to ensure that every component could run concurrently.
To accomplish this, I used "cooperative multitasking," which is not true multithreading but does help interleave the program's functions in a way that can approximate multitasking in the Arduino's single-threaded environment. I check timestamps and avoid using delay() functions, and use state variables so each component remembers its past state independently.