newPing() library disconnect wifi !

Hi All,
I'm using arduino uno with ESP01 wifi module to send current and ultrasonic sensors to cloud.

Wifi configured and working fine and data sent successfully to cloud, BUT when i add the part if ultrasonic using newPing library and once upload code to arduino , i got time out when i ping the IP! and if i comment this part of code , everything eorks fine.

I am only guessing, but suspect there could be something in that part of the code that is making it not work.

Wonder what it looks like?

Thanks for reply .

The function of ultrasonic is only use sonar() function and get the distance and return it.

I will copy code..

this is the part of ultrasonic

double measureLevel(double dim1 , double dim2 , String shape,double totalvolume){

unsigned int uS =; // Send ping, get ping time in microseconds (uS).
double distance = (uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
double levelvol = distance *dim1*dim2;
return levelvol;

hence ,
when i comment the line of and replace it with constant figure Wifi works fine .

Does Ping work without Wifi?

Yes, if i discarded the Wifi and print the value out of ping() it works .

also i tried again without using newPing library , i used the following example but also once it loaded to arduino , ping to IP return with time out response while the example itself works fine.

const int trigPin = 12;
const int echoPin = 11;

void setup() {
  // initialize serial communication:

void loop()
  // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);

  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  Serial.print("in, ");

long microsecondsToInches(long microseconds)
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See:
  return microseconds / 74 / 2;

long microsecondsToCentimeters(long microseconds)
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;

How are these components powered? ESP can draw a lot transmitting.

Given they are separate components, the only thing in common seems to be power.

Maybe the entire failing code along with a wiring diagram would help.

Ok , complete code is attached .

and regarding to power wiring diagram as it’s related to power consumption as you suggest

Esp Vcc → 3.3V
ESP EN → 10K resistor → 3.3v

Ultrasonic Vcc → 5V

i just mentioned the power wiring because the complete wiring is combination of CT , Wifi and Ultrasonic and it may be confusing .

calc_Current_Power.ino (6.95 KB)

Thanks , Issue Solved .

i found out the cause of the problem , the reason of wifi disconnect is that the EN pin should be HIGH 3.3v always but in my case once Arduino communicate with Ultrasonic sensor the Power of EN goes 0v .

so i removed the resistor between 3.3v and EN pin and it works fine