Code 2
Code 2
h>
#include <Wire.h>
#include <ClosedCube_MAX30205.h>
#include <MAX30105.h>
#include <heartRate.h>
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);
ClosedCube_MAX30205 max30205;
MAX30105 particleSensor;
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;
void setup() {
Serial.begin(9600);
while (!Serial);
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy module failed!");
while (1);
}
BLE.setLocalName("esp32");
pinMode(vibrationMotor, OUTPUT);
pinMode(buzzer, OUTPUT);
BLE.advertise();
Wire.begin(19, 18);
//max30205.begin(0x48);
// particleSensor.setup(); //Configure sensor with default settings
//
// particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to indicate
sensor is running
// particleSensor.setPulseAmplitudeGreen(0); //Turn off Green LED
}
void readTemp(){
temp = max30205.readTemperature();
}
void readBPM(){
long irValue = particleSensor.getIR();
if (checkForBeat(irValue) == true)
{
//We sensed a beat!
long delta = millis() - lastBeat;
lastBeat = millis();
beatAvg = 0;
for (byte x = 0 ; x < RATE_SIZE ; x++)
beatAvg += rates[x];
beatAvg /= RATE_SIZE;
}
}
Serial.print("IR=");
Serial.print(irValue);
Serial.print(", BPM=");
Serial.print(beatsPerMinute);
Serial.print(", Avg BPM=");
Serial.print(beatAvg);
Serial.println();
}
void getVoltage(){
val = analogRead(voltSens);
volt = val*(3.3/4095)*2;
String a1,b1,c1;
void loop() {
BLEDevice central = BLE.central();
if (central) {
if(central.connected()){
if(stringIncoming.written()){
if(stringIncoming.value()){
digitalWrite(vibrationMotor, HIGH);
digitalWrite(buzzer, HIGH);
delay(2000); //playing buzzerr and vibration motor for two seconds
digitalWrite(vibrationMotor, LOW);
digitalWrite(buzzer, LOW);
BLEDevice central = BLE.central();
}
}
}
digitalWrite(vibrationMotor, LOW);
digitalWrite(buzzer, LOW);
}
else{
timer1 = millis();
dt = declaredTime;
break;
}
}
}
else{
timer = millis();
}
}
}