Introduction: The Mappifier - Mapping + Notification System

Night driving is quite a lot of fun. But often, it turns out to be a nightmare, in the form of animals crossing the road (especially those stray cats and dogs, who waits for you to drive near them so that they can cross!!). So I thought of making something that warns you when you get near these vulnerable locations, so that you can drive more carefully.

The system has two parts: Data Collection & Data Retrieval. The first part takes the location data, that is the locations at which there is a more probability of animal crossing. This data must be manually added and is updated on a map. The latter part takes our current location and then compare it with the collected data and appropriate notifications or warnings are provided.

Supplies

Hardware Used

ESP8266 WiFi development board

Ublox NEO-6M GPS Module

LEDs

Momentary Push Button

Software Used

Arduino IDE

Any JavaScript Editor

Firebase (for data storage and retrieval)

Step 1: The Hardware Unit

The hardware is required to work in two ways(modes):
1) Store the location to the Database: This is a major part in the data collection process; the location retrieved by the GPS module is sent to the firebase database through an ESP8266 WiFi development board.

2) Provide notifications during navigation: During navigation, the current location is retrieved and is sent to the database. Upon each update of the location, the distance between current location and those locations (which were stored during data collection process) is calculated and is recovered by the ESP8266 module which then warns the user according to how near user is from those stored locations.

I added three LEDs to notify the change in modes, as well as successful updation to database and a warning lamp to notify the closeness of user to the stored location.

The push button is used to store the location in just one click (in the store/data collection mode) and also to change between these modes.

Powering:

Initially, a 3.7V 300mAh Lipo battery was used, but it posed some problems. The major problem was ESP8266 resetting (might be due to the current spikes ). Also the battery did not last much. Finally a powerbank came to my rescue.

Step 2: Circuit

Step 3: About Firebase

Firebase is a mobile and web application development platform, owned by Google. It has many features, but here I am using only two of them, Realtime Database and Cloud Functions.

To get started on Firebase,

1.First go to the firebase webpage.

2.Now navigate to the console and click create a new project.

3.You need to provide a project name along with other details to create a project.

4.After the project is created click on the database option from the side pane to create a new database.

5.Do the same for the functions.

These are general steps for creating a project, firebase is well documented and there are many youtube video series for beginners, kindly go through for understanding more.

Step 4: Realtime Database

After you created the database, the next step is to see how data in database is stored and can be accessed. For writing or reading to/from database, you need to configure the database rules. For the development purpose, we can use an open rule so that anyone with the database reference can read/write but be careful while configuring the rules .The database stores the data in the JSON format and is synced to all devices that are connected to the database.You can add child nodes using the '+' sign but nodes can also be generated programmatically. All the data that we upload to the database in 'store' mode(storing location collected) gets stored here as separate nodes while data in 'notification' mode(retrieving data upon navigation) gets updated everytime(check the image).

Step 5: Setting Up Firebase Functions

We need something to calculate the closeness of current location to the stored locations, and the background database triggered functions would do our job. Functions are written in javascript and needs to be deployed onto the firebase.

You need to have node.js installed on your computer.

1) Now download the firebase command line interface using the command "npm install -g firebase-tools" on your command prompt

2)Now you need to login to firebase using the command "firebase login"( You need to give your gmail login password if you are not already logged in)

3)After this navigate to your project directory and initiate the function with the command "firebase init". You would need to select the 'functions' option for initiating firebase functions for your project.

4)Now you need to go to the 'functions' folder in your project directory and find the 'index.js' file.

5)Edit the file with a text editor and edit the file/replace the file with mappifier_function.txt.(This would effectively be our function)

6)Finally deploy your function using "firebase deploy" on command prompt.

You can check whether the function is deployed under the function menu on your firebase console

Step 6: Code

For ESP8266:

The board connects to the WiFi and Firebase using credentials and waits for a push button press. According to the duration of the button press, different modes are initiated. In the data collection mode(let's call this "store" mode), each button press will lead to the current position being sent to the database while in the data retrieval mode("notification mode"), the current location is sent to the database and distance is retrieved from database automatically. I added LEDs for warnings(closeness to marked location) and notification(like GPS fix, WiFi connection, successful database write, mode change,etc.).

For Firebase Function:

This function checks for a write to the 'current location' node on database and calculates the distance between the locations on database and current location and then finds the smallest distance which is then written to the 'distance' node on database.

Remember to add your wifi credentials and firebase auth credentials before you upload your program.(Please see the images). Also, if you are new to ESP8266 and to code them on Arduino IDE, refer these.

Step 7: Optional Step (Building an Enclosure)

In order to make the hardware part compact so that it can be mounted , I made a small enclosure to fit them inside. A couple of holes were made to mount the LEDs and to connect the USB cable. But the final enclosure was beyond my expectations!! It fitted inside my palm perfectly, and it was very easily mountable on cycle handle and on the steering wheel.

Step 8: In Action....

Here is a small video demonstrating both modes(store and notification) with warning and notification LEDs.

Step 9: Moving Further....

This system can be used for various purposes,for example, considering present scenario,if you can get the locations of disease spread and store it in a database, warnings will be provided by this system when you are closer to those locations. But I am seriously thinking of getting animal crossing data from all over the world to make drivers cautious and to save many animals from accidents. I have made a simple webpage(but not hosted yet) which has all the data that I collected. These are the data that I collected during walk or cycling( whenever I find a cat or dog on the roadside as they are more prone to cross) but we need much more data to implement this.

I am fairly new to making webpages(mainly javascript) and other stuffs and would love to have your suggestions and expertise :)

Maps Challenge

Participated in the
Maps Challenge