• Hardware model-node mcu ESP8266 12E, max30100 oxygen & heart rate sensor, 2 switches and 1 servo.
This Program runs fine and gives Temp, oxygen and heart beats but when I add switches, servo and buzzer max30100 stops giving oxygen and heartbeat while the sensor light keeps glowing. I have attached second code below this one. Please help.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "MAX30100_PulseOximeter.h"
#include <SimpleTimer.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "6ri9E_diXys4DvhS1ulntv8Tpa2kXdrk";
/* WiFi credentials */
char ssid[] = "adik";
char pass[] = "1234567890";
#define REPORTING_PERIOD_MS 3000
SimpleTimer timer;
PulseOximeter pox;
uint8_t tempPin = A0; //<---------This is the PIN the LM53 is connected! CHANGE accordingly
uint16_t val;
uint32_t tsLastReport = 0;
void onBeatDetected()
{
;
}
void myTimerEvent()
{
analogRead(tempPin);
val = analogRead(tempPin);
float mv = ( val / 1024.0) * 3300;
float cel = mv / 10;
Serial.print("Temp: ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
Blynk.virtualWrite(V4, cel);
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
Serial.print("Initializing pulse oximeter..");
// Initialize the PulseOximeter instance
// Failures are generally due to an improper I2C wiring, missing power supply
// or wrong target chip
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
digitalWrite(1,HIGH);
}
pox.setIRLedCurrent(MAX30100_LED_CURR_24MA);
// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
timer.setInterval(1000L, getSendData);
timer.setInterval(1000L, myTimerEvent);
}
void loop()
{
timer.run(); // Initiates SimpleTimer
Blynk.run();
// Make sure to call update as fast as possible
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
// to computer serial monitor
Serial.print("BPM: ");
Serial.print(pox.getHeartRate());
//blue.println("\n");
Serial.print(" SpO2: ");
Serial.print(pox.getSpO2());
Serial.print("%");
Serial.println("\n");
Blynk.virtualWrite(V2,pox.getHeartRate() );
Blynk.virtualWrite(V3,pox.getSpO2());
tsLastReport = millis();
}
}
void getSendData()
{
;
}```
2nd code where max30100 stops giving oxygen and heartbeat while other devices switch temperature buzzer works fine.
```#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <SimpleTimer.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>
int buzzer = D3 ;
char auth[] = "6ri9E_diXys4DvhS1ulntv8Tpa2kXdrk";
/* WiFi credentials */
char ssid[] = "adik";
char pass[] = "1234567890";
WidgetLCD lcd(V1);
#define REPORTING_PERIOD_MS 3000
SimpleTimer timer;
Servo servo1;
PulseOximeter pox;
uint8_t tempPin = A0;
uint16_t val;
uint32_t tsLastReport = 0;
void onBeatDetected()
{
;
}
void temperature()
{
analogRead(tempPin);
val = analogRead(tempPin);
float mv = ( val / 1024.0) * 3300;
float cel = mv / 10;
Serial.print("Temp: ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
Blynk.virtualWrite(V4, cel);
}
void servoDataSend()
{
int key1 = digitalRead(D5);
if (key1 == HIGH)
{
servo1.write(90);
delay(2000);
servo1.write(0);
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(4, 0, "Medicine"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(4, 1, "Taken");
delay (5000);
lcd.clear(); //Use it to clear the LCD Widget
}
else
{
servo1.write(0);
}
}
void emergency()
{
int key2 = digitalRead(D6);
if (key2 == HIGH)
{
digitalWrite (buzzer, HIGH) ;
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(4, 0, "Emergency"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(4, 1, "Alert");
delay (2000);
lcd.clear(); //Use it to clear the LCD Widget
digitalWrite (buzzer, LOW) ;
}
else
{
lcd.clear(); //Use it to clear the LCD Widget;
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(D5, INPUT);
pinMode(D6, INPUT);
pinMode(D6, OUTPUT);
pinMode(D3, OUTPUT);
servo1.attach(D8);
servo1.write(0);
Serial.print("Initializing pulse oximeter..");
// Initialize the PulseOximeter instance
// Failures are generally due to an improper I2C wiring, missing power supply
// or wrong target chip
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
digitalWrite(1,HIGH);
}
pox.setIRLedCurrent(MAX30100_LED_CURR_24MA);
// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
timer.setInterval(1000L, getSendData);
timer.setInterval(1000L, temperature);
timer.setInterval(1000L, servoDataSend);
timer.setInterval(1000L, emergency);
}
void loop()
{
timer.run(); // Initiates SimpleTimer
Blynk.run();
// Make sure to call update as fast as possible
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
// to computer serial monitor
Serial.print("BPM: ");
Serial.print(pox.getHeartRate());
//blue.println("\n");
Serial.print(" SpO2: ");
Serial.print(pox.getSpO2());
Serial.print("%");
Serial.println("\n");
Blynk.virtualWrite(V2,pox.getHeartRate() );
Blynk.virtualWrite(V3,pox.getSpO2());
tsLastReport = millis();
}
}
void getSendData()
{
;
}```