WeMos D1 would't connect when use A0

I’m using a WeMos D1, all works fine until I perform an analogRead(A0), at this point Blynk disconnect.
Obviusoly in the Blnynk project I don’t use A0 directly but only via virtual pin.

This code got me a continuolsy reconnection…

void loop() { 
  Blynk.run();
  int sensorValue = analogRead(ELECTRICITY_SENSOR);
  if (sensorValue > sensorMax) sensorMax = sensorValue;
  if((millis() - start_time) > 1000) { 
  if (sensorMax >= offset) sensorMax = sensorMax - offset;
//  Serial.print(sensorMax);
//  Serial.print("\t\t");
  amplitude_current=(float)sensorMax/1023*3.3/200*1000000;
  effective_value=amplitude_current/1.414;
  power = (effective_value*voltage*pFactor);
  Serial.print(amplitude_current,1);
  Serial.print(" mA\t");
  Serial.print(effective_value,1);
  Serial.print(" mA\t");
  Serial.print(power/1000,1);
  Serial.print(" W\t\t");  
  sensorMax = 0;
  start_time = millis();
}

}

BLYNK_READ(V0) {
  Blynk.virtualWrite(V0, String(power,1));
}

if, for example, I use the code below…

void loop() { 
  Blynk.run();
  int sensorValue = 0; //analogRead(ELECTRICITY_SENSOR);
  if (sensorValue > sensorMax) sensorMax = sensorValue;
  if((millis() - start_time) > 1000) { 
  if (sensorMax >= offset) sensorMax = sensorMax - offset;
//  Serial.print(sensorMax);
//  Serial.print("\t\t");
  amplitude_current=(float)sensorMax/1023*3.3/200*1000000;
  effective_value=amplitude_current/1.414;
  power = (effective_value*voltage*pFactor);
  Serial.print(amplitude_current,1);
  Serial.print(" mA\t");
  Serial.print(effective_value,1);
  Serial.print(" mA\t");
  Serial.print(power/1000,1);
  Serial.print(" W\t\t");  
  sensorMax = 0;
  start_time = millis();
}

}

BLYNK_READ(V0) {
  Blynk.virtualWrite(V0, String(power,1));
}

No problem at all.

@naamah75 why are you not using the recommended SimpleTimer or Ticker as your faulty loop looks to be reading the analogue port at thousands of times a second?

You indicate 3.3V tolerance on the AO port. Unless you have built your own voltage divider it is 3.2V and trying 3.3V can create problems.

Okay… now I will try with your suggestions and I will report the success. :thumbsup: