Software apps and online services
Hand tools and fabrication machines
Driving on smooth roads is something everyone enjoys and certainly provides for a much safer environment. Rough and jagged roads can be hazardous to those who drive on them, leading to the possibility of more accidents, and most significantly, more deaths.
The condition of roadways can vary greatly within both urban and rural cities, and therefore, devices that can aid in quickly identifying hazardous roadways can be extremely valuable to infrastructure engineers striving to increase the safety and quality of their cities. While this prototype device is not fully integrated with urban planners and construction companies, it represents a possible solution to solving one of the primary problems of cities across the world.
The goal of this project is to develop a prototype capable of aiding in the solving of one of the major problems in urban, suburban, and rural communities.Explanation
This IoT device consists of a Particle Argon, Inertial Measurement Unit (IMU), a GPS module, and an EEPROM module. When mounted to the user's car or truck, the device can detect spikes in the acceleration of the vehicle on the vertical axis; these peaks correspond with possibly hazardous bumps on the road as the user is driving. While sensing, the device will store the locations of hazardous road conditions in its EEPROM memory, which it can later read from and upload to a Google Firestore database. Because the Particle Argon is limited in its functionality of connecting with REST APIs, especially ones which require HTTPS over HTTP, the Argon will attempt to connect to its home Wi-Fi network where a computer will be running a Python script that accepts binary data from the Argon. The binary data consists of the device's identifier and all of the sensor readings the device has measured in the past trips that have not been uploaded yet.
The running of the Python script removes the operational overhead from the Argon, allowing for the fastest possible relaying of data to the central Firestore database.
While this prototype IoT device is simple, its capability to successfully and automatically identify hazardous road conditions could enable it to reduce the number of road-related crashes and deaths. Giving city maintenance engineers and construction companies access to the locations of hazardous roads has the capacity to save thousands of lives all around the worldAssembly
This section will be very simple!
1) Place all components on the breadboard and connect the pins with jumper wires according to the schematic below or at the bottom of the page.
2) Mount the breadboard and GPS module to a sufficiently sized enclosure with double-sided adhesive. (I used the cardboard box my Argon Kit was packaged in)
Yup, that's it! I told you this section was simple 😃Programming
1) Create a new project named "Road Quality Detector" and paste the provided code into the Particle Build IDE.
2) Add the necessary libraries to the project:
3) Change the value of PYTHON_SERVER to match the IP address of the machine running the Python script.
4) Power on the Particle Argon by plugging in a USB cable, or plugging in the LiPo battery.
5) After the device is connected to the Particle Cloud, click the Flash button in the upper-left corner of the screen. The RoadQualityDetector code will be flashed to your Particle Argon.
Note: Because the code sets the system mode to MANUAL, re-flashing the device requires you to enter safe mode. Refer to the Particle Documentation for entering safe mode: https://docs.particle.io/tutorials/device-os/led/argon/Firestore and Uploader Script
1) Open the Firebase console in your favorite web browser: https://console.firebase.google.com/, click "Add project", and give it a reasonable name.
2) Select your new project and click "Database" from the menu. Next, click "Create database" under the Cloud Firestore header.
3) Select "Start in test mode" to enable read and write access to the database. After pressing next, choose a nearby location to ensure the fastest connection speed possible.
Now that the Firestore database is setup, you'll need to get service credentials so the Python script can communicate with the database.
4) Head over to https://console.cloud.google.com/home/dashboard/ and make sure your newly-created project is selected next to "Google Cloud Platform" at the top of the screen. Navigate to "Credentials" in the "APIs & Services."
5) In "Create Credentials, " select "Service account key."
6) Select "firebase-adminsdk" as the service account, then press "Create." The credentials will be downloaded as a JSON file; this file will be necessary for the script to connect and authenticate with Google's Firestore servers.
7) Download the batcher.py script from the bottom of this project page and place it in an easily reachable folder. Also, move the downloaded credentials JSON file inside of this folder and rename it to "firebaseAdminCredentials.json."
8) Execute the following commands to install the required Python libraries. (Note: I wrote the Python script to use Python3 so you may need to use pip3 instead of pip depending on your system's Python installation)
pip install google-cloud-firestore firebase-admin
Congratulations! Firestore and the Python script are now setup to run!The Device in Action!
Once powered on, the device will detect high amplitude vibrations in whatever surface it is attached to and save them to its EEPROM chip.
Find a good spot in your car to mount the device; I chose a spot near my cupholders as a level spot and it worked great! Make sure your adhesive can stick to whatever surface you choose, and while the surface does not need to be completely level, angled surfaces will reduce the sensitivity of the device due to the Z-axis vector of the accelerometer not comprising of as much of the vertical axis of the car.
For my demonstration below, I do not have the device mounted to my car, but it works the same. The data in the graphs is, however, raw data from a road test with the device.
You may be wondering what data the device is actually measuring. The Particle Argon reads the Z axis acceleration value which aligns with an up/down vector. As the device operates, it keeps track of a rolling mean of the previous 1s of data (50 samples of each average over a 20ms period) and can compare its current Z-axis acceleration value with that moving average. When the amplitude of the difference between the current value and the current moving average is beyond a certain threshold (0.17G's), the detection code is triggered.
Based on the following graph, the rolling mean of acceleration data allows the device to smooth out the noisy accelerometer data.
The following graph shows the absolute value of the difference between the measured accelerometer value and the current value of the rolling mean. Whenever a sample rises above the threshold line of 0.17G's, the detector has detected a bump in the road.
While this threshold of 0.17G's may seem arbitrary, it is, in fact, not. In my initial test runs of this device, I had the Argon directly connected to a laptop which was saving the raw data the device measured. While driving, I mounted a button on the device that would mark what I believed to be a significant bump in the road. After a test drive of collecting data, I could later review the data and graph it based on Latitude and Longitude, drawing markers at where it detected bumps in the road. I could then modify the threshold to produce the fewest false-positives and the most true-positives. (Note: the threshold can easily be changed to be more or less sensitive by modifying the #define statement in the Argon's code)
This may seem like quite a few possibly hazardous locations, and that would be exactly correct. Based on these results, this device can successfully identify the locations of hazardous, uneven, and significantly rough roads, increasing public awareness of road conditions and enabling the faster repair of these dangerous roads.
After being powered on again, the device will attempt to communicate over Wi-Fi with the batcher.py Python script to upload its readings to the Firestore Database.
Taking a look at the Firestore database in the Firebase Console shows that the upload was successful!
The ease of access the Firestore database provides would enable a massive fleet of these devices to report the locations of hazardous roads all around the world automatically!
How's that for the power of IoT in solving real world problems!