Arduino don't start

Hi everyone, I ask you a question about a simple project that I am realizing … Why when I boot up, if I do not connect the LAN cable to the ethernet shield, since I do not get the IP addresses, the sketch does not start up when do I not connect the LAN? How can I solve it without distorting everything?
thanks for the answers in advance
Here is the sketch I use:

#define BLYNK_PRINT Serial

#include <Blynk.h>

#include <FastIO.h>
#include <I2CIO.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal_SR2W.h>
#include <LiquidCrystal_SR3W.h>
#include <Wire.h>
#include <DHT.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define W5100_CS  10
#define SDCARD_CS 4
char auth[] = "...";
IPAddress server_ip (.,.,.,.);




#define DHTPIN 2          // What digital pin we're connected to
#define DHTPIN1 3          // What digital pin we're connected to
#define ONE_WIRE_BUS 7
#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
#define deum 8
#define vlv 9

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DHT dht(DHTPIN, DHTTYPE);
DHT dht1(DHTPIN1, DHTTYPE);
BlynkTimer timer;
WidgetLED LEDdeum(V3);
WidgetLED LEDvlv(V4);
int virtualbutton;
byte range = 3;
int val = 0;
float h, t, h1, t1, td, td1, s1;
String deu, valve;
byte ultimo_pulsante;
byte page = 0;
byte freccia_su[8] = {
  B00000,
  B00000,
  B00100,
  B01110,
  B11111,
  B00000,
  B00000,
  B00000,
};
byte freccia_giu[8] = {
  B00000,
  B00000,
  B00000,
  B11111,
  B01110,
  B00100,
  B00000,
  B00000,
};
byte grado[8] = {
  B00010,
  B00101,
  B00010,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
};


LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

BLYNK_WRITE(V1) {
  val = param.asInt(); // assigning incoming value from pin V1 to a variable
  range = range + val;
  Serial.println("pulsante remoto");
}

BLYNK_WRITE(V2) {
  virtualbutton = param.asInt();
  Serial.println("Interruttore remoto");
  Serial.print("virtual= ");
  Serial.print(virtualbutton);
}

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V0, range);
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
  Blynk.virtualWrite(V7, h1);
  Blynk.virtualWrite(V8, t1);
  Blynk.virtualWrite(V9, s1);
  Blynk.virtualWrite(V10, td);
  Blynk.virtualWrite(V11, td1);
}

void setup() {
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  //timer.setInterval(myEthernetTimeout, myfunction);
  //timer.setInterval(blynkInterval, checkBlynk);   // check connection to server per
  lcd.begin(20, 4);
  lcd.clear();
  lcd.createChar(1, freccia_su);
  lcd.createChar(2, freccia_giu);
  lcd.createChar(3, grado);
  lcd.setCursor(0, 0);
  lcd.print("CONTROLLO          ");
  lcd.setCursor(0, 1);
  lcd.print("DEUMIDIFICAZIONE");
  lcd.setCursor(0, 2);
  lcd.print("Premere ENTER      ");
  lcd.setCursor(0, 3);
  lcd.print("per accedere ai menu");
  page = 0;
  Serial.begin(9600);
  pinMode(deum, OUTPUT);
  pinMode(vlv, OUTPUT);
  //Ethernet.begin();

  Blynk.begin(auth, server_ip, 8442);
  // You can also specify server:
  //Blynk.begin(auth, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, IPAddress(server_ip), 8442);
  dht.begin();
  sensors.begin();
  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
  digitalWrite (deum, HIGH);
  digitalWrite (vlv, LOW);

}

void loop() {
  Serial.println("Inizia");
  sensori();
  Blynk.run();
  timer.run();
  onoff();
  lettura_pulsanti();
  richiama_update();
  if ((page == 4) || (page == 5) || (page == 6) || (page == 7) || (page == 8) || (page == 4)) {
    Serial.println("OK");
    Serial.println("OKK");
    updateLcd();
  }
}

Blynk.begin() is a blocking routine. Search for recent W5100 threads for a fix.

I tried to change the sketch in various ways. What I got is that the sketch is anceh without LAN, but after 25 seconds, when the checkBlynk function is called up, it locks everything up to Blynk.connect (), and no more starts if I do not connect the cable …
Give me some extra help, please? Thank you

