#include <ArduinoBLE.
h>
#include <Wire.h>
#include <ClosedCube_MAX30205.h>
#include <MAX30105.h>
#include <heartRate.h>
#define SERVICE_UUID "e2718b81-13fd-40e1-beaa-8c1478943906"
#define CHARACTERISTIC_UUID "7f21a525-8ef5-43fa-92d2-3fb5564aefa9"
std::string value1 = "";
BLEService bleService("19B10000-E8F2-537E-4F6C-D104768A1214");
BLEStringCharacteristic stringTemp("183E", BLERead | BLEWrite, 31);
BLEStringCharacteristic stringBpm("2A19", BLERead | BLEWrite, 31);
BLEStringCharacteristic stringVolt("2a3F", BLERead | BLEWrite, 31);
BLEStringCharacteristic stringIncoming("537E", BLERead | BLEWrite, 31);
String inData = "";
ClosedCube_MAX30205 max30205;
MAX30105 particleSensor;
const byte RATE_SIZE = 4; //Increase this for more averaging. 4 is good.
byte rates[RATE_SIZE]; //Array of heart rates
byte rateSpot = 0;
long lastBeat = 0; //Time at which the last beat occurred
float beatsPerMinute;
int beatAvg;
#define vibrationMotor 7
#define buzzer 6
#define voltSens 3
int incoming;
float temp = 0.00;
float volt = 0.00;
float val = 0.00;
unsigned static long timer = 0;
unsigned static long timer1 = 0;
unsigned static long declaredTime = 30000;
unsigned static long dt = 0;
String data = "";
std::string input = "";
String a = "";
String b = "";
String c = "";
void setup() {
[Link](9600);
while (!Serial);
if (![Link]()) {
[Link]("starting Bluetooth® Low Energy module failed!");
while (1);
}
[Link]("esp32");
[Link](bleService); // add the service UUID
[Link](stringTemp); // add the battery level
characteristic
[Link](stringBpm);
[Link](stringVolt);
[Link](stringIncoming);
pinMode(vibrationMotor, OUTPUT);
pinMode(buzzer, OUTPUT);
[Link]();
[Link](19, 18);
//[Link](0x48);
// [Link](); //Configure sensor with default settings
//
// [Link](0x0A); //Turn Red LED to low to indicate
sensor is running
// [Link](0); //Turn off Green LED
}
void readTemp(){
temp = [Link]();
}
void readBPM(){
long irValue = [Link]();
if (checkForBeat(irValue) == true)
{
//We sensed a beat!
long delta = millis() - lastBeat;
lastBeat = millis();
beatsPerMinute = 60 / (delta / 1000.0);
if (beatsPerMinute < 255 && beatsPerMinute > 20)
{
rates[rateSpot++] = (byte)beatsPerMinute;
rateSpot %= RATE_SIZE;
beatAvg = 0;
for (byte x = 0 ; x < RATE_SIZE ; x++)
beatAvg += rates[x];
beatAvg /= RATE_SIZE;
}
}
[Link]("IR=");
[Link](irValue);
[Link](", BPM=");
[Link](beatsPerMinute);
[Link](", Avg BPM=");
[Link](beatAvg);
if (irValue < 50000)
[Link](" No finger?");
[Link]();
}
void getVoltage(){
val = analogRead(voltSens);
volt = val*(3.3/4095)*2;
String a1,b1,c1;
void loop() {
BLEDevice central = [Link]();
if (central) {
if(millis() - timer1 > dt){
while(true){
if(millis() - timer < 20000){ //for 20 seconds it will active
readTemp();
readBPM();
getVoltage();
a1 = temp;
b1 = beatsPerMinute;
c1 = volt;
a = "Temp: " + a1;
b = "BPM: " +b1;
c = "Voltage: " +c1;
BLEDevice central = [Link]();
[Link](bleService);
[Link](a.c_str());
[Link](b.c_str());
[Link](c.c_str());
if([Link]()){
if([Link]()){
if([Link]()){
digitalWrite(vibrationMotor, HIGH);
digitalWrite(buzzer, HIGH);
delay(2000); //playing buzzerr and vibration motor for two seconds
digitalWrite(vibrationMotor, LOW);
digitalWrite(buzzer, LOW);
BLEDevice central = [Link]();
}
}
}
digitalWrite(vibrationMotor, LOW);
digitalWrite(buzzer, LOW);
}
else{
timer1 = millis();
dt = declaredTime;
break;
}
}
}
else{
timer = millis();
}
}
}