Longer Life For Drivers

This project helps to detect motorcycle accidents and monitor the driver and vehicle involved in it, in order to save many lives.

IntermediateFull instructions provided1,555

Things used in this project

Hardware components

LinkIt ONE
MediaTek Labs LinkIt ONE
×1
NXP Pressure Sensor
×2
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
e-Health Shield
×1
Pulse and Oxygen in blood Sensor
×1
SparkFun Vibration Sensor
×2
SparkFun Flex Sensor
×2

Software apps and online services

Arduino IDE
Arduino IDE
Ubidots
Ubidots

Story

Read more

Schematics

Flex sensors connection to Linkit One

The design is made with Arduino because there is no Linkit One model in Fritzing
F1

Code

Analog input from vest V1.0

Arduino
Regular use of the vest on arduino and link it one
//analog inputs
int sensorPin = A0; 
int sensorPin1 = A1;

//inicialize the measure
int sensorValue= 0; 
int sensorValue1= 0; 

void setup() {
  //inicialize the serial monitor
  Serial.begin(9600);
}

void loop() {
  //Read the value equivalent to the voltage from the sensors  
  sensorValue = analogRead(sensorPin);
  sensorValue1 = analogRead(sensorPin1);

  //equations for force in Newtons
  float forceback=((1.772*sensorValue)-536.6);
  float forcechest=((0.4118*sensorValue1)-24.3);
  
  //erase wrong data
  if(forceback<0){forceback=0;}
  if(forcechest<0){forcechest=0;}
  
  //prints the force and the mass in rest
  Serial.print("back: ");
  Serial.print(forceback);
  Serial.println(" Newtons");
  Serial.print(forceback/8);
  Serial.println(" Kg");
  Serial.print("torax: ");
  Serial.print(forcechest);
  Serial.println(" Newtons");
  Serial.print(forcechest/8);
  Serial.println(" Kg");
  Serial.println("");
  delay(100);
}

Analog input from vest V1.1 (Sending to Ubidots)

Arduino
Used in LinkIt One to send the vest's data to Ubidots
#include <LWiFi.h>
#include <LWiFiClient.h>

#define WIFI_AP "" //name
#define WIFI_PASSWORD "" //password

#define WIFI_AUTH LWIFI_WPA  // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP.

// Ubidots information
#define URL        "things.ubidots.com"
#define TOKEN      "ZhmOE6cKoBzsyAYHJ6Ujz37WZ3HleGPovTOu8bjLLeMLscHeAqNmHuNDsXzK" //can be found at profile         
#define S_BACK   "560880387625421327f293e4"  //Variable ID              
#define S_CHEST  "5658893d7625427789802a97"  //Variable ID

//analog inputs
int sensorBack = A0;
int sensorChest = A1;

//force variables
int BackValue, ChestValue = 0;
int presb,presc = 0;

void setup()
{
  //initialize wifi and serial monitor
  LWiFi.begin();
  Serial.begin(9600);

  // get wifi communication
  Serial.println("Connecting to AP");
  while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    delay(1000);
  }
}

void loop()
{ 
  //read the sensors value
  BackValue = analogRead(sensorBack);
  ChestValue = analogRead(sensorChest);
  
  //print before send
  Serial.println(BackValue);
  Serial.println(ChestValue);
  delay(100);
  
  //converts the voltage to a force value
  presb=((1.772*BackValue)-144.59);
  presc=((0.4118*ChestValue)-14.476);
  
  //send the two values to Ubidots
  upload(String(presb), S_BACK);
  upload(String(presc), S_CHEST);
}

//Function that do the request
void upload(String value, String VARIABLEID){
 
  Serial.println("Sending value to Ubidots...");
  LWiFiClient c;
  while (!c.connect(URL, 80))
  {
    Serial.println("Retrying to connect...");
    delay(100);
  }

  String data = "{\"value\":"+ value + "}";
  String thisLength = String(data.length());
  
  // Build HTTP POST request
  c.print("POST /api/v1.6/variables/");
  c.print(VARIABLEID);
  c.print("/values?token=");
  c.print(TOKEN);
  c.println(" HTTP/1.1");
  c.println("Content-Type: application/json");
  c.println("Content-Length: " + thisLength);
  c.print("Host: ");
  c.println(URL);
  c.print("\n" + data);
  c.print(char(26));

  while (c){
    Serial.print((char)c.read());
  } 
  c.stop();
}

Vibration with delta

