VitalSense: alcohol and heart rate monitor with GPS for automobiles
Project by
Adarsh Ravi and Roshan Vidyavasthu
Overview
- A major cause of road accidents is due to Driving under Influence (DUI) and emergency medical conditions on the road causing drivers to lose control of the vehicle. The former can easily be detected using an alcohol sensor and the latter can be estimated by measuring the heart rate.
- This project is a low cost mbed based system which is intended to be installed in vehicles to measure breath alcohol level and the heart rate of the driver using a non-intrusive sensor; when either of the measured signals go beyond a certain limit, the system will send an automated email and text messages (SMS) to predefined destinations with the GPS data of the vehicle to help locate the driver swiftly.
- The heart rate is measured continuously at fixed intervals, the GPS data can be obtained either by a dedicated GPS module or using your smart phone (via bluetooth). Additionally, all data is stored in a SD card.
Components Used
- Pulse sensor : The pulse sensor https://pulsesensor.com/ is a non-intrusive photoplethysmograph, which produces an analog fluctuation in voltage, and it has a predictable wave shape. The sensor can be placed on the finger or the tip of a ear to measure heart rate effectively. The library for mbed can be found here https://developer.mbed.org/users/donalm/code/PulseSensor/.
- MQ-2 Gas sensor : The MQ2 sensor is a low cost gas sensor which is sensitive to a range of combustible gases like LPG, alcohol and propane. The sensor outputs a digital and an analog value that can be used to estimate the PPM (parts per million) of the gas. Useful resources for the sensor are http://wiki.seeed.cc/Grove-Gas_Sensor-MQ2/ and http://www.instructables.com/id/How-to-use-MQ2-Gas-Sensor-Arduino-Tutorial/.
- GPS : The GPS data can be obtained from a dedicated module like the GlobalSat EM 406 GPS Module (https://developer.mbed.org/cookbook/GlobalSat-EM-406-GPS-Module) or using a bluetooth module connected to your smart phone. An Adafruit Bluefruit BLE UART friend module is handy and a cheaper alternative - https://developer.mbed.org/users/4180_1/notebook/adafruit-bluefruit-le-uart-friend---bluetooth-low-/.
- Ethernet module : A small Ethernet breakout module from Sparkfun can be used to connect the mbed to the network via ethernet. https://developer.mbed.org/handbook/Ethernet provides the library and additional information. The SMTP library (https://developer.mbed.org/cookbook/SMTPClient) can be used to send mails and texts using the mbed.
Pin Setup
- pulse sensor
| mbed | pulse sensor |
|---|---|
| Vu | +5 V |
| gnd | gnd |
| p15 | AO |
- Magjack ethernet module
| mbed | ethernet adapter |
|---|---|
| TD+ | P1 |
| TD- | P2 |
| RD+ | P7 |
| RD- | P8 |
- MQ2 sensor
| mbed | MQ2 |
|---|---|
| Vu | Vcc |
| gnd | gnd |
| P16 | Ao |
- Bluetooth module
| mbed | Adafruit BLE |
|---|---|
| Vu | +5V |
| gnd | gnd |
| nc | RTS |
| gnd | CTS |
| p27 (Serial RX) | TXO |
| p28 (Serial TX) | RXI |
Photos
Setup
Email alert
GUI
GUI
A GUI was developed to output the map once the GPS data is input. The code can be found at - https://drive.google.com/open?id=0Bx7cKiV68hOMQll0RmYzVWZqNG8.
Code
/*___________________________________________________________________________________________________________________
Title : Heart rate and alcohol level monitoring in Auto mobiles
Author: Adarsh Ravi & Roshan V N Vidyavasthu
*/
#include "mbed.h"
#include "EthernetNetIf.h"
#include "NTPClient.h"
#include "SMTPClient.h"
#include "PulseSensor.h"
#define HOSTNAME "mbedSE"
// Variables for SMTP Client
#define DOMAIN "smtp2go.com"
#define SERVER "mail.smtp2go.com"
#define PORT 2525
#define USER "sudrec2020@gmail.com"
#define PASSWORD "nw9GDueV5y4M"
#define FROM_ADDRESS "sudrec2020@gmail.com"
#define TO_ADDRESS "ece4180.goomail@gmail.com"
// Global functions declaration
void sendDataToProcessing(char symbol, int data); // Heart rate monitor function
// Union for getting GPS location from Adafruit Bluetooth module
union f_or_char {
float f;
char c[4];
};
// Global variables
union f_or_char x,y,z;
PulseSensor sensor(p20, sendDataToProcessing,1000);
AnalogIn alco(p18);
EthernetNetIf eth(HOSTNAME);
Serial bluemod(p13,p14);
DigitalOut led1(LED1, "led1");
bool b;
char bchecksum=0;
char temp=0;
// Heart rate monitor reading and processing function definition
void sendDataToProcessing(char symbol, int data){
printf("symbol : %c BPM: %d \r\n", symbol, data);
if(symbol == 'B'){ // Symbol 'B' implies that finger is placed on the sensor and is reading the correct values
if(data<30 || data >100) // Symbol 'S' signifies no finger is placed
b = true;
else
b = false;
wait(2.0);
}
sensor.stop();
}
// Bluetooth GPS function definition
void bluetooth(){
if (bluemod.getc()=='!') {
if (bluemod.getc()=='L') {
for (int i=0; i<4; i++) {
temp = bluemod.getc();
x.c[i] = temp;
bchecksum = bchecksum + temp;
}
for (int i=0; i<4; i++) {
temp = bluemod.getc();
y.c[i] = temp;
bchecksum = bchecksum + temp;
}
for (int i=0; i<4; i++) {
temp = bluemod.getc();
z.c[i] = temp;
bchecksum = bchecksum + temp;
}
if (bluemod.getc()==char(~('!' + 'L' + bchecksum))) {
printf("Latitude = %f Longitude = %f Altitude = %f\n\r",x.f, y.f, z.f);
}
}
}
}
int main() {
printf("Heart rate and alcohol level monitoring in Auto mobiles \n");
// Connecting to Ethernet
EthernetErr ethErr;
int count = 0;
do {
printf("Setting up %d...\n", ++count);
ethErr = eth.setup();
if (ethErr) printf("Timeout\n", ethErr);
} while (ethErr != ETH_OK);
printf("Connected OK\n");
const char* hwAddr = eth.getHwAddr();
printf("HW address : %02x:%02x:%02x:%02x:%02x:%02x\n", hwAddr[0], hwAddr[1], hwAddr[2],hwAddr[3], hwAddr[4], hwAddr[5]);
IpAddr ethIp = eth.getIp();
printf("IP address : %d.%d.%d.%d\n", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
// Initialising NTP and SMTP clients
NTPClient ntp;
printf("NTP setTime...\n");
Host server(IpAddr(), 123, "pool.ntp.org");
printf("Result : %d\n", ntp.setTime(server));
time_t ctTime = time(NULL);
printf("\nTime is now (UTC): %d %s\n", ctTime, ctime(&ctTime));
Host host(IpAddr(), PORT, SERVER);
SMTPClient smtp(host, DOMAIN, USER, PASSWORD, SMTP_AUTH_PLAIN);
// Continuously check for heart rate and alcohol level
while(1){
sensor.start();
bool a = alco;
// If either of the sensors not in range get the current GPS location and send text message and e-mail
if(a|b){
bluetooth();
EmailMessage msg;
// Sending e-mail
msg.setFrom(FROM_ADDRESS);
msg.addTo(TO_ADDRESS);
msg.printf("HELP ...! HELP ...! HELP ...!.\r\n ");
msg.printf("I'm in trouble, please find me in the below location.\r\n");
msg.printf("Latitude = %f Longitude = %f\r\n",x.f, y.f);
msg.printf("http://www.google.com/maps/place/%f,%f",x.f, y.f);
msg.printf(".\r\n");
msg.printf("\n");
printf("Send result %d\n", smtp.send(&msg));
printf("Last response | %s", smtp.getLastResponse().c_str());
// Sending text message
msg.setFrom(FROM_ADDRESS);
msg.addTo("4049802603@tmomail.net");
msg.printf("HELP ...! HELP ...! HELP ...!\r\n ");
msg.printf("I'm in trouble, please find me in the below location.\r\n");
msg.printf("Latitude = %f Longitude = %f\r\n",x.f, y.f);
msg.printf("http://www.google.com/maps/place/%f,%f",x.f, y.f);
msg.printf(".\r\n");
msg.printf("\n");
printf("Send result %d\n", smtp.send(&msg));
printf("Last response | %s", smtp.getLastResponse().c_str());
}
}
}
Please log in to post comments.
