Not running code without connection to PC via USB

I have an Arduino UNO and esp8266 connected to it. Both devices has separate power lines. Each connected via USB cable, for Arduino USB used as power line and standard firmware uppload line, for esp8266 only as power suppli line. If I connect all to computer's USB ports, everything working fine. But, if I connect Arduino to separate charger that has USB port, then Arduino not running code. I can see it by Serial interface work, because code using it intensively, and when I'm turning Arduino on the RX and TX lines are down all the time, that I think indicates, that code is not running, and Arduino in boot mode, somehow.

I've made a search through same issues and nothing helped from theirs suggestions. I tried to pull RX line to GND through resistor, to make sure that there are no noise on the line, added capacitors for power supply line, to make exclude pulsations on the line. But nothing helped.

Arduino not running code independently from esp8266. I tried to run Arduino separately, without any other connections, but it not helped. Still not running.

I have the same problem with Arduino Uno and Ehternet Shield and CODE for read temp. sensor, write to LCD and write to WEB page.

With external 12V 1A power supply code not work , read WEB server not start.
LCD show value 5 minuts then stop.

I solved the problem (just a little) :

a) With external power supply 12V 1A ( low-price china product ) code not work until i press reset button.
But it does not always work. Sometimes it is necessary to repeatedly press reset button.
After 10-15 min. code stop work.

b) 5V 3A, or 9V 2A power supply (better quality9 work fine,
It is still necessary after connecting to press reset, but only once.
LCD work and WEB server work OK.

c) I try with car battery 12V , result is the same as in point b

currently more then one month i use 5V 3A power supply like this :

http://www.ebay.co.uk/itm/361421967134?_trksid=p2057872.m2749.l2649&var=630781817972&ssPageName=STRK%3AMEBIDX%3AIT

and work all OK ( of course, after connect external supply , press reset :frowning: )

I think that the USB connection made trigger signal to reset or start ehternet / wifi shield

Why is this problem will be maybe explain someone else....

A little money, a little music :slight_smile:

Are the GND/0V pins of all modules connected together?
It's generally better to feed all devices at the same rating from the same source, but as long as they are close, tying the grounds should be enough.

I can see it by Serial interface work, because code using it intensively, and when I'm turning Arduino on the RX and TX lines are down all the time,

The RX and TX LEDs are controlled by the USB port not the Arduino. When you just power an Arduino without connecting it to a computer these LEDs will not light or flash.

upj11097:
But, if I connect Arduino to separate charger that has USB port, then Arduino not running code.

What charger.
Should we guess?

svedr:
With external power supply 12V 1A ( low-price china product ) code not work until i press reset button.
But it does not always work. Sometimes it is necessary to repeatedly press reset button.
After 10-15 min. code stop work.

This typically is an overheating 5volt regulator.
Put your finger on it. It's the black thinghy between the DC socket and the ethernet socket.

12volt is too much for the regulator when it also has to supply an ethernet shield (~160mA) and LCD.
Use a REGULATED 7.5volt (minimum) supply on the DC socket.
A 9volt (maximum) supply could already be too much.
Leo..