C/C++
This is the code used to measured the changes between last vibrations and new vibrations on the helmet
//Programmers: Ciro Gamboa - Alix Angarita - Nelson Monroy
//test of vibration sensors with delta technique
const int frontSensor=A1;
const int backSensor=A2;
int frontValue=0,backValue=0;
//delta's assingment
int deltaFront,deltaBack;

//Inputs and outputs
void setup() { 
  pinMode(frontSensor, INPUT);  
  pinMode(backSensor, INPUT);
  
  Serial.begin(9600);
  }

void loop() {
  
  deltaFront=frontValue;
  deltaBack=backValue;
  
  frontValue = analogRead(frontSensor); 
  backValue = analogRead(backSensor); 
  
  deltaFront=deltaFront-frontValue;
  deltaBack=deltaBack-backValue;
  
   Serial.print("Front=");
   Serial.print(abs(deltaFront));
   Serial.print("\tBack=");
   Serial.println(abs(deltaBack));
   
  
   delay(100);
   
}

Vibration with delta and filters

C/C++
Here, a filter of 150 units is applied, in order to avoid motorcycle's natural vibrations caught by the sensors.
//Programmers: Ciro Gamboa - Alix Angarita - Nelson Monroy
//test of vibration sensors with delta technique and filters
const int frontSensor=A1;
const int backSensor=A2;
int frontValue=0,backValue=0;
//delta's assingment
int deltaFront,deltaBack;

//Inputs and outputs
void setup() { 
  pinMode(frontSensor, INPUT);  
  pinMode(backSensor, INPUT);
  
  Serial.begin(9600);
  }

void loop() {
  
  deltaFront=frontValue;
  deltaBack=backValue;
  
  frontValue = analogRead(frontSensor); 
  backValue = analogRead(backSensor); 
  
  deltaFront=abs(deltaFront-frontValue);
  deltaBack=abs(deltaBack-backValue);
  
  if(deltaFront>=150)//if greater, means that it was serious
  {
    Serial.print("IMPACT OF ");
    Serial.print(deltaFront);
    Serial.println(" ON THE FRONT!!");
  }
  
   if(deltaBack>=150)//if greater, means that it was serious
  {
    Serial.print("IMPACT OF ");
    Serial.print(deltaBack);
    Serial.println(" ON THE BACK!!");
  }
   
  
   delay(100);
   
}

Motorcycle deflexion

C/C++
Here it's the code that detects if the bike went to the ground, and which side touched the ground
//Programmers: Ciro Gamboa - Alix Angarita - Nelson Monroy
//test of deflexion sensors with delta technique and filters

const int rightSide = A1;//right side of the motorbike
const int leftSide = A2; //left side of the motorbike
int rightValue=0,lefValue=0;//getters
int deltaRight,deltaLeft;

//Pins..
void setup() { 
  pinMode(rightSide, INPUT);  
  pinMode(leftSide, INPUT);
  
  Serial.begin(9600);
  }

void loop() {
  
  deltaRight=rightValue;
  deltaRLeft=leftValue;
  
   rightValue = analogRead(rightSide); 
   leftValue = analogRead(leftSide);
  
  deltaRight = abs(deltaRight - rightValue);
  deltaleft = abs(deltaLeft - leftValue);
   
  if(deltaRight>5)//it flexed!!
  {
    Serial.println("THE MOTORBIKE TOUCH THE GROUND ON ITS RIGHT SIDE!!");
  }
  
  if(deltaLeft>5)//it flexed!!
  {
    Serial.println("THE MOTORBIKE TOUCH THE GROUND ON ITS LEFT SIDE!!");
  }
    delay(100);
}

Use of pulse-oximeter

C/C++
This is an example code which contains the libraries needed in order to use the pulse-oximeter properly
#include <PinChangeInt.h>//library for setting the pulse-oximeters interruption 
#include <eHealth.h>// shield's library
int cont = 0;
void setup() {
  Serial.begin(115200);
  eHealth.initPulsioximeter();///initializes the sensor 
  PCintPort::attachInterrupt(6, readPulsioximeter, RISING);// setting the interruption
}
void loop() {
  Serial.print("PRbpm : "); 
  Serial.print(eHealth.getBPM());//the heart rate is obtained
  Serial.print("    %SPo2 : ");
  Serial.print(eHealth.getOxygenSaturation());//the oxygen's saturation   is obtained
  Serial.print("\n");
  Serial.println("=============================");
  delay(500);
}
//=========================================================================
void readPulsioximeter(){
  cont ++;
  if (cont == 50) { //Get only of one 50 measures to reduce the latency
    eHealth.readPulsioximeter();
    cont = 0;
  }
}

