Blynk app disconnecting

Hi I have a problem.
My blynk app disconnects with esp32 or refuses to connect. I supply power to esp32 and other things and when esp32 works on this supply it does not connect. But if I disconnect vin from esp32 and supply power only to it via micro usb cable, it works. Then I connect it to the normal power supply and it’s still connected to micro usb and it works. When I remove micro usb it works for 10 mins and then stops working (disconnects) (led on it still shines).
Here’s code:

float MaxTemp = 0;
int MaxMoist = 0;
int MinMoist = 0;
int x = 0;
float temperatureIN = 0;
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591);
#define pump 26
int ElFan = 12;
int PlFan = 32;
int soilMoisture = 0;
int soilMoistureSensor = 34;
int gBright = 0;
int rBright = 213;
int bBright = 42;
#include <analogWrite.h>
#define RED_LED 14
#define BLUE_LED 19
#define GREEN_LED 27
#define BLYNK_PRINT Serial  
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char ssid[] = "****";
char pass[] = "-----;
char auth[] = "pass"; 
BlynkTimer timer;
boolean stateled=0;
boolean prevStateled=0;
 #define BLYNK_MSG_LIMIT 20
#include <OneWire.h>
#include <DallasTemperature.h>
float tempC = 0;

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 15

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Addresses of 3 DS18B20s
uint8_t sensor1[8] = { 0x28, 0xFF, 0xCD, 0xAC, 0x02, 0x19, 0x8A, 0xDE };
uint8_t sensor2[8] = { 0x28, 0xFF, 0xED, 0xAD, 0x02, 0x19, 0x8A, 0xA9 };
void printTemperature(DeviceAddress deviceAdress){
 
}
BLYNK_READ(V2) {

 Blynk.virtualWrite(2,analogRead(soilMoistureSensor)/37);
  
}
BLYNK_READ(V1) {

 Blynk.virtualWrite(1,tsl.getLuminosity(TSL2591_VISIBLE));
  
}
BLYNK_READ(V3) {
  float tempC = sensors.getTempC(sensor1 );
  Blynk.virtualWrite(3, tempC);
}
BLYNK_WRITE(V4)
{
  MinMoist = param.asInt(); 
  if ( analogRead(soilMoistureSensor)/37< MinMoist){
    digitalWrite(pump,HIGH);
  }
  
}
BLYNK_WRITE(V7) {
  MaxMoist = param.asInt(); 
  if(analogRead(soilMoistureSensor)/37 > MaxMoist) {
    digitalWrite(pump,LOW);
  }
}
BLYNK_WRITE(V8) {
  MaxTemp = param.asInt();
  if(sensors.getTempC(sensor1 ) > MaxTemp){
    digitalWrite(PlFan,HIGH);
    
  }
  else {
    digitalWrite(PlFan, LOW);
  }
}
void simpleRead(void)
{
  // Simple data read example. Just read the infrared, fullspecrtrum diode 
  // or 'visible' (difference between the two) channels.
  // This can take 100-600 milliseconds! Uncomment whichever of the following you want to read
  uint16_t x = tsl.getLuminosity(TSL2591_VISIBLE);
  //uint16_t x = tsl.getLuminosity(TSL2591_FULLSPECTRUM);
  //uint16_t x = tsl.getLuminosity(TSL2591_INFRARED);

  Serial.print(F("[ ")); Serial.print(millis()); Serial.print(F(" ms ] "));
  Serial.print(F("Luminosity: "));
  Serial.println(x, DEC);
}
void setup(void)
{
  pinMode(PlFan, OUTPUT);
  configureSensor();
  pinMode(ElFan, OUTPUT);
  sensors.begin();
  pinMode(soilMoistureSensor, INPUT_PULLUP);
  pinMode(pump, OUTPUT);
  // Debug console
  Serial.begin(115200);
  pinMode(13,OUTPUT); // NODEMCU PIN D7
  Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  timer.setInterval(300L, checkledstate);
 //  attachInterrupt(digitalPinToInterrupt(13), notifyOnled, CHANGE);
}

