Kutluhan Aktar
Published © CC BY

Free IoT Services | Get Heart Rate, Temperature and Humidity

Get data packets from NodeMCU etc. through encrypted database connection path by subscribing with Google+, Twitter, or creating an account.

EasyFull instructions provided1 hour203
Free IoT Services | Get Heart Rate, Temperature and Humidity

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
KY-039 Finger Heart Rate Sensor
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
5 mm LED: Green
5 mm LED: Green
×1
SparkFun Solder-able Breadboard - Mini
SparkFun Solder-able Breadboard - Mini
×3
Male/Male Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE
TheAmplituhedron IoT Services
Programmed in PHP, AJAX and jQuery by myself for only my website subscribers.
Twitter
Twitter
Continue with Twitter
Google Gmail
Sign In with Google Plus

Story

Read more

Custom parts and enclosures

Fritzing File

Schematics

Schematic

Free iot i 3ycvbxvpdv

Code

Source Code

Arduino
         /////////////////////////////////////////////  
        // IoT Heart Rate and Temperature Detector //
       //    via TheAmplituhedron IoT Services    //
      //          ---------------------          //
     //           NodeMCU (ESP-12E)             //           
    //           by Kutluhan Aktar             // 
   //                                         //
  /////////////////////////////////////////////

// By only subscribing to TheAmplituhedron, you will be able get your data packets from NodeMCU, or any other device that can make an HTTP GET Request, to your IoT Dashboard on your account page.
// TheAMplituhedron IoT Services is an available system for TheAmplituhedron.com subscribers only, and simple to use.
// Follow the steps down below to create and communicate your connection path on which you will display your data packets in every 2 seconds.
// 1) Go to your Dashboard.
// 2) Click Iot Services under Available Systems.
// 3) Read the given instructions and click Create+
// 4) Copy the url to use in the souce code.
// After creating your unique connection path, you can send data packets through NodeMCU by entering your WiFi settings and required information down below.
//
// As a reminder, my website has SSL protection so that you need to identify your NodeMCU connection by entering TheAmplituhedron FingerPrint or ThumbPrint.
// You can learn about it more from the link below.
// https://www.theamplituhedron.com/dashboard/IoTServices/
//
// In this project turorial, I decided to use a KY-039 Heart Rate Sensor and a DHT11 Temperature and Humidity as data providers.
// But do not forget that the heart rate value generated by KY-039 is not accurate most of the time; it is merely a demonstration sensor for this project tutorial. If you want to
// get more accurate data in that subject, I recommend you to use an heart rate detector with enhanced accuracy and efficieny.
//
// Connections
// NodeMCU (ESP-12E) :           
//                                Control Led
// D1  --------------------------- +
//                                DHT11 Temperature and Humidity Sensor Module
// D2  --------------------------- Data
//                                KY-039 Heart Rate Sensor
// A0  --------------------------- S


// Include required libraries to send data to a website, in this case TheAmplituhedron.com.
#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>

// Include DHT master library to elicit information from DHT11 Temperture and Humidity Sensor.
#include "DHT.h"

// Define DHT object.
DHT dht;

// Define your WIFI settings.
const char *ssid = "WiFi_SSID";
const char *password = "WiFi_Password";

// Define Finger Heart Rate Sensor signal pin.
#define fingerSignal A0

// Define a default average heartbeat value as integer to count heartbeat.
int count = 70;

// Define a control pin for WiFi test.
#define control D1

// Create data holders to send data packets.
int temperature, humidity;
String connectionPath, USERNAME, HEDRON, data_name_1, data_name_2, data_name_3, data_1, data_2, data_3;


void setup() {
  // Start DHT object at digital pin 2.
  dht.setup(D2);
  
  // Activate control led.
  pinMode(control, OUTPUT);
  digitalWrite(control, LOW);
  
  // Wait until connected.
  delay(1000);
  Serial.begin(115200);
  // It is just for assuring connection is alive.
  WiFi.mode(WIFI_OFF);
  delay(1000);
  // This mode allows NodeMCU to connect any WiFi directly.
  WiFi.mode(WIFI_STA);        
  // Connect NodeMCU to your WiFi.
  WiFi.begin(ssid, password);
  
  Serial.print("\n\n");
  Serial.print("Try to connect to WiFi. Please wait! ");
  Serial.print("\n\n");
  // Halt the code until connected to WiFi.
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print("*");
  }
 
  // If connection is successful, turn control led on and write WiFi SSID to serial monitor along with assigned IPAddress.
  digitalWrite(control, HIGH);
  Serial.print("\n\n");
  Serial.print("-------------------------------------");
  Serial.print("\n\n");
  Serial.print("Connection is successful!");
  Serial.print("\n\n");
  Serial.print("Connected WiFi SSID : ");
  Serial.print(ssid);
  Serial.print("\n\n");
  Serial.println("Connected IPAddress : ");
  Serial.println(WiFi.localIP());
  Serial.print("\n\n");
}

void loop() {
  // Detect the heart beat approximately in a given range point.
  heartBeat(1000);
  // Get tenperature and humidity from DHT11.
  getTemperatureandHumidity();

  // Create HTTP object to make a request.
  HTTPClient http;    
 
  // Enter your connection path variables and define a name and a value for each data packet below - up to 6 entry.
  USERNAME = "Account_Username";
  HEDRON = "Account_Hedron";
  // You can change these names if you want.
  data_name_1 = "HeartRate";
  data_name_2 = "Temperature";
  data_name_3 = "Humidity";
  data_1 = String(count);
  data_2 = String(temperature) + "C";
  data_3 = String(humidity) + "%";
  
  connectionPath = "https://www.theamplituhedron.com/dashboard/IoTServices/" + USERNAME + "-" + HEDRON + ".php?dataNameFirst=" + data_name_1 + "&dataNameSecond=" + data_name_2 + "&dataNameThird=" + data_name_3 + "&data1=" + data_1 + "&data2=" + data_2 + "&data3=" + data_3;
  
  http.begin(connectionPath, "xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx");
  
  int httpCode = http.GET();           
  String payload = http.getString();    
 
  Serial.println(httpCode); 
 
  // End HTTP Get Request.
  http.end(); 
  
  // Send data packets every 2 seconds to TheAmplituhedron.
  delay(2000);

}

// KY-039 Heart Rate Sensor detection unit is based on the peaks generated by the sensor, and by conunting them in a defined time period, you can approximately detect the heart beat. Nevertheless, this data might not be accurate becouse of the circuit schematic of KY-039; it is just a demonstration.
void heartBeat(int Delay){
  // Read sensor after a delay to detect peaks for conunting them later.
  int firstReading = analogRead(fingerSignal);
  delay(Delay);
  int secondReading = analogRead(fingerSignal);
  // Calculate the range to define peaks.
  int peak = firstReading - secondReading;
  // If there is a peak, count them to evaluate the heart beat at a given time. These values are accurate for my sensor but you might need to test yours to get data explicitly.
  if(peak >= 2){
    count++;
    }else if(peak < 2 && peak >= 0){
      count = count;
      }else if(peak < 0){
        count--;
        }
  }

  void getTemperatureandHumidity(){
      // Wait until DHT11 Temperature and Humidity Sensor became ready.
      delay(dht.getMinimumSamplingPeriod());
      // Get temperature and humidity. 
      humidity = dht.getHumidity();
      temperature = dht.getTemperature();
    }

Credits

Kutluhan Aktar

Kutluhan Aktar

15 projects • 26 followers
Physics enthusiast, Developer, Programmer and Maker.

Comments