nishanchettri
Published © LGPL

Smart Gloves

Monitor your sleep and meditation using smart gloves and IOT application.

IntermediateFull instructions provided932
Smart Gloves

Things used in this project

Hardware components

ESP8266 ESP-12E
Espressif ESP8266 ESP-12E
×1
Resistor 10k ohm
Resistor 10k ohm
×1
aluminium foil
×1
Capacitor 100 nF
Capacitor 100 nF
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Phone Audio Connector, Jack
Phone Audio Connector, Jack
×1
Phone Audio Connector, 3.5mm
Phone Audio Connector, 3.5mm
×1
Male Header 40 Position 1 Row (0.1")
Male Header 40 Position 1 Row (0.1")
×1
Grove - 2-Channel SPDT Relay
Seeed Studio Grove - 2-Channel SPDT Relay
×1

Software apps and online services

Arduino IDE
Arduino IDE
Adafruit IO

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Wire Cutter / Stripper, 5.25 " Overall Length
Wire Cutter / Stripper, 5.25 " Overall Length

Story

Read more

Schematics

Glove circuit with sensor electrode

IOT node for turning on fan when trigger is caused

IOT node for turning on RGB mood LED bulb when trigger is caused

Code

For the glove and IOT dashboard monitoring

Arduino
/* ===================================================================
Thanks to Adafrut mqtt example.
Author: nishan chettri
This sketch includes the use of NTC 10D-9 thermistor, it is commented out.If you want to monitoe temperature too you can add the temperature sensor and uncomment.
=======================================================================
*/

#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <math.h>        //include math.h

/******************Thermistor Calibration*************************/
//float thermistorError=20 ;
//There is 6 degree deviation from actual value

/******************* WiFi Access Point ***************************/
#define WLAN_SSID       "nissan"
#define WLAN_PASS       "password"
/******************* Adafruit.io Setup ***************************/
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883                   // use 8883 for SSL
#define AIO_USERNAME    "put your adafruit IO username herer"
#define AIO_KEY         "put your Api key here"
//********* Global State (you don't need to change this!) **********
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
/************************ Feeds ********************************/
/************************* Topics ******************************/
//  Setup a feed called 'temp_topic' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
Adafruit_MQTT_Publish gsr = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/gsr10_05_2020");
//Adafruit_MQTT_Publish temp = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temp");
//Publishing to the feed "band" in my dashboard
void MQTT_connect();
//declaration of mqtt connect funciton
//measure(beta,normal tempreature in K, normal resistance, analog value , Series resistance)
double measure(double beta,double To,double R,double aVal,double Rs);

void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.println(F("Adafruit MQTT demo"));
// Connect to WiFi access point.
  Serial.println(); Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);
  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
Serial.println("WiFi connected");
  Serial.println("IP address: "); Serial.println(WiFi.localIP());
}
//uint32_t x = 0;
/************************ Loop  *****************************/
void loop()
{
  delay(2000);
  MQTT_connect();
//    double val=analogRead(34);   //analog read 
    double gsrValue=analogRead(A0);
  /*measure(beta,normal tempreature in K, normal resistance, analog value , Series resistance)*/
//    double temperature = measure(3000,25,10,val,120);
/************************ Publish  **************************/

  // Publishing the temperature and GSR raw data
//  if (! temp.publish(temperature)) {
//    Serial.println(F("temp Failed"));
//  } else {
//    Serial.println(F("OK!"));
//  }
    if (! gsr.publish(gsrValue)) {
    Serial.println(F("gsr Failed"));
  } else {
    Serial.println(gsrValue);
    Serial.println(F("OK!"));
  }
/************************ Ping  *********************************/
  // ping the server to keep the mqtt connection alive
  // NOT required if you are publishing once every KEEPALIVE seconds
  
    if(! mqtt.ping()) {
    mqtt.disconnect();
    }
  delay(2000);
}

