hey guys…
I use Sensor Pulse as my sensor.
i need to measure the heart rate BPM to display on my Blynk.
but the sensor doesn’t seems to be responding according to my finger placement. if i put my finger the sensor wont showing anything, the sensor showing some result only when i try tapping the sensor, and it get random BPM.
i got code from https://github.com/vamsikikkuri/Pulse-Sensor IoT/blob/master/Pulse_Sensor_Final.ino.
code tht i use :
#define pulsePin A0
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = “”;//yourauthtoken
char ssid[] = “”;//name of your wifi
char pass[] = “”;//password of wifi
int rate[10];
unsigned long sampleCounter = 0;
unsigned long lastBeatTime = 0;
unsigned long lastTime = 0, N;
int BPM = 0;
int IBI = 0;
int P = 512;
int T = 512;
int thresh = 510;
int amp = 100;
int Signal;
boolean Pulse = false;
boolean firstBeat = true;
boolean secondBeat = true;
boolean QS = false;
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run();
if (QS == true) {
Serial.println("BPM : "+ String(BPM));
Blynk.virtualWrite(V1, BPM);
QS = false;
} else if (millis() >= (lastTime + 2)) {
readPulse();
lastTime = millis();
}
}
void readPulse() {
Signal = analogRead(pulsePin);
sampleCounter += 2;
int N = sampleCounter - lastBeatTime;
detectSetHighLow();
if (N > 250) {
if ( (Signal > thresh) && (Pulse == false) && (N > (IBI / 5) * 3) )
pulseDetected();
}
if (Signal < thresh && Pulse == true) {
Pulse = false;
amp = P - T;
thresh = amp / 2 + T;
P = thresh;
T = thresh;
}
if (N > 2500) {
thresh = 510;
P = 512;
T = 512;
lastBeatTime = sampleCounter;
firstBeat = true;
secondBeat = true;
}
}
void detectSetHighLow() {
if (Signal < thresh && N > (IBI / 5) * 3) {
if (Signal < T) {
T = Signal;
}
}
if (Signal > thresh && Signal > P) {
P = Signal;
}
}
void pulseDetected() {
Pulse = true;
IBI = sampleCounter - lastBeatTime;
lastBeatTime = sampleCounter;
if (firstBeat) {
firstBeat = false;
return;
}
if (secondBeat) {
secondBeat = false;
for (int i = 0; i <= 9; i++) {
rate[i] = IBI;
}
}
word runningTotal = 0;
for (int i = 0; i <= 8; i++) {
rate[i] = rate[i + 1];
runningTotal += rate[i];
}
rate[9] = IBI;
runningTotal += rate[9];
runningTotal /= 10;
BPM = 60000 / runningTotal;
QS = true;
}
thank you
PS : sorry if my english bad
this is cayenne IOT platform and you are using the code for blynk.
to start with get your sensor reading first. can you provide a link to the sensor which you are using?
Sorry dude… dont know where to ask lol
I got code from this
https://github.com/vamsikikkuri/Pulse-Sensor-IoT
#define pulsePin A0
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
// WiFi network info.
char ssid[] = "ssid";
char wifiPassword[] = "wifiPassword";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";
const int postingInterval = 10 * 1000;
int rate[10];
unsigned long sampleCounter = 0;
unsigned long lastBeatTime = 0;
unsigned long lastTime = 0, N;
int BPM = 0;
int IBI = 0;
int P = 512;
int T = 512;
int thresh = 512;
int amp = 100;
int Signal;
boolean Pulse = false;
boolean firstBeat = true;
boolean secondBeat = true;
boolean QS = false;
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}
void loop() {
Cayenne.loop();
if (QS == true) {
Serial.println("BPM: " + String(BPM));
QS = false;
} else if (millis() >= (lastTime + 2)) {
readPulse();
lastTime = millis();
}
}
void readPulse() {
Signal = analogRead(pulsePin);
sampleCounter += 2;
int N = sampleCounter - lastBeatTime;
detectSetHighLow();
if (N > 250) {
if ( (Signal > thresh) && (Pulse == false) && (N > (IBI / 5) * 3) )
pulseDetected();
}
if (Signal < thresh && Pulse == true) {
Pulse = false;
amp = P - T;
thresh = amp / 2 + T;
P = thresh;
T = thresh;
}
if (N > 2500) {
thresh = 512;
P = 512;
T = 512;
lastBeatTime = sampleCounter;
firstBeat = true;
secondBeat = true;
}
}
void detectSetHighLow() {
if (Signal < thresh && N > (IBI / 5) * 3) {
if (Signal < T) {
T = Signal;
}
}
if (Signal > thresh && Signal > P) {
P = Signal;
}
}
void pulseDetected() {
Pulse = true;
IBI = sampleCounter - lastBeatTime;
lastBeatTime = sampleCounter;
if (firstBeat) {
firstBeat = false;
return;
}
if (secondBeat) {
secondBeat = false;
for (int i = 0; i <= 9; i++) {
rate[i] = IBI;
}
}
word runningTotal = 0;
for (int i = 0; i <= 8; i++) {
rate[i] = rate[i + 1];
runningTotal += rate[i];
}
rate[9] = IBI;
runningTotal += rate[9];
runningTotal /= 10;
BPM = 60000 / runningTotal;
QS = true;
}
CAYENNE_OUT_DEFAULT()
{
Cayenne.virtualWrite(0, BPM);
}
Could you help me? Are there any codes for heart rate sensors used on wemos d1 r1?
Do a google search on how to connect a heart rate sensor to arduino devices and change the pin number to wemos.
i get this code, can you correct this code?
#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>
//#include <ESP8266WiFi.h>
const char* ssid = “sadfgh”;
const char* password = “ertiope123”;
//WiFiServer server(80);
const int PulseWire = analogRead(0);
const int LED13 = 13;
int Threshold = 550;
PulseSensorPlayground pulseSensor;
void setup() {
Serial.begin(115200);
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(2);
pulseSensor.setThreshold(Threshold);
if (pulseSensor.begin()) {
Serial.println(“We created a pulseSensor Object !”);
}
}
void loop() {
int myBPM = pulseSensor.getBeatsPerMinute();
if (pulseSensor.sawStartOfBeat()) {
Serial.println(" A HeartBeat Happened ! ");
Serial.print("BPM: ");
Serial.println(myBPM);
}
delay(20);
}
are you getting reading from the sensor in your serial montior?
nothing appeared at all in the serial monitor
good news sir,
I have tried the code that you created, and the results are serial monitors can display it
it’s like a miracle that God gave me for me
thank you in advance sir …
but I still have an obstacle, which is not yet connected to cayenne sir … something that holds to cayenne Sir, cayenne is always pending when connected sir.
can you give me advice? previously I had followed the steps to add new device cayenne sir
but you never seems to understand the advise given by me.