void checkBlynk() {
unsigned long startConnecting = millis();
  while (!Blynk.connected()) {
    Serial.println("dddd");
    Blynk.connect();
    Serial.println("aaaaaaa");
    if (millis() > startConnecting + myEthernetTimeout) {
      Serial.print("\tUnable to connect to server. ");
      break;
    }
  }
  Serial.println("Checking again in 25s.");
}



void setup() {
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  //timer.setInterval(myEthernetTimeout, myfunction);
  //timer.setInterval(blynkInterval, checkBlynk);   // check connection to server per
  lcd.begin(20, 4);
  lcd.clear();
  lcd.createChar(1, freccia_su);
  lcd.createChar(2, freccia_giu);
  lcd.createChar(3, grado);
  lcd.setCursor(0, 0);
  lcd.print("CONTROLLO          ");
  lcd.setCursor(0, 1);
  lcd.print("DEUMIDIFICAZIONE");
  lcd.setCursor(0, 2);
  lcd.print("Premere ENTER      ");
  lcd.setCursor(0, 3);
  lcd.print("per accedere ai menu");
  page = 0;
  Serial.begin(9600);
  pinMode(deum, OUTPUT);
  pinMode(vlv, OUTPUT);
  //Ethernet.begin();
  Serial.println("Z");
  timer.setInterval(blynkInterval, checkBlynk);
  Serial.println("Z0");
  Blynk.config(auth, server_ip);
  
  Serial.println("Z1");
  
    Serial.println("Z3");
    // You can also specify server:
    //Blynk.begin(auth, "blynk-cloud.com", 8442);
    //Blynk.begin(auth, IPAddress(server_ip), 8442);
    dht.begin();
    sensors.begin();
    // Setup a function to be called every second
    timer.setInterval(1000L, sendSensor);
    digitalWrite (deum, HIGH);
    digitalWrite (vlv, LOW);

  
}








  void loop() {
    Serial.println("Inizia");
    sensori();
    if (Blynk.connected()) {
      Serial.println("y");
      Blynk.run();
    }
    timer.run();
    onoff();
    lettura_pulsanti();
    richiama_update();
    if ((page == 4) || (page == 5) || (page == 6) || (page == 7) || (page == 8) || (page == 4)) {
      Serial.println("OK");
      Serial.println("OKK");
      updateLcd();
    }

    if (ultimo_pulsante == 0) {
      Serial.println("OK");

      Serial.println(res);
      if (millis() - res > 30000) {
        res = millis();
        page = 11;
        displayMenu();
        lcd.noDisplay();
        cont = 1;
      }
    }
    if (cont == 1) {
      if (ultimo_pulsante != 0) {
        page = 0;
        displayMenu();
        lcd.display();
        cont = 0;

      }
    }
  }

When you ditch Blynk.begin() you have got to set all your Ethernet details (local IP, gateway etc).
Look for sketches that contains full Ethernet configuration, I believe they are covered in the recent W5100 threads.

Thanks for the answers … but forgive me … I can not understand …

Do you know what IP, gateway and DNS are and how to set them up in your sketch?

Is there a line in your code like this:
Blynk.config()
Blynk.config(auth, server, port);

I am not a big Ethernet user but I don’t think that will work if the OP hasn’t defined “the network” for the Arduino.

@Mic_Putignano the recent “W5100” thread I was referring to can be found at Brown outs or reboots - #60 by Costas

It’s probably worth you reading through the whole thread so you get some understanding of how the final sketch was arrived at. You will see in the sketch all the network definitions (MAC, IP, Gateway, DNS, Subnet etc). Obviously you will have to modify the definitions for your particular network.

The problem is that I know IP, DNS, etc. to which I’m connected, but then I have to give the whole box that runs the program to a friend. I do not know when it will connect to its plant, what its IP, DNS etc will be.

Don’t you think you should have mentioned this in the first post?

Have you thought seriously about a proper IOT system i.e. an ESP. You can add additional analog and digital ports to the ESP if you need them and update the project over the internet etc.

If you insist on going the Arduino route you will have to build a Blynk project that requests the network settings from your friend. Take or send the Arduino and a 3G pocket router ($7) to your friend. He starts with the 3G network and then enters his network details in Blynk etc.

Happy coding.

1 Like