/************************** MQTT Conn  **************************/
// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect()
{
  int8_t ret;
// Stop if already connected.
  if (mqtt.connected()) {
    return;
  }
Serial.print("Connecting to MQTT... ");
uint8_t retries = 3;
  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
    Serial.println(mqtt.connectErrorString(ret));
    Serial.println("Retrying MQTT connection in 5 seconds...");
    mqtt.disconnect();
    delay(5000);  // wait 5 seconds
    retries--;
    if (retries == 0) {
      // basically die and wait for WDT to reset me
      while (1);
    }
  }
  Serial.println("MQTT Connected!");
}
/*
 * Function to calculate temperature according to thermistor used here NTC 10D-9 is used
 * This function can be used with any thermistor
 */
 
//double measure(double beta,double To,double R,double aVal,double Rs)
//{ //steinhart hart eqution for temperature calculation
//  double To_C=To+273.15;
//  double Eout=(aVal/4095)*3.3;
//  double Rt=((3.3*Rs)/Eout)-120 ;
//  double alpha=log(Rt/R)/beta ;
//  double inv_To= 1/To_C ;
//  double Tk= 1/(alpha+inv_To) ; 
//  double Tc=Tk-273.15-thermistorError ; //convert from kelvin to celsius 
//  return Tc;
//}

Code for the node controlling the fan

Arduino
/* ===================================================================
Thanks to Adafrut mqtt example.
Author: nishan chettri
Please make necessary tweaks according tothe board used. This is for ESP12E
If you are using ESP32:
replace #include <ESP8266WiFi.h> by #include <WiFi.h>
=======================================================================
*/

#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

/************************* WiFi Access Point *********************************/

#define WLAN_SSID       "wifi ssid"
#define WLAN_PASS       "password"

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883                   // use 8883 for SSL
#define AIO_USERNAME    "put your username here"
#define AIO_KEY         "put your api key here"

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

/****************************** Feeds ***************************************/


Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/fan");

/*************************** Sketch Code ************************************/

void MQTT_connect();
#define fanPin D7


void setup() {
  Serial.begin(115200);
  delay(10);
  pinMode(fanPin,OUTPUT);
  Serial.println(F("Adafruit MQTT demo"));

  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();

  Serial.println("WiFi connected");
  Serial.println("IP address: "); Serial.println(WiFi.localIP());

  // Setup MQTT subscription for onoff feed.
  mqtt.subscribe(&onoffbutton);
  digitalWrite(fanPin,LOW);
}

uint32_t x=0;

void loop() {
  // Ensure the connection to the MQTT server is alive (this will make the first
  // connection and automatically reconnect when disconnected).  See the MQTT_connect
  // function definition further below.
  MQTT_connect();

  // this is our 'wait for incoming subscription packets' busy subloop
  // try to spend your time here

  Adafruit_MQTT_Subscribe *subscription;
  while ((subscription = mqtt.readSubscription(5000))) {
    if (subscription == &onoffbutton) {
      Serial.print("Got: ");
      Serial.print((char*)onoffbutton.lastread);
    if(strcmp((char*)onoffbutton.lastread,"OFF")==0)
      {
        digitalWrite(fanPin,HIGH);
      }
      else
      {
        digitalWrite(fanPin,LOW);
      }
    }
  }
  
  // Now we can publish stuff!
 
  // ping the server to keep the mqtt connection alive
  // NOT required if you are publishing once every KEEPALIVE seconds
  
 if(! mqtt.ping()) {
   mqtt.disconnect();
 }
}
void MQTT_connect() {
  int8_t ret;

  // Stop if already connected.
  if (mqtt.connected()) {
    return;
  }

  Serial.print("Connecting to MQTT... ");

  uint8_t retries = 3;
  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
       Serial.println(mqtt.connectErrorString(ret));
       Serial.println("Retrying MQTT connection in 5 seconds...");
       mqtt.disconnect();
       delay(5000);  // wait 5 seconds
       retries--;
       if (retries == 0) {
         // basically die and wait for WDT to reset me
         while (1);
       }
  }
  Serial.println("MQTT Connected!");
}

Credits

nishanchettri

nishanchettri

6 projects • 4 followers
Maker with an infinite curiosity to learn.

Comments