Arduino nano doesnt work without serial monitor on

Hey guys,

I got a problem with my Arduino nano(orginal).
When i run the code below with Serial monitor on, it works fine.
But when i close the arduino software on my pc/laptop, and reset the Nano, it issnt working properly.
The keyboard and LCD dislay works. Only the ethernet shield can not connect to the server. The nano is pingable, but he can not send the relevant json.

I tested several power kabels and computers. No luck at all…

If you know something help me please;)

Code:

#include <Keypad.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include "EtherCard.h"

#define I2C_ADDR        0x3F //<<----- Add your address here.  Find it with the I2C Scanner sketchup!
#define BACKLIGHT_PIN   3 //default, dont change
#define BUZZER          14 //buzzer pin

static byte mymac[] = {0x00,0x00,0xAA,0xBB,0x00,0x07};//00:00:AA:BB:00:07 

const static uint8_t ip[] = {10,0,0,107};
const static uint8_t gw[] = {10,0,0,1};
const static uint8_t dns[] = {10,0,0,98};

byte Ethernet::buffer[400];
static uint32_t timer;

const char serverIp[] PROGMEM = "10.0.0.98";
const char backupServerIp[] PROGMEM = "10.0.0.99";
const int serverPoort = 8080;

String dataInput = "";

boolean lockSystem = false;
const int freq = 880;

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
byte rowPins[ROWS] = {5, 6, 7, 8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4};  //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal_I2C  lcd(I2C_ADDR,2,1,0,4,5,6,7);

String FileNr = "";
String StartMsg1 = "Enter a file";
String StartMsg2 = "number.";

// Called when the client request is complete
static void brw_cb (byte status, word off, word len) {
 Ethernet::buffer[off+300] = 0;
 Serial.print((const char*) Ethernet::buffer + off);
 Serial.println("...");
}

void setup(){
  Serial.begin(9600);
  lcd.begin (16,2); 
   
  pinMode(BUZZER, OUTPUT);

  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println(F("Failed to access Ethernet controller"));

  ether.staticSetup(ip, gw, dns);
  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  

  if (!ether.dnsLookup(serverIp))
    Serial.println("DNS failed");
  ether.hisport  =  serverPoort;
  ether.printIp("SRV: ", ether.hisip);
  
  // Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  
  lcd.home (); // go home
  lcd.print(StartMsg1); 
  lcd.setCursor (0,1);
  lcd.print(StartMsg2);
}

void loop(){
  ether.packetLoop(ether.packetReceive());
  char key = keypad.getKey();
  if (key != NO_KEY){
    FileNr += key;
    if(FileNr.length() == 3){    
      NumberScene();
      FileChecker();
    } 
  }  
}

void FileChecker(){
  lcd.clear(); 
  switch(FileNr.toInt()){
    case 136:
      makeBeep(3, freq);
      lcd.print("File found.");
      sendJson("10");
      resetsystem();
    break;
    case 278:
      makeBeep(3, freq);
      lcd.print("File found.");
      sendJson("20");
      resetsystem();
    break;
    case 245:
      makeBeep(3, freq);
      lcd.print("File found.");
      sendJson("30");
      resetsystem();
    break;
    default:
      makeBeep(1, freq);     
      lcd.print("File not found.");  
      lcd.setCursor (0,1);   
      lcd.print("Enter a number");
    break;    
    }
    FileNr="";
}

void NumberScene(){
  lcd.clear();
  lcd.print("Entered numbers: ");
  lcd.setCursor (0,1); 
  lcd.print(FileNr);
  
  delay(2500);
  lcd.clear();
  lcd.print("Checking System.");
  lcd.setCursor (0,1); 
  for(int i = 0; i < 10; i++){
      lcd.print(".");
      delay(500);
  } 
}

void makeBeep(int howlongSeconds, int freq) {
  tone(BUZZER, freq, howlongSeconds * 1000);
}

void sendJson(String lvl){  
  Serial.println("<<< SENDING DATA");
  char charBuf[100];
  lvl.toCharArray(charBuf, 100);
  if(lvl == "10"){
    ether.browseUrl(PSTR("/json.htm?type=command&param=switchlight&idx=14&switchcmd=Set%20Level&level="), charBuf, serverIp, brw_cb);
  }else if(lvl == "20"){
    ether.browseUrl(PSTR("/json.htm?type=command&param=switchlight&idx=14&switchcmd=Set%20Level&level="), charBuf, serverIp, brw_cb);
  }else if(lvl == "30"){
    ether.browseUrl(PSTR("/json.htm?type=command&param=switchlight&idx=14&switchcmd=Set%20Level&level="), charBuf, serverIp, brw_cb);
  }
}

void resetsystem(){
  String resetnr= "";
  while (true){
    char key = keypad.getKey();
    if (key != NO_KEY){
      resetnr += key;
      if(resetnr == "#972902"){
        lcd.clear();
        lcd.print("RESETTING..."); 
        delay(5000);
        break;
      }else if(resetnr.length() > 8){
        lcd.clear();
        lcd.print("Try again.");
        resetnr = "";
      } 
    }    
  }
}

How are you powering your project when it’s off the USB cable?

Yeah for now it is. I also tryed it on the vin port. But no luck at all.

pasibun: Yeah for now it is. I also tryed it on the vin port. But no luck at all.

Now it is what ?

Not a 9V PP3 battery by any chance ?

well, now i just use a power mini usb to my laptop. Just for testing.

What I forget what to say is that the keyboard and LCD dislay works. Only the ethernet shield can not connect to the server. The nano is pingable, but he can not send the relevant json.

pasibon, i’m guessing English isn’t your first language. You may get better answers if you explain the problem you’re facing in your most proficient language - in the forum section for ‘that’ language.

So far, there have been a couple of suggestions which you ignored. You may have more luck expressing the elements of your project over there.