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

Pin Setup

  • pulse sensor
mbedpulse sensor
Vu+5 V
gndgnd
p15AO
  • Magjack ethernet module
mbedethernet adapter
TD+P1
TD-P2
RD+P7
RD-P8
  • MQ2 sensor
mbedMQ2
VuVcc
gndgnd
P16Ao
  • Bluetooth module
mbedAdafruit BLE
Vu+5V
gndgnd
ncRTS
gndCTS
p27 (Serial RX)TXO
p28 (Serial TX)RXI

Photos

Setup
setup
Email alert
email GUI
/media/uploads/aravi40/3.jpeg

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.