Replace the USB cable with a ESP8266 module!

Hi guys, I recently got a WeMos D1 board with an integrated ESP8266 wifi module. I plan to use it on a project that requires me to have the computer display the distance between an ultrasonic sensor and an obstacle. Currently I can do that via an USB cable and use the serial monitor to see the distances, but I want to use the wifi module on-board so I don't need an USB cable stayed connected to communicate with the computer. Please help, thanks in advance!

My current code is as follows:

#define echoPin D7 // Echo Pin
#define trigPin D6 // Trigger Pin

long duration, distance; // Duration used to calculate distance

void setup()
{
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop()
{
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;

if (distance >= 200){
Serial.println(distance);
}
delay(500);
}
delay(500);
}

Please help

Sure thing. What do you need help with? Which device is going to be the server? Which is going to be the client? WiFi means wireless, but it is NOT a direct replacement for a serial cable.

Hi PaulS thanks for the message! I want to be able to see the distance measured by the ultrasonic sensor from my phone. I think in this case my PC can be the server, and the client is my phone. I am not sure about this but I think maybe have a simple website that the phone can access and see the distance?

I think in this case my PC can be the server, and the client is my phone.

And the Arduino will just sit there giggling at you?

You could have the Arduino have a WiFi shield and be a server. The phone could access the Arduino-as-server. No need for the PC to be anywhere in the picture.

I see, gonna give it a try and thanks a lot.