Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
ujjval rathod
Published

Building a Smart Helmet with the Blues Wireless Notecard

A smart helmet which can track the user location and detect a fall using a MPU6050 IMU based fall detector

IntermediateFull instructions provided805
Building a Smart Helmet with the Blues Wireless Notecard

Things used in this project

Hardware components

Blues Notecard (Cellular)
Blues Notecard (Cellular)
Has Cellular+GPS connectivity with M.2 type of headers, I have a global Notecard
×1
Blues Swan
Blues Swan
Has an STM32 MCU and comes in Adafruit Feather form factor
×1
Blues Notecarrier-AF
This Notecarrier has external SIM slot, two Grove port, one Qwiic port, a feather compatible header socket and pin type connections available onboard
×1
MPU6050 Sensor
6-Axis IMU with Accelerometer, Gyroscope sensors and motion detection, freefall detection, and zero motion detection capabilities.
×1
Battery Holder, 18650 x 2
Battery Holder, 18650 x 2
×1
18650 LiPo battery
×2
JST connector- 2 Pin
×1
SIM card Airtel
×1

Software apps and online services

Thinger.io Platform
Thinger.io Platform
Blues Notehub.io
Blues Notehub.io
Arduino IDE
Arduino IDE

Story

Read more

Code

Swanfalldetector

Arduino
One can use it with swan feather and set the duration and threshold values as per their needs.
#include <Wire.h>
#include <Notecard.h>
#include <MPU6050IMU.h>

MPU6050IMU imu;

volatile bool falldetection = false;
int count=0;

void int_serv(){
  Serial.println("Fall detected....!! ");
  falldetection = true;
  
  imu.readbyte(INT_STATUS);  
  digitalWrite(A0, HIGH);
  digitalWrite(LED_BUILTIN, HIGH);
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Wire.begin();
  attachInterrupt(digitalPinToInterrupt(D5), int_serv, HIGH);
  imu.begin();
  imu.enablefreefall(0xA0,0xFF);
  pinMode(A0, OUTPUT); 
  digitalWrite(A0, LOW); 
  
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

}

void loop() {
  // put your main code here, to run repeatedly:
  delay(100);
  
  while(falldetection == true){
    count+=1;
    if(count==10){
      count = 0;
      digitalWrite(A0, LOW);//pinmode low
      digitalWrite(LED_BUILTIN, LOW);
      falldetection = false;
      }
    delay(1000);
    }
}

Falldetector.ion

Arduino
It is the final code for the Free-Fall detection and sending data to Notehub
#include <Wire.h>
#include <Notecard.h>
#include <MPU6050IMU.h>

#define serialDebug Serial

#define productUID "ProjectUID"

Notecard notecard;
MPU6050IMU imu;

volatile int falldetection = 0;
volatile int count = 0;
volatile uint32_t fallcount = 0;

void int_serv()
{
  //Serial.println("Interuppt...! ");
  falldetection = 1;
  digitalWrite(LED_BUILTIN, HIGH);
  fallcount +=1;
  count = 0;
  imu.readbyte(INT_STATUS); //clear the interrupt by reading the status register.
  //sendsms();  
}

void setup() 
{
  // put your setup code here, to run once:
  delay(2500);
  Serial.begin(9600);
  serialDebug.begin(9600);
  Wire.begin();
  notecard.begin(0x17);
  notecard.setDebugOutputStream(serialDebug);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
  digitalWrite(D5, LOW);
  //pinMode(D5, INPUT);
  attachInterrupt(digitalPinToInterrupt(D5), int_serv, HIGH);
  
  J *req = notecard.newRequest("hub.set");
  JAddStringToObject(req, "product", productUID);
  JAddStringToObject(req, "mode", "periodic");
  notecard.sendRequest(req);
  delay(1000);
  
  J *req1 = notecard.newRequest("card.location.mode");
  JAddStringToObject(req1, "mode", "continuous");
  //JAddNumberToObject(req1, "seconds", 300);
  notecard.sendRequest(req1);

  delay(100);

  J *req3 = notecard.newRequest("card.time");
  notecard.sendRequest(req3);
  
  delay(1000);
  imu.begin();
  imu.enablefreefall(0x70, 0xFF);
  delay(1000);
}

void loop() 
{
  // put your main code here, to run repeatedly:

  float temp;
  double lat, lon;
  double voltage;
  bool alert;
  char *orientation;
  char msg[100];

  J *voltagereq = notecard.requestAndResponse(notecard.newRequest("card.voltage"));

  if (voltagereq != NULL){
    voltage = JGetNumber(voltagereq, "value");
    }
  notecard.deleteResponse(voltagereq);

  J *tempreq = notecard.requestAndResponse(notecard.newRequest("card.temp"));

  if(tempreq != NULL)
  {
    temp = JGetNumber(tempreq, "value");    
    notecard.deleteResponse(tempreq);
  }

  notecard.deleteResponse(tempreq);

  J *locationreq = notecard.requestAndResponse(notecard.newRequest("card.location"));

  if(locationreq != NULL)
  {
    lat = JGetNumber(locationreq, "lat");
    lon = JGetNumber(locationreq, "lon");
    Serial.println(lat);
    Serial.println(lon);
  }
//GPS is not working, use cellular to get the cordinates//
    if(lat == 0)
    {
      J *timereq = notecard.requestAndResponse(notecard.newRequest("card.time"));
      if(timereq != NULL)
      {
        lat = JGetNumber(timereq, "lat");
        lon = JGetNumber(timereq, "lon");
        notecard.deleteResponse(timereq);
      }
    notecard.deleteResponse(locationreq);
    }

  J *motionrequest = notecard.requestAndResponse(notecard.newRequest("card.motion"));

  if(motionrequest != NULL)
  {
    alert = JGetBool(motionrequest, "alert");
    orientation = JGetString(motionrequest, "status");
  }
  
  J *req4 = notecard.newRequest("note.add");
  
  if (req4 != NULL){
    JAddStringToObject(req4, "file", "sensors.qo");
    JAddBoolToObject(req4,"sync", true);
    
    J *body = JCreateObject();
    if (body != NULL)
    {
      JAddNumberToObject(body, "Temp", temp);
      if(lat != 0){
        JAddNumberToObject(body, "Latitude", lat);
        JAddNumberToObject(body, "Longitude", lon);        
        }
      JAddNumberToObject(body, "Count", fallcount);
      JAddNumberToObject(body, "Falldetection", falldetection);

      JAddBoolToObject(body, "alert", alert);
      JAddStringToObject(body, "orientation", orientation);

      JAddNumberToObject(body, "voltage", voltage);
      
      JAddItemToObject(req4, "body", body); 
    }    
    notecard.sendRequest(req4);
    }
    count = count + 1;
    
 //if long time fall was detected than make count==0
  if(count == 3){
    falldetection = 0;
    digitalWrite(LED_BUILTIN, LOW);
    count = 0;
   }
  if(fallcount > 10000){
      fallcount = 0;
   }
  if(count == 1 & falldetection == 1){
    
    snprintf(msg, sizeof(msg), "The fall detected at https://www.google.com/maps?q=%.81f,%.81f", lat, lon);
    J *req5 = notecard.newRequest("note.add");

   if (req5 != NULL){
    JAddStringToObject(req5, "file", "twilio.qo");
    JAddBoolToObject(req5, "sync", true);

    J *body1 = JCreateObject();
    if (body1 != NULL){
      JAddStringToObject(body1, "body", msg);
      JAddStringToObject(body1, "from", "+151655xxxx");
      JAddStringToObject(body1, "To", "+918735xxxxxx");

      JAddItemToObject(req5, "body", body1);
      } 
      notecard.sendRequest(req5);
    }     
    }
  delay(60000);
}

Credits

ujjval rathod

ujjval rathod

9 projects • 19 followers

Comments