I have same problem when connected external dc supply and work fine when I connected with usb and code running

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <HMC5883L.h>
#include <math.h>
/*
   This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const int RXPin = 0, TXPin = 1;
static const uint32_t GPSBaud = 9600;
double compass_headingDegrees;
int L1=4;
int L2=5;
int L3=6;
int L4=7;


// The TinyGPS++ object
TinyGPSPlus gps;
// the HMC5883L object
HMC5883L compass;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup()
{
  Serial.begin(115200);
  ss.begin(GPSBaud);
  pinMode(13,OUTPUT);
  pinMode(L1,OUTPUT);
   pinMode(L2,OUTPUT);
  pinMode(L3,OUTPUT);
  pinMode(L4,OUTPUT);
  // Set measurement range
  compass.setRange(HMC5883L_RANGE_1_3GA);

  // Set measurement mode
  compass.setMeasurementMode(HMC5883L_CONTINOUS);

  // Set data rate
  compass.setDataRate(HMC5883L_DATARATE_30HZ);

  // Set number of samples averaged
  compass.setSamples(HMC5883L_SAMPLES_8);

  // Set calibration offset. See HMC5883L_calibration.ino
  compass.setOffset(0, 0);
}

void loop()
{
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
    gps_track();
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
  }

}

void gps_track()
{
    //*******************compasss data ****************************//
   Vector norm = compass.readNormalize();

  // Calculate heading
  double heading = atan2(norm.YAxis, norm.XAxis);

  // Set declination angle on your location and fix heading
  // You can find your declination on: http://magnetic-declination.com/
  // (+) Positive or (-) for negative
  // For Bytom / Poland declination angle is 4'26E (positive)
  // Formula: (deg + (min / 60.0)) / (180 / M_PI);
  double declinationAngle = (4.0 + (26.0 / 60.0)) / (180 / M_PI);
  heading += declinationAngle;

  // Correct for heading < 0deg and heading > 360deg
  if (heading < 0)
  {
    heading += 2 * PI;
  }

  if (heading > 2 * PI)
  {
    heading -= 2 * PI;
  }

  // Convert to degrees
 compass_headingDegrees = heading * 180/M_PI; 
  if (gps.location.isValid())
  {  
    double gps_headingDeg;
    double distance_cal;
    double headingRad;
    double long1=gps.location.lng() ;
    double lat1= gps.location.lat();
    double long2=87.2345  ;
    double lat2=22.1167   ;
    double diflong;
    double diflat;
    double a;
    double c;
    double error;
    lat1=radians(lat1);
    long1=radians(long1);
    lat2=radians(lat2);
    long2=radians(long2);
     diflong=long1-long2;
    diflat=lat1-lat2;
    headingRad=atan2((sin(diflong)*cos(lat2)),((cos(lat1)*sin(lat2))-(sin(lat1)*cos(lat2)*cos(diflong))));
    gps_headingDeg=(180*headingRad)/3.14159;
    
    if(gps_headingDeg>0){
     gps_headingDeg=gps_headingDeg;
    }else{
      gps_headingDeg=gps_headingDeg+360;
    }
      
      error =(gps_headingDeg-compass_headingDegrees);
      if(error < -180){
        error=error+360;
      
      }
      if(error>180){
        error =error-360;
     
     
    }
    
    //*******distance calculation
    a=(sin(diflat/2)*sin(diflat/2))+(cos(lat1)*cos(lat2)*(sin(diflong/2)*sin(diflong/2)));
    c=2*atan2(sqrt(a),sqrt(1-a));
    distance_cal=c*6371000.0;// gives in meters
    //////////****************************error calculation
      Serial.print("gps heading");
      Serial.println(gps_headingDeg);
      Serial.print("magnetic heading");
      Serial.println(compass_headingDegrees);
          Serial.print("error");
      Serial.println(error);
        Serial.print("distance");
      Serial.println(distance_cal);
        bool condition=((compass_headingDegrees-10)<gps_headingDeg)&&((compass_headingDegrees+10)>gps_headingDeg);
        if(condition){
         
          fwr();
        }else{
          if(error>10){
            rgt();
          }
          if(error<-10){
            left();
          }
        }
  }
}
void fwr()
{
  digitalWrite(L1,HIGH);
  digitalWrite(L2,LOW);
  digitalWrite(L3,HIGH);
  digitalWrite(L4,LOW);
}
void left(){
   digitalWrite(L1,LOW);
  digitalWrite(L2,HIGH);
  digitalWrite(L3,HIGH);
  digitalWrite(L4,LOW);
}
void rgt(){
   digitalWrite(L1,HIGH);
  digitalWrite(L2,LOW);
  digitalWrite(L3,LOW);
  digitalWrite(L4,HIGH);
}

I have same problem when connected external dc supply and work fine when I connected with usb and code running

That is NOTHING to do with the code. Code is not sensitive to the source of power.

Wawa:
What charger.
Should we guess?
This typically is an overheating 5volt regulator.
Put your finger on it. It's the black thinghy between the DC socket and the ethernet socket.

12volt is too much for the regulator when it also has to supply an ethernet shield (~160mA) and LCD.
Use a REGULATED 7.5volt (minimum) supply on the DC socket.
A 9volt (maximum) supply could already be too much.
Leo..

In my case it works without any problems, with external supply 5V 3A. 5 x DS18b20 sensors and 2x LCD 20*4 and web server.