Skip to content

Instantly share code, notes, and snippets.

@IdrisCytron
Last active August 30, 2018 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IdrisCytron/03528948f6a4864edb742d64a64c4ff0 to your computer and use it in GitHub Desktop.
Save IdrisCytron/03528948f6a4864edb742d64a64c4ff0 to your computer and use it in GitHub Desktop.
/*
Project Video: https://www.youtube.com/watch?v=Dzq4tnJ0LjA
Product required:
1. Grove - Finger-clip Heart Rate Sensor
https://www.cytron.io/p-grv-heart-finger
2. Maker UNO:
https://www.cytron.io/p-maker-uno
Tutorial:
https://tutorial.cytron.io/2018/08/30/measuring-heart-rate-using-grove-sensor-and-arduino/
*/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <Wire.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
const int interval = 500;
unsigned char bpm = 0;
void setup()
{
// Debug console
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Wire.begin();
Blynk.begin(auth, wifi, ssid, pass);
}
void loop()
{
Blynk.run();
currentMillis = millis();
if (currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
Wire.requestFrom(0xA0 >> 1, 1); // Request 1 bytes from slave device
while (Wire.available()) { // Slave may send less than requested
bpm = Wire.read(); // Receive heart rate value (a byte)
Serial.println(bpm, DEC); // Print heart rate value
}
}
}
BLYNK_READ(V0)
{
Blynk.virtualWrite(0, bpm);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment