Last active
August 30, 2018 09:54
-
-
Save IdrisCytron/03528948f6a4864edb742d64a64c4ff0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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