Hannan Satopay
Published © CC BY-NC-ND

SuperWear

SuperWear is one-of-a-kind and seamless approach that enables an individual to utilize technology for healthcare and daily lifestyle.

IntermediateFull instructions providedOver 1 day262
SuperWear

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Solar Cockroach Vibrating Disc Motor
Brown Dog Gadgets Solar Cockroach Vibrating Disc Motor
×1
SparkFun Power Cell - LiPo Charger/Booster
SparkFun Power Cell - LiPo Charger/Booster
×1
Inertial Measurement Unit (IMU) (6 deg of freedom)
Inertial Measurement Unit (IMU) (6 deg of freedom)
×1

Software apps and online services

Blynk
Blynk

Story

Read more

Schematics

Breadboard Circuit

Code

SuperWear

C/C++
The main code to run all the modules for the project. Please save it as .ino file and then load it up in the Arduino IDE.
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// Auth Token for Blynk
char auth[] = "#########";

// WiFi credentials.
char ssid[] = "#####";
char pass[] = "#####";

// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default)
MPU6050 accelgyro(0x68);

int16_t ax, ay, az;
int16_t gx, gy, gz;
float acc_vector;
float tempMPU;

int workMode = 0;

int vibrationPin = D3;

int slouchingCountLight=0;
int slouchingCountModerate=0;
int slouchingCountExtreme=0;

long highPeakStep;
long lowPeakStep;
long highPeakStepVal;
int highPeakStepDetected=0;
int steps=0;

int weight;
int height;
  
unsigned long previousMillis = 0;        
const long interval = 10000;     

BlynkTimer timer;

// Code for Sleep Monitoring
void sleepMonitoring()
{
  if(abs(ay-az)<7000)
  {
    Blynk.virtualWrite(V15, 1);
  }
  else
  {
    Blynk.virtualWrite(V15, 0);
  } 
}

// Code for Custom Alarm
BLYNK_WRITE(V1) {
  // Receive 1.0 when time starts so turn the vibration motor ON and receive 0.0 when time stops so turn the vibration motor OFF
  if (param.asInt() == 1.0)
  {
    digitalWrite(vibrationPin, HIGH);
  }
  else
  {
    digitalWrite(vibrationPin, LOW);
  }
}

BLYNK_WRITE(V10) {
 weight=param.asInt(); // Weight in kg
}

BLYNK_WRITE(V11) {
 height=param.asInt(); // Height in cm
}

// Code to check Work Mode Status
BLYNK_WRITE(V8) {
  workMode = param.asInt();
  if(workMode==0)
  {
    slouchingCountLight=0;
    slouchingCountModerate=0;
    slouchingCountExtreme=0;
    Blynk.virtualWrite(V6,"OFF");
    digitalWrite(vibrationPin, LOW);
  }
}

void setup()
{
  pinMode(vibrationPin, OUTPUT);
  Wire.begin(); // join I2C bus
  accelgyro.initialize();

//  while(!accelgyro.testConnection())
//  {
//    Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
//    delay(500);
//  }

// Add offsets
  accelgyro.setXAccelOffset(-1188);
  accelgyro.setYAccelOffset(1345);
  accelgyro.setZAccelOffset(1386);
  accelgyro.setXGyroOffset(135);
  accelgyro.setYGyroOffset(138);
  accelgyro.setZGyroOffset(-20);

  Blynk.begin(auth, ssid, pass);
  timer.setInterval(5000L, sleepMonitoring); // Check every ten seconds if sleeping
}

BLYNK_CONNECTED() {
Blynk.syncVirtual(V8, V10, V11);
}

void loop()
{
  Blynk.run();
  timer.run();
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  acc_vector=sqrt(sq(ax)+sq(ay)+sq(az));
  if (workMode == 1)
  { 
    slouchingDetection();
  }
  pedometerActivity();
  temperatureMonitoring();
}

void slouchingDetection() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    slouchingCountLight=0;
    slouchingCountModerate=0;
    slouchingCountExtreme=0;
  }
 if(((az+ay) >= 100)&&((az+ay) < 3000)){
  slouchingCountLight=slouchingCountLight+1;
  if(slouchingCountLight>10)
  {
      Blynk.virtualWrite(V6,"Light Slouching"); 
      slouchingCountLight=0;
  }
 }
 else if(((az+ay) >= 3000)&&((az+ay) < 6000)){
  slouchingCountModerate=slouchingCountModerate+1;
    if(slouchingCountModerate>10)
  {
      Blynk.virtualWrite(V6,"Moderate Slouching");
      slouchingCountModerate=0;
      digitalWrite(vibrationPin, HIGH);
  }
 }
 else if(((az+ay) >= 6000)){
  slouchingCountExtreme=slouchingCountExtreme+1;
    if(slouchingCountExtreme>10)
  {
      Blynk.virtualWrite(V6,"Extreme Slouching");
      slouchingCountExtreme=0;
      digitalWrite(vibrationPin, HIGH);
  }
 }
 else
 {
  Blynk.virtualWrite(V6,"Good Posture");
  digitalWrite(vibrationPin, LOW);
 }
}

void pedometerActivity() {
 if(highPeakStepDetected==0)
{
  highPeakStep=0;
  lowPeakStep=1000;
}
if(acc_vector>16000)
{
 highPeakStep = millis();
 highPeakStepVal=acc_vector;
 highPeakStepDetected=1;
}
else if(acc_vector<(highPeakStepVal*0.95))
{
  lowPeakStep = millis();
}
if(abs(lowPeakStep-highPeakStep)<70)
{
  steps=steps+1;
  highPeakStepDetected=0;
  float caloriesBurnedPerMile = 0.57 * (weight * 2.2);
  float strip = height * 0.415;
  float stepCountMile = 160934.4 / strip;
  float conversationFactor = caloriesBurnedPerMile / stepCountMile;
  float caloriesBurned = steps * conversationFactor; // In cal
  float distance = (steps * strip) / 100000; // In km
  Blynk.virtualWrite(V12,steps);
  Blynk.virtualWrite(V13,caloriesBurned);
  Blynk.virtualWrite(V14,distance);
  delay(100);
}
}

void temperatureMonitoring() {
  tempMPU = accelgyro.getTemperature();
  Blynk.virtualWrite(V4, (tempMPU/340.00+36.53)); // Temperature in degree celcius
}

Credits

Hannan Satopay

Hannan Satopay

1 project • 4 followers
I am doing electronics engineering and I am interested in both hardware and software development.

Comments

Add projectSign up / Login