Pulse-oximeter, GPS,Flex, Ubidots

C/C++
Here is the main code of the obtainment of geo localization, diagnostic parameters and more!
/*
  Wifi-GPS_Flex
  Nelson Monroy
  Ciro Gamboa
  Alix Angarita
 */
//Library inclusion
#include <LWiFi.h>
#include <LWiFiClient.h>
#include <LTask.h>
#include <LGPS.h>
#include<HardwareSerial.h>///librerias para la comunicación con el arduino
#include<UARTClass.h>///librerias para la comunicación con el arduino

//Wifi Network settings
#define WIFI_AP "network_name" //NETWORK NAME
#define WIFI_PASSWORD "network_password"//NETWORK PASSWORD
#define WIFI_AUTH LWIFI_WPA/// -> LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP.

//////Variables
char action[] = "POST ";
char server[]="things.ubidots.com";//ADDRESS IN UBIDOTS WHERE I UPLOAD DATA
char path[]= "/api/v1.6/variables/XXXXXXXXXXXXXX/values";///  XXXXXX INCLUDE VARIABLE SOURCE KEY
char path2[]= "/api/v1.6/variables/XXXXXXXXXXXXXX/values";/// 
char path3[]= "/api/v1.6/variables/XXXXXXXXXXXXXX/values";/// HELMET
char path4[]= "/api/v1.6/variables/XXXXXXXXXXXXXX/values";/// BIKE
char path5[]= "/api/v1.6/variables/XXXXXXXXXXXXXX/values";/// VEST
char token[]="E6RqUj6gnQ9b9oyeGaKLuvu5At0peb"; /// THE APIKEY .
int port =80,BPM,SPO2,dato; //PORT OF CONNECTION TO THE SERVER
int FH,BH,BF,CF;

int num;
uint32_t sensorBikeRight =A2;
uint32_t sensorBikeLeft =A1;
int sensorValueBikeRight= 0;  
int sensorValueBikeRight=0;
String le, thisLength;
String var;
String var2,var3,var4;
unsigned long ReportingInterval = 100;// TIME TO ACTUALIZE SAMPLING
String Location="";// THE LOCATION STRING IS SAVED


///////////////////////////// INSTANCIATION
LWiFiClient globalClient;
gpsSentenceInfoStruct info;

/////////////////////////////////
void setup() {
 ///////////////////////////////
 Serial.begin(19200);
 Serial1.begin(19200);
 
 LWiFi.begin();
 LTask.begin();
 LGPS.powerOn();
 
 /////////////////////////////// 
 Serial.println();
 Serial.print("Connecting to server");
 if(LWiFi.connectWPA(WIFI_AP,WIFI_PASSWORD)<0)
    {
      Serial.println("FAIL!");
      return;
    }
    Serial.println("OK");
  LWiFiClient client;
 globalClient=client;
 }
