Sketch won't run stand alone only works right after upload

The general problem is my sketch won’t run stand alone. When I compile and upload it to the board, it starts reporting on the Blynk web app as expected. If I unplug the board from USB, plug it back in, it doesn’t start reporting to the web app. Same USB cord is being used. The only difference is I didn’t upload the sketch to it. I tried pressing reset on the board and still not reporting in.

Board is an Arduino clone - I have been compiling using LOLIN (WeMos) D1 R1. This is and ESP8622 board communicating via Wifi. The board is stamped with WeMos logo
The server is Blynk servers not local.
My mobile device is an Samsung Note 9 running latest Android build
Getting the same result using multiple mobile devices, so I don’t think it has anything to do with my mobile device.
Blynk Library version 1.1.0

Here is my code:

//River Level indicator

#define BLYNK_DEVICE_NAME "Creek Meter"
#define BLYNK_AUTH_TOKEN "**********"

// Comment this out to disable prints and save space
// #define BLYNK_PRINT Serial

// Define Physical connection to sensor

#define TRIGPIN 2   // Board pin D4
#define ECHOPIN 0   // Board pin D3

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "DTW";
char pass[] = "************";

BlynkTimer timer;

// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V2, millis() / 1000);

void sensorDataSend()
    //Initialize measurement variables
  float duration = 0;   //time between ping and receive on sensor
  float distance = 0;   //distance calculated in millimeters
  int feet = 0;
  int inches = 0;
  int remainder_inches = 0;

  // Set the trigger pin LOW for 2uS to stablized sensor
  digitalWrite(TRIGPIN, LOW);

  // Set the trigger pin HIGH for 20us to send pulse
  digitalWrite(TRIGPIN, HIGH);

  // Return the trigger pin to LOW
  digitalWrite(TRIGPIN, LOW);

  // Capture an incoming pulse
  duration = pulseIn(ECHOPIN, HIGH);

  // Determine distance in meters from duration
  // Use 343 metres per second as speed of sound
  // Divide by speed of sound by 1000 (.0343) as we result want millimeters

  distance = (duration / 2) * 0.343;
  //convert to inches
  inches = distance/25.4;
  //convert to feet
  feet = inches/12;
  //determine remainder in inches
  remainder_inches = inches-(feet*12);
  Blynk.virtualWrite(V3, inches);

void setup()
 // Debug console
  Blynk.begin(auth, ssid, pass);
  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
  timer.setInterval(1000L, sensorDataSend);

  // intialize physical pins on Arduino
  pinMode(ECHOPIN, INPUT);

void loop()

We need to see your serial monitor results

1 Like

When it is working, connected via usb after an upload, the serial monitor results are a number (inches) rolling down the screen one after another 1 second apart. There is some noise displayed (random characters) sometimes before the numbers start rolling. When is connected via wifi only, there are no serial monitor results, because it is stand alone wifi.

Start is missing in your output display.
What you should see is connected to wifi xxSSIDxx and connected to blynk.

1 Like

I commented it out. Thinking it wasn’t necessary, according to the comments… I put it back in.

I assume you tried to push the reset button after power on ?
If so I think your ESP8266 is corrupted :scream:

1 Like

This is showing what I already described. It works after uploading the sketch. Data starts showing up on my phone as well. When I unplug the USB and reconnect it, without upload. No data. Yes. I pressed the reset button

Trying a recompile with different board types as a Hail Mary. So far nothing…

Tried running just the serial monitor after unplugging and plugging in usb. Nothing. If I push the reset, I get garbage characters in the serial monitor but then nothing.

I have tried different USB cables, but that is grasping at straws. I am going to try an external power supply next…

@garlydog when you post serial monitor output, please copy and paste the text and post it between triple backticks, rather than posting screeenshots.

These pins a a bad choice which an ESP8266. What happens if you disconnect the ultrasonic sensor and try again?

If you want to understand more about ESP8266 pins you should read this…


1 Like

Once again. Thank you. Removing the sensor and it starts reporting with data = 0. Which is correct. I will adjust the script per your ESP8266 GPIO pins info. And report back. But I think you identified the issue. Thank you.


It’s quite normal because at start Esp8266 start at 74880 bauds, change serial begin to 74880 and the output speed and you will see boot up

1 Like

Here is another link to help map GPIO ports to physical ports on the boards.

I adjusted the code as follows:

// Define Physical connection to sensor

#define TRIGPIN 5   // Board pin D1
#define ECHOPIN 4   // Board pin D2

Works properly now. Thanks again.