BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

The node MCU keeps disonnecrting while it runs another project.Plz help me

Im using node mcu connected with max30100 sensor, lm35,servo, and two switches.
Wen I only run max30100 program it goes well but after combing this code it keeps connecting and disconnecting.

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>
#include <Wire.h>
#include <SimpleTimer.h>
#include "MAX30100_PulseOximeter.h"

const int selectPins[3] = {D3, D2, D1};
const int analogInput = A0;

char auth[] = "DKzt93WiavmRmSvb1XmSuCTGLgK0oBt2";

char ssid[] = "adik";
char pass[] = "1234567890";

#define REPORTING_PERIOD_MS     3000
SimpleTimer timer;

PulseOximeter pox;
uint32_t tsLastReport = 0;

WidgetLCD lcd1(V2);

Servo servo1, servo2;

void onBeatDetected()
{
   ;
}

void setup()
{
 Serial.begin(9600);

 pinMode(D5, INPUT);
 pinMode(D6, INPUT);
 pinMode(D6, OUTPUT);

 servo1.attach(D8);
 servo1.write(0);
 Blynk.begin(auth, ssid, pass);
 lcd1.clear();

 for (int i = 0; i < 3; i++)
 {
   pinMode(selectPins[i], OUTPUT);
   digitalWrite(selectPins[i], HIGH);
 }
{
   Serial.begin(115200);
   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);
}
 }

BLYNK_WRITE(V5) // V5 is the number of Virtual Pin
{
 int pinValue = param.asInt();
 Serial.println(pinValue);
}

void loop()
{
 Blynk.run();
 int key1 = digitalRead(D5);

 if (key1 == HIGH)
 {
   servo1.write(90);
   Blynk.notify("Yaaay... Medicine 1 taken!");
   delay(2000);
   servo1.write(0);
 }
 else
 {
   servo1.write(0);
 }
 int key2 = digitalRead(D8);
 Serial.println(key2);

 if (key2 == HIGH)
 {
   digitalWrite(D8, LOW);
   Blynk.notify("Emergency Alert!");
 }
 else {
   Serial.println("No Emergency ");
 }
 for (byte pin = 0; pin <= 1; pin++)
 {
   if (pin == 0)
   {
     Serial.println("In Pin =0 ");

     for (int i = 0; i < 3; i++)
     {
       digitalWrite(selectPins[i], pin & (1 << i) ? HIGH : LOW);
     }
     int inputValue = analogRead(analogInput);
     float millivolts = (inputValue / 1024.0) * 3300; //3300 is the voltage provided by NodeMCU
     float celsius = millivolts / 10;
     Serial.print("in DegreeC=   ");
     Serial.println(celsius);
     Blynk.virtualWrite(V0, celsius);
   }
   if (pin == 1)
   {
     Serial.println("In Pin =1 ");

     for (int i = 0; i < 3; i++)
     {
       digitalWrite(selectPins[i], pin & (1 << i) ? HIGH : LOW);
     }
     int inputValue = analogRead(analogInput);
     Serial.print(" Heart Rate= ");
     int BPM = random(78, 98);
     Serial.println(BPM);

     Blynk.virtualWrite(V1, BPM);
     //      delay(10000);
   }
   {
  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(V6,pox.getHeartRate() );
Blynk.virtualWrite(V7,pox.getSpO2());

       tsLastReport = millis();
       
   }
}
 }
 Serial.println();
 delay(3000);
}
void getSendData()
{
 ;
}

Read this…

Pete.

Thank you sir, It helped.