void loop() {
  ////obtencion del dato de moto 
  int deltamotoderecho=sensorValuemotoderecha;
  sensorValuemotoderecha=analogRead(sensormotoderecho);
  deltamotoderecho=abs(deltamotoderecho-sensorValuemotoderecha);
  
  int deltamotoizquierdo=sensorValuemotoizquierda;
  sensorValuemotoizquierda=analogRead(sensormotoizquierdo);
   deltamotoizquierdo=abs(deltamotoizquierdo-sensorValuemotoizquierda);
  
  if (globalClient.available()) {// if there are incoming bytes available from the server
    char c = globalClient.read();   // read them and print them:
    Serial.print(c);
  }
  pulsioximetria();
  String value1 = String (BPM);
  String value2 = String (SPO2);
  String value3= String(deltaBikeRight);
  String value4= String(deltaBikeLeft);

  LGPS.getData(&info);
  if (ParseLocation((const char*)info.GPGGA)) {  // This is where we break out needed location information
      Serial.print("Location is: ");
      Serial.println(Location);                 // This is the format needed by Ubidots
    }
   if (Location.length()==0) {
      var2="{\"value\":"+ value2 + "}";
      var3="{\"value\":"+ value3 + "}";
      var4="{\"value\":"+ value4 + "}";   
    }
    else {
      var="{\"value\":"+ value1 + ", \"context\":"+ Location + "}";  // with GPS info
      var2="{\"value\":"+ value2 + "}"; 
      var3="{\"value\":"+ value3 + "}";     
      var4="{\"value\":"+ value4 + "}";
    }
  num=var.length();               // How long is the payload
  le=String(num);
  thisLength = String(var2.length());
  Serial.print("Connect to ");    // For the console - show you are connecting
    Serial.println(server);
    if (globalClient.connect(server, port)){  // if you get a connection, report back via serial:
      Serial.println("connected");  // Console monitoring
      Serial.print(action);                   // These commands build a JSON request for Ubidots but fairly standard
      Serial.print(path);                     // specs for this command here: http://ubidots.com/docs/api/index.html
      Serial.println(" HTTP/1.1");
      Serial.println(("Content-Type: application/json"));
      Serial.print(("Content-Length: "));
      Serial.println(le);
      Serial.print(("X-Auth-Token: "));
      Serial.println(token);
      Serial.print(("Host: "));
      Serial.println(server);
      Serial.println();
      Serial.println(var);  // The payload defined above
      Serial.println();
      ////envio de datos de gps
      Serial.println((char)26); //This terminates the JSON SEND with a carriage return
      globalClient.print(action);                   // These commands build a JSON request for Ubidots but fairly standard
      globalClient.print(path);                     // specs for this command here: http://ubidots.com/docs/api/index.html
      globalClient.println(" HTTP/1.1");
      globalClient.println(("Content-Type: application/json"));
      globalClient.print(("Content-Length: "));
      globalClient.println(le);
      globalClient.print(("X-Auth-Token: "));
      globalClient.println(token);
      globalClient.print(("Host: "));
      globalClient.println(server);
      globalClient.println();
      globalClient.println(var);  // The payload defined above
      globalClient.println();
      globalClient.println((char)26); //This terminates the JSON SEND with a carriage return
    }
    //envio datos spo
    if (globalClient.connect(server, port)){      
      Serial.println("SPO:"+ var2);
      Serial.print(action);                   // These commands build a JSON request for Ubidots but fairly standard
      Serial.print(path2);                     // specs for this command here: http://ubidots.com/docs/api/index.html
      Serial.println(" HTTP/1.1");
      Serial.println(("Content-Type: application/json"));
      Serial.print(("Content-Length: "));
      Serial.println(thisLength);
      Serial.print(("X-Auth-Token: "));
      Serial.println(token);
      Serial.print(("Host: "));
      Serial.println(server);
      Serial.println();
      Serial.println(var);  // The payload defined above
      Serial.println();
      globalClient.print(action);                   // These commands build a JSON request for Ubidots but fairly standard
      globalClient.print(path2);                     // specs for this command here: http://ubidots.com/docs/api/index.html
      globalClient.println(" HTTP/1.1");
      globalClient.println(("Content-Type: application/json"));
      globalClient.print(("Content-Length: "));
      globalClient.println(thisLength);
      globalClient.print(("X-Auth-Token: "));
      globalClient.println(token);
      globalClient.print(("Host: "));
      globalClient.println(server);
      globalClient.println();
      globalClient.println(var2);  // The payload defined above
      globalClient.println();
      globalClient.println((char)26);
    }
    //envio datos moto
    if (globalClient.connect(server, port)){      
      Serial.println("SHOCK ON THE RIGHT:"+ var3);
      Serial.print(action);                   // These commands build a JSON request for Ubidots but fairly standard
      Serial.print(path3);                     // specs for this command here: http://ubidots.com/docs/api/index.html
      Serial.println(" HTTP/1.1");
      Serial.println(("Content-Type: application/json"));
      Serial.print(("Content-Length: "));
      Serial.println(thisLength);
      Serial.print(("X-Auth-Token: "));
      Serial.println(token);
      Serial.print(("Host: "));
      Serial.println(server);
      Serial.println();
      Serial.println(var3);  // The payload defined above
      Serial.println();
      globalClient.print(action);                   // These commands build a JSON request for Ubidots but fairly standard
      globalClient.print(path3);                     // specs for this command here: http://ubidots.com/docs/api/index.html
      globalClient.println(" HTTP/1.1");
      globalClient.println(("Content-Type: application/json"));
      globalClient.print(("Content-Length: "));
      globalClient.println(thisLength);
      globalClient.print(("X-Auth-Token: "));
      globalClient.println(token);
      globalClient.print(("Host: "));
      globalClient.println(server);
      globalClient.println();
      globalClient.println(var3);  // The payload defined above
      globalClient.println();
      globalClient.println((char)26);
    }
    //envio datos moto
    if (globalClient.connect(server, port)){      
      Serial.println("SHOCK ON THE LEFT:"+ var4);
      Serial.print(action);                   // These commands build a JSON request for Ubidots but fairly standard
      Serial.print(path4);                     // specs for this command here: http://ubidots.com/docs/api/index.html
      Serial.println(" HTTP/1.1");
      Serial.println(("Content-Type: application/json"));
      Serial.print(("Content-Length: "));
      Serial.println(thisLength);
      Serial.print(("X-Auth-Token: "));
      Serial.println(token);
      Serial.print(("Host: "));
      Serial.println(server);
      Serial.println();
      Serial.println(var4);  // The payload defined above
      Serial.println();
      globalClient.print(action);                   // These commands build a JSON request for Ubidots but fairly standard
      globalClient.print(path4);                     // specs for this command here: http://ubidots.com/docs/api/index.html
      globalClient.println(" HTTP/1.1");
      globalClient.println(("Content-Type: application/json"));
      globalClient.print(("Content-Length: "));
      globalClient.println(thisLength);
      globalClient.print(("X-Auth-Token: "));
      globalClient.println(token);
      globalClient.print(("Host: "));
      globalClient.println(server);
      globalClient.println();
      globalClient.println(var4);  // The payload defined above
      globalClient.println();
      globalClient.println((char)26);
    }
}

