Professional Documents
Culture Documents
NodeMCU ESP12E Pulse Heart Rate Sensor
NodeMCU ESP12E Pulse Heart Rate Sensor
===================================================================================
NodeMCU Heart Rate_Sensor Serial Plotter
//----------------------------------------Variable Declaration
const int PulseSensorHRWire = A0; //--> PulseSensor connected to ANALOG PIN 0 (A0 /
ADC 0).
const int LED_D1 = D1; //--> LED to detect when the heart is beating. The LED is
connected to PIN D1 (GPIO5) on the NodeMCU ESP12E.
int Threshold = 600; //--> Determine which Signal to "count as a beat" and which to
ignore.
int Signal; //--> holds the incoming raw data.
//----------------------------------------
//--------------------------------------------------------------------------------
void setup
void setup() {
Serial.begin(115200); //--> Set's up Serial Communication at certain speed.
pinMode(LED_D1,OUTPUT); //--> Set LED_3 PIN as Output.
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
void loop
void loop() {
Signal = analogRead(PulseSensorHRWire); //--> Read the PulseSensor's value.
Assign this value to the "Signal" variable.
delay(10);
}
//--------------------------------------------------------------------------------
//
===================================================================================
//
===================================================================================
Heart Rate Sensor Station Mode
//----------------------------------------Include the NodeMCU ESP8266 Library
//----------------------------------------see here: https://www.youtube.com/watch?
v=8jMr94B8iN0 to add NodeMCU ESP8266 library and board
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
//----------------------------------------
#define ON_Board_LED 2 //--> Defining an On Board LED (GPIO2 = D4), used for
indicators when the process of connecting to a wifi router and when there is a
client request.
unsigned long previousMillisGetHR = 0; //--> will store the last time Millis (to
get Heartbeat) was updated.
unsigned long previousMillisHR = 0; //--> will store the last time Millis (to get
BPM) was updated.
const long intervalGetHR = 10; //--> Interval for reading heart rate (Heartbeat) =
10ms.
const long intervalHR = 10000; //--> Interval for obtaining the BPM value based on
the sample is 10 seconds.
const int PulseSensorHRWire = A0; //--> PulseSensor connected to ANALOG PIN 0 (A0 /
ADC 0).
const int LED_D1 = D1; //--> LED to detect when the heart is beating. The LED is
connected to PIN D1 (GPIO5) on the NodeMCU ESP12E.
int Threshold = 600; //--> Determine which Signal to "count as a beat" and which to
ignore.
//--------------------------------------------------------------------------------
void handleRoot()
// This subroutine is executed when NodeMCU ESP12E IP is opened in the browser.
void handleRoot() {
String s = MAIN_page; //--> Read HTML contents
server.send(200, "text/html", s); //--> Send web page
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
void handleHeartRate()
// This subroutine is executed when there is a request from the browser / client.
// This subroutine will send / display the BPM value to the browser.
void handleHeartRate() {
digitalWrite(ON_Board_LED, LOW); //--> "ON_Board_LED" will be turned on when the
request from the browser / client starts.
String BPMvalSend = String(BPMval);
server.send(200, "text/plane", BPMvalSend); //--> Sends BPM value to client
request / browser.
digitalWrite(ON_Board_LED, HIGH); //--> Turn off the LED because the client
request / browser has been processed.
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
void GetHeartRate()
// This subroutine is for reading the heart rate and calculating it to get the BPM
value.
// To get a BPM value based on a heart rate reading for 10 seconds.
void GetHeartRate() {
//----------------------------------------Process of reading heart rate.
unsigned long currentMillisGetHR = millis();
BPMval = cntHB * 6; //--> The taken heart rate is for 10 seconds. So to get the
BPM value, the total heart rate in 10 seconds x 6.
Serial.print("BPM : ");
Serial.println(BPMval);
cntHB = 0;
}
//----------------------------------------
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
void setup()
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(500);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password); //--> Connect to your WiFi router
Serial.println("");
Serial.println();
Serial.println("Please wait 10 seconds to get the BPM Value");
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
void loop()
void loop() {
// put your main code here, to run repeatedly:
server.handleClient(); //--> Handle client requests
GetHeartRate(); //--> Calling the GetHeartRate() subroutine
}
//--------------------------------------------------------------------------------
//
===================================================================================
//
===================================================================================
Heart Rate Sensor Access Point Mode
//----------------------------------------Include the NodeMCU ESP8266 Library
//----------------------------------------see here: https://www.youtube.com/watch?
v=8jMr94B8iN0 to add NodeMCU ESP8266 library and board
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
//----------------------------------------
#include "Index.h" //--> Our HTML webpage contents with javascripts
#define ON_Board_LED 2 //--> Defining an On Board LED (GPIO2 = D4), used for
indicators when the process of connecting to a wifi router and when there is a
client request.
unsigned long previousMillisGetHR = 0; //--> will store the last time Millis (to
get Heartbeat) was updated.
unsigned long previousMillisHR = 0; //--> will store the last time Millis (to get
BPM) was updated.
const long intervalGetHR = 10; //--> Interval for reading heart rate (Heartbeat) =
10ms.
const long intervalHR = 10000; //--> Interval for obtaining the BPM value based on
the sample is 10 seconds.
const int PulseSensorHRWire = A0; //--> PulseSensor connected to ANALOG PIN 0 (A0 /
ADC 0).
const int LED_D1 = D1; //--> LED to detect when the heart is beating. The LED is
connected to PIN D1 (GPIO5) on the NodeMCU ESP12E.
int Threshold = 600; //--> Determine which Signal to "count as a beat" and which to
ignore.
//--------------------------------------------------------------------------------
void handleRoot()
// This subroutine is executed when NodeMCU ESP12E IP is opened in the browser.
void handleRoot() {
String s = MAIN_page; //--> Read HTML contents
server.send(200, "text/html", s); //--> Send web page
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
void handleHeartRate()
// This subroutine is executed when there is a request from the browser / client.
// This subroutine will send / display the BPM value to the browser.
void handleHeartRate() {
digitalWrite(ON_Board_LED, LOW); //--> "ON_Board_LED" will be turned on when the
request from the browser / client starts.
String BPMvalSend = String(BPMval);
server.send(200, "text/plane", BPMvalSend); //--> Sends BPM value to client
request / browser.
digitalWrite(ON_Board_LED, HIGH); //--> Turn off the LED because the client
request / browser has been processed.
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
void GetHeartRate()
// This subroutine is for reading the heart rate and calculating it to get the BPM
value.
// To get a BPM value based on a heart rate reading for 10 seconds.
void GetHeartRate() {
//----------------------------------------Process of reading heart rate.
unsigned long currentMillisGetHR = millis();
BPMval = cntHB * 6; //--> The taken heart rate is for 10 seconds. So to get the
BPM value, the total heart rate in 10 seconds x 6.
Serial.print("BPM : ");
Serial.println(BPMval);
cntHB = 0;
}
//----------------------------------------
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
void setup()
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(500);
Serial.println();
Serial.println("Please wait 10 seconds to get the BPM Value");
}
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
void loop()
void loop() {
// put your main code here, to run repeatedly:
server.handleClient(); //--> Handle client requests
GetHeartRate(); //--> Calling the GetHeartRate() subroutine
}
//--------------------------------------------------------------------------------
//
===================================================================================