Arduino mega2560/ESP8266 only runs with usb (data-)connection

My Sketch with Blynk works very good – but only with connected USB Cable to my PC.
I checked the power supply with external input (9 V) as well as the power supply via USB connector (without data-lines). 5 Volt are always stable present.

I think the Arduino is waiting for a connection with my PC. If I comment this line
„Blynk.begin (auth, wifi,ssid, pass, “192.168.178.52”);“
out, the Arduino is working (Test-LED is blinking) even with external power supply but of course without the WIFI-connection….

Meanwhile I tested the program on two Arduinos Mega always with the same problem: The program runs only with connection to the USB-interface of my PC.
Therefore I‘m sure that this is not a hardware or a 5V power Supply problem .

Can anyone please give me some advice how I get my project running with external power supply?
Thank you very much!!

Hi,

Can you paste your code and debug here.

Thank you for your Reply. Here is my Sketch:

/*************************************************************

/* Comment this out to disable prints and save space */

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>


char auth[] = "XXXX";


char ssid[] = "XXX";
char pass[] = "XXXX";



// Hardware Serial on Mega, Leonardo, Micro...

#define EspSerial Serial1 


// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX


// Your ESP8266 baud rate:
#define ESP8266_BAUD 19200

ESP8266 wifi(&EspSerial);

BlynkTimer timer;                   //Create a Timer  objekt calles "timer"

void setup()

{

  // Debug console

  Serial.begin(9600);

  analogReference (INTERNAL1V1);   // Referenz-Signal für Analog-Eingänge ist 1,1 Volt

  delay(10);

    pinMode(13, OUTPUT);

  // Set ESP8266 baud rate

  EspSerial.begin(ESP8266_BAUD);

  delay(10);



  Blynk.begin(auth, wifi,ssid, pass, "192.168.178.52");

   timer.setInterval(2000L, myTimerEvent);

}

 void myTimerEvent()
 {
           // You can send any value at any time.
           // Please don't send more that 10 values per second.
  int sensorValue = analogRead(A13);
  float volt = (sensorValue/1024.0) * 98;   //ursprünglich *330 wegen 0-1 V Sensoroutput auf 0-3,3 V Eingang von ESP8266

        volt = volt + 0.05;                   // damit er "richtig" rundet, bei 1 nachkommastellen 0.05 usw.
        volt = (int)(volt*10);                // hier wird der float *10 gerechnet und auf int gecastet, so fallen alle weiteren Nachkommastellen weg
        volt = volt /10;                      // und hier wieder durch 10 dann haste 1 Nachkommastellen

      //  Serial.println (sensorValue);
      //  Blynk.virtualWrite (A14,sensorValue);                            
   Blynk.virtualWrite(V0, volt);
 }  

void loop()

{
 Blynk.run();
 timer.run();
      digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)  
      delay(1000);              // wait for a second  
      digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW  
      delay(1000);              // wait for a second  

}

That’s it.Every thing works fine, exept the necessary connection to my PC. Again thank you for any advice.

Can you paste the result of serial monitor when you use your ESP.
You use an ESP-01 ? The speed of your EspSerial is 19200 but is the same with your ESP ?

Why do you have add IP here ? You use local server ?

Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

I think you can use timer rather than delay function.

Hi Aklain,
yes, I use an ESP-01. The Arduino Mega and the ESP are connected with 19200 baud.
And yes, I’m using a local Rasberry-Server.
Here is the result of the Serial Monitor:

   ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.0 on Arduino Mega

[604] Connecting to Area 1
[3720] AT version:1.3.0.0(Jul 14 2016 18:54:01)
SDK version:2.0.0(5a875ba)
Farylink Technology Co., Ltd. v1.0.0.2
May 11 2017 22:23:58
OK
[4811] Failed to enable MUX
[7921] +CIFSR:STAIP,"192.168.178.65"
+CIFSR:STAMAC,"b4:e6:2d:1b:90:bb"
[7930] Connected to WiFi
[18115] Ready (ping: 19ms).

After that my Arduino with ESP is online and I can see the “Temperature” on my iPhone.

Best regards and thank you for your time.

Ok work fine. How is connect your ESP to your MEGA ?

The connection is via RX1/TX1 and I have a level converter from 5 to 3,3V.

I just tested it again with external power. The L-LED is blinking twice (=same with USB-Connection) but nothing else happens…
With USB-Connection I can see the flashing of the TX-LED of the USB-Interface immediately after Reset and the flashing of the blue LED on the ESP (=Serial connection with the Mega).It has something todo with the line:
Blynk.begin (auth, wifi,ssid, pass, “192.168.178.52”); Without this line the Arduino is starting up and working…

One of the issues with a Arduino/ESP connection is powering the ESP… even at only 3.3v, it draws more current when in WiFi mode then the Arduinos built in 3.3v regulator can usually handle.

It is possible it is just barely hanging on when drawing from the PC’s USB power, but then when running on your external 9v (particularly if you are actually using a rectangular 9v battery - they are VERY low current) then you are simply running out of current for the ESP and this is causing brownouts and disconnection.

Thank you for your advice. The ESP is not connected to the 3,3V output of the Mega but to the 5V output.
To exclude this power supply influence I tested my Arduino/ESP with an USB Cable and a strong 5V/2A Adapter
at the USB-Interface. Even with an osziloscop I don’t see critical Drops in the Supply voltage.
Meanwhile I did another testing and it is confirmed that the Arduino starts the sketch even with external power Supply and is connected to my WiFi Network but it never comes back from
Blynk.begin (auth, wifi,ssid, pass, “192.168.178.52”); .
Best regards.

Well, if the only difference is the power source, then the power source IS the issue.

Otherwise there is no way that the WiFi enabled connection can differentiate (nor really care) whether it is tethered to USB or not.

PS having delays in the void loop() with Blynk is not good coding practice.

Hi Gunner, hi Aklain,
I think I found the Problem - a tricky on …
The only difference between supply over USB and supply over external devices was the voltage!
USB deliveres for the circuites 4,6 Volt, external supply deliveres nearly 5 Volts.
And with the 5 Volts the ESP doesn’t want to run, although I use a 3.3 V voltage regulator for the component.
I tested it with an adjustable voltage regulator on the Vin pin of the Arduino. Maximum input voltage is 4.7 Volt.

I think one reason could be the voltage divider on the RX- Channel of the ESP. Something more to explore…

Thank you all for your advice.
Best regards.

ESP-01 is not 5v torelrant. You need adapt to 3.3v.

Yes, I know. Therefore I use the 3.3V voltage regulator. For the RX-Input I use a voltage divider based on 2 resistors. The voltage

The voltage at this input of the ESP was still a bit to high, I optimized the resistor values and now the system works even with external supply.
Again thanks a lot!

Stop buying these nasty things.