GPS settings

C/C++
This is the code of the format that help us to transform the information we receive in an specific point in a map!
boolean ParseLocation(const char* GPGGAstr)
// Refer to http://www.gpsinformation.org/dale/nmea.htm#GGA
// Sample data: $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
{
  char latarray[6];
  char longarray[6];
  int index = 0;
  Serial.println(GPGGAstr);
  Serial.print("Fix Quality: ");
  Serial.println(GPGGAstr[43]);
  if (GPGGAstr[43]=='0') {        //  This is the place in the sentence that shows Fix Quality 0 means no fix
    Serial.println("No GPS Fix");
    Location = "";           // No fix then no Location string
    return 0;
  }
  String GPSstring = String(GPGGAstr);
  for (int i=20; i<=26; i++) {         // We have to jump through some hoops here
    latarray[index] = GPGGAstr[i];     // we need to pick out the minutes from the char array
    index++;
  }
  float latdms = atof(latarray);        // and convert them to a float
  float lattitude = latdms/60;          // and convert that to decimal degrees
  String lattstring = String(lattitude,10);// Then put back into a string
  Location = "{\"lat\":";
  if(GPGGAstr[28] == 'S') Location = Location + "-";
  Location += GPSstring.substring(19,20) + "." + lattstring.substring(2,12);
  index = 0;
  for (int i=33; i<=38; i++) {         // And do the same thing for longitude
    longarray[index] = GPGGAstr[i];     // the good news is that the GPS data is fixed column
    index++;
  }
  float longdms = atof(longarray);        // and convert them to a float
  float longitude = longdms/60;          // and convert that to decimal degrees
  String longstring = String(longitude,8);// Then put back into a string
  Location += " ,\"lng\":";
  if(GPGGAstr[41] == 'W') Location = Location + "-";
  if(GPGGAstr[30] == '0') {
    Location = Location + GPSstring.substring(31,33) + "." + longstring.substring(2,12) + "}";
  }
  else {
    Location = Location + GPSstring.substring(30,33) + "." + longstring.substring(2,12) + "}";
  }
  return 1;
}

The little big function

C/C++
This is a small function that has the big responsibility of bringing the heart rate and the oxygen saturation...
//Programmers: Nelson Monroy-Alix Angarita-Ciro Gamboa
void pulsioximetria()
{
  if(Serial1.available())
  {
  dato=Serial1.read();
  }
  switch(dato)
  {
    case 1:
    Serial.println("Beats per minute:");
    Serial.println(BPM);
    BPM=Serial1.read();//I get the heart rate
    dato=0;
    break;
    case 2:
    Serial.println("Blood's oxygen:");
    Serial.println(SPO2);
    SPO2=Serial1.read();//I get the oxygen saturation
    dato=0;
    break;
  }
}

Credits

Álix A.

Álix A.

1 project • 14 followers
Student of electronics engineering at UPB.
Nelson Fernando Monroy Rios

Nelson Fernando Monroy Rios

1 project • 4 followers
Ciro Alberto Gamboa

Ciro Alberto Gamboa

1 project • 4 followers
Student of electronic engineering and computing engineering
Sergio Alexander Salinas

Sergio Alexander Salinas

1 project • 0 followers
Thanks to Sergio Alexander Salinas, Nelson Pimiento Serrano, Jairo Vargas Quintero , and Universidad Pontificia Bolivariana.

Comments