Skip to content

Page #3: Implementation Details

Alex edited this page Apr 15, 2024 · 16 revisions

3.1 Hardware Setup

The hardware setup steps are detailed below:

The goal is to mimic the Traffic light systems in the United Kingdom, and the components below were used in the final product:

  • Raspberry Pi B+ v1.2
  • 2 LEDs: red and green for the pedestrian traffic light system
  • 3 LEDs: red, yellow and green for the car traffic light system
  • 2 HC-SR04 ultrasonic sensors for motion detection and calibration for each traffic light system
  • push button to switch between states (i.e. permission to proceed for the pedestrians and stopping the vehicles)
  • buzzer and 3 small warning LEDs to trigger the alarm when conditions are not safe for pedestrian crossing
  • camera module v1.3 5MP for scanning the surroundings and feed data for accurate safety trigger detentions

However, to make this traffic system smart, throughout the operation of the traffic light system, the checking system ultrasonic sensors are employed to detect motion and a camera to identify the cars (to make sure that the motion detected is a car’s). The ultrasonic sensors are always on to check if a pedestrian is crossing the road, and if there is a car picked up by the ultrasonic sensor and the camera, the warning system made up of red LEDs and a buzzer to alarm the pedestrian visually and aurally are activated to avoid missing the alarms if the pedestrian is looking at his phone or has earbuds or headphones on. At the same time, the cars' traffic light system turns to the warning phase (yellow) and then the stopping phase (red).

Hence, the following components were added:

  • 2 ultrasonic sensors for detecting pedestrians and cars
  • buzzer for aurally warning the pedestrians
  • 3 small red LEDs for visually warning the pedestrians

The following steps are implemented to develop the hardware for this project.

Firstly, the pinouts used were based on the first generation of the Raspberry Pi model and the library used was obtained from the Raspberry Pi GPIO pinout guide. The table below provides the overview of pin-out legend:

image

Secondly, a schematic of the model was developed following the following steps:

  1. Installed KiCad
  2. Created a new schematic
  3. Imported Raspberry Pi symbol from the symbol library to the schematic
  4. Imported red and green LEDs from the symbol library for both traffic pole and pedestrian pole
  5. Imported yellow LED from the symbol library for traffic pole.
  6. LEDs need 330Ω resistors
  7. Imported the Ultrasonic sensor HC-SR04 component
  8. Imported additional two resistors with values 330 Ω and 470 Ω resistances for the connection to the echo pin in the HC-SR04
  9. Imported the buzzer to the schematic
  10. Imported a push button switch for the pedestrian pole
  11. Imported a resistor with a value of 270 Ω for the switch
  12. Connected the components to the Raspberry Pi and the connections were as follows:

image

However, since the symbol of the Raspberry Pi model and the library used was not available on KiCad, the incorrect GPIO pins were used just to demonstrate the idea and avoid complicated connections in the schematic.

Lastly, the pins used for the physical implementation are listed in the table below: image

3.2 Software Development

In developing the CrossGuard traffic light management system, we employed an Agile methodology to maintain flexibility and adaptability in our workflow. Our tasks and sprints were managed using a Kanban board, which can be accessed here.

The software development process was initiated with a cmake_minimum_required version of 3.10 to ensure compatibility and ease of setup across development environments. The project, named CrossGuard, is structured with modern C++17 standards to leverage the latest language features for improved performance and reliability.

The development of the CrossGuard traffic light system leveraged a variety of libraries to ensure robust operation and facilitate a range of functionalities.

Key Libraries and Tools Used:

  • C++ Standard Library: Utilizing C++17 for its modern features and improvements, enabling more efficient and safer code.
  • CPR (C++ Requests): A modern C++ library for making HTTP/REST requests, which was included via CMake's FetchContent. It allows seamless communication over the network, vital for remote monitoring and control aspects of the system.
  • pigpio: This library is critical for interfacing with the GPIO pins on the Raspberry Pi, enabling the system to interact with hardware components such as sensors and actuators.

During development, to accommodate and simulate the hardware interaction in non-Raspberry Pi environments, we implemented stub files. These stubs mimic the behavior of the Raspberry Pi's hardware interfaces, allowing developers to write and test their code on different platforms without needing actual Raspberry Pi hardware.

One of the pivotal features of CrossGuard is its integration with Firebase and Firestore for real-time data management and logging. While the specific library used for Firebase communication is not detailed in the provided CMakeLists.txt, typically, a Firebase C++ SDK or a REST API wrapper is utilized for such tasks. This allows CrossGuard to send and receive real-time updates from the Firestore database, which is instrumental in monitoring traffic flow, logging system activities, and potentially receiving configuration updates or other commands remotely.

By employing these libraries, CrossGuard ensures a high level of functionality and adaptability, necessary for modern traffic management systems.

Clone this wiki locally