Today I will talk about you how the Internet of Things can be used in the automotive sector, and I will show you how to monitor driving behavior using a smart and connected device.
Even if the future holds the promise of cars that can drive themselves, it will probably take some time until it becomes the main way of driving. Until then, careful driving is what keeps everyone safe on the roads. To promote good driving practices, a device could monitor excessive acceleration and breaking, and even report the captured data to the cloud for further analysis. This could even be interesting for the insurance sector, as insurance companies could offer better premiums to better (calmer) drivers. Let’s build a device that monitor driving behavior and send its data to the ThinkSpeak cloud, where a chart can be used for analysis.
In this video I will use the FONA board again, and for more information about it, please see my previous video called “Internet of Things in Travel – Baggage Tracking”. If you prefer to communicate using your smartphone, please see my video “Internet of Things – Wearable Sensors”, and if you have a 3G router in the car, see the video “Internet of Things in Transportation”. However, the important component here is the accelerometer module, which will sense movement in any of the three dimensions. To connect everything, you need a breadboard, and 9 jumper wires.
To setup the hardware, you start by disconnecting everything from its power source, and then connect the pins according to the tables and diagram here. The GSM module connects just like in my previous video, the accelerometer module connects VCC and GND as usual, and then the Arduino A0 to X, A1 to Y, and A2 to Z.
This is the Arduino code (Sketch) to check for acceleration (or deceleration, i.e. breaking) above a threshold, and report such occurrences over GPRS to the server…
SoftwareSerial SoftSerial(2, 3); // RX, TX
const int xPin = 0;
const int yPin = 1;
const int zPin = 2;
int xRead, yRead, zRead, xLast, yLast, zLast, acceleration;
xRead = analogRead(xPin);
yRead = analogRead(yPin);
zRead = analogRead(zPin);
acceleration = max(max(abs(xRead - xLast), abs(yRead - yLast)), abs(zRead - zLast));
if(xLast > 0 && acceleration > 20)
SoftSerial.println("AT+HTTPPARA=\"URL\",\"http://api.thingspeak.com/update?key=WRITEAPIKEY&field1=" + String(acceleration) + "\"");
xLast = xRead;
yLast = yRead;
zLast = zRead;
…and after the initial include of the software serial library (on line 1), a variable is created for it (on line 2). Constants for the accelerator pins are defined (on lines 4-6) followed by some variable declarations (on line 7). In the setup, the software serial communication is initiated (on line 11), then the APN for my operator is configured (on line 12), and the GPRS connection is opened (on line 14). The eternal loop starts by getting the values from the accelerometer (on lines 20-22), and check whether the acceleration in any dimension is greater than the threshold (on line 23). If it is, a HTTP connection is initiated (on line 26), the URL is set (on line 28), and the request is made (on line 30). The HTTP connection is terminated (on line 32), and then the previous values are saved (on lines 34-36).
You sign up for a ThingSpeak account (on https://thingspeak.com), and create a new channel, to get the API key for writing that you need to insert into the code. When you run the code on the device while it’s moving fast enough to pass the threshold, you will start seeing the values in the chart on the channel page, similar to this. Note that ThingSpeak is open source (https://github.com/iobridge/thingspeak), so you could also set it up on your own server.
That’s how the Internet of Things can be used in the automotive sector.