BLYNK_WRITE(V6)
{
    if (param.asInt()){       
   analogWrite(GREEN_LED, gBright);
  analogWrite(RED_LED, rBright);
  analogWrite(BLUE_LED, bBright); 
   Blynk.virtualWrite(V13,1);
    } else {
      analogWrite(GREEN_LED,0);
  analogWrite(RED_LED, 0);
  analogWrite(BLUE_LED, 0);  
  Blynk.virtualWrite(V13,0);
    }
}



void loop(){
simpleRead();
 ElWent();
   sensors.requestTemperatures();
  if (Blynk.connected())
  {
    Blynk.run();
  }
   timer.run();  
}

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V6);
  
}
void checkledstate()
{
  
  stateled=digitalRead(13);
  if (stateled!=prevStateled)
  {
    if (stateled==0) Blynk.virtualWrite(V13,0); 
    if (stateled==1) Blynk.virtualWrite(V13,255); 
  }
  prevStateled=stateled;
}
void ElWent (){
  if(temperatureIN >= 35) {
    digitalWrite(ElFan, HIGH);
  }
  else{
    digitalWrite(ElFan, LOW);
  }
}void configureSensor(void)
{
  // You can change the gain on the fly, to adapt to brighter/dimmer light situations
  //tsl.setGain(TSL2591_GAIN_LOW);    // 1x gain (bright light)
  tsl.setGain(TSL2591_GAIN_MED);      // 25x gain
  //tsl.setGain(TSL2591_GAIN_HIGH);   // 428x gain
  
  // Changing the integration time gives you a longer time over which to sense light
  // longer timelines are slower, but are good in very low light situtations!
  //tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS);  // shortest integration time (bright light)
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
  tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS);  // longest integration time (dim light)

  /* Display the gain and integration time for reference sake */  
  Serial.println(F("------------------------------------"));
  Serial.print  (F("Gain:         "));
  tsl2591Gain_t gain = tsl.getGain();
  switch(gain)
  {
    case TSL2591_GAIN_LOW:
      Serial.println(F("1x (Low)"));
      break;
    case TSL2591_GAIN_MED:
      Serial.println(F("25x (Medium)"));
      break;
    case TSL2591_GAIN_HIGH:
      Serial.println(F("428x (High)"));
      break;
    case TSL2591_GAIN_MAX:
      Serial.println(F("9876x (Max)"));
      break;
  }
  Serial.print  (F("Timing:       "));
  Serial.print((tsl.getTiming() + 1) * 100, DEC); 
  Serial.println(F(" ms"));
  Serial.println(F("------------------------------------"));
  Serial.println(F(""));
}

please help
Maciek

Can lack of power cause it?
Even if it’s 2 amps and 3 sensors work at the time.

Are you supplying 5v to the VIN pin?

If so then a 47uF tantalum capacitor between GND and VIN can often help.

Pete.

Yes. 5V. But between the VIN and GND comind to esp32 right?

And from vin to gnd or from gnd to vin which side?

I don’t understand either of these two questions.

Pete.

Sorry


Like this?

and is 10 Uf ok because I don’t have 47 uF

and it’s an Electrolytic (polarised) capacitor, not Tantalum.

Pete.

Ohh I gotta buy one :frowning: .

Thanks Pete

is 47uF 35V 5.08mm tantalum capacitor ok?

can the voltage be higher?

That will be fine. The voltage is the highest voltage that should be applied to it.
The only issue with higher voltage ones is that they tend to be physically larger.
When you mount the capacitor it needs to be as close to the ESP32’s pins as possible, with leads as short as practical.

Pete.

And which leg should come to VIN and which to GND? Like this?

Yes.

Pete.

I did it like this @PeteKnight and it does not work :frowning:

What happens if you run a simple Blynk sketch (one of the ones from the shetch builder) instead of yours - which has a rather cluttered void loop?

Do you still get disconnections then, when powered via the Vin pin?

If so then maybe you have a power supply problems that the capacitor isn’t able to smooth out - in which case I’d expect you to see some brownout messages from the board in the serial monitor. Obviously you don’t have a serial monitor connected when powering the board via the Vin pin, but there might be ways around this using a USB cable that has been doctored to only have the data (and maybe GND) wires attached, or using an FTDI adapter.

Pete.

I uploaded a simple blynk sketch and it works.

But how do I clean my void loop()
?