Error on input Blynk.begin (auth)

Hello everyone, I have a problem with my project.

The program stops working completely when I put Blynk.begin (auth); on the void setup.

I’m new to the platform and I have this problem, could someone help me please?


///////////////////////////////////////////////////////////////////////////////////////////////////////
#include <Keypad.h> //Libraries needed
#include <Wire.h>
#include <virtuabotixRTC.h>
#include <LiquidCrystal_I2C.h>
#include <SerialRelay.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SerialRelay.h>
#include <SimpleTimer.h>

///////////////////////////////////////////////////////////////////////////////////////////////////////

#define DHTPIN 52 // Define em que pino está conectado o módulo DHT
#define DHTTYPE DHT22 // Define se o módulo conectado é o DHT11 ou DHT22
#define    ONE_WIRE_BUS     53
#define BLYNK_PRINT Serial


///////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////

OneWire oneWire(ONE_WIRE_BUS);        //objeto one_wire
DallasTemperature sensors(&oneWire);
DeviceAddress sensor1;
DHT dht(DHTPIN, DHTTYPE);

///////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////

const byte NumModules = 1;
SerialRelay relays(30,31,NumModules); // (data, clock, number of modules)

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

///////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////

LiquidCrystal_I2C lcd(0x27, 20, 4);
LiquidCrystal_I2C lcd2(0x26, 16, 2);

///////////////////////////////////////////////////////////////////////////////////////////////////////

virtuabotixRTC myRTC(32, 33, 34); //Wiring of the RTC (CLK,DAT,RST)
                               //If you change the wiring change the pins here also

///////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////

const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]= 
{
{'1', '2', '3', 'A'}, 
{'4', '5', '6', 'B'}, 
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};


byte rowPins[numRows] = {22,23,24,25}; //Rows 0 to 3 //if you modify your pins you should modify this too
byte colPins[numCols]= {26,27,28,29}; //Columns 0 to 3

//////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////

int i1,i2,i3,i4;
char c1,c2,c3,c4;
char keypressed,keypressedx;

int A_hour=NULL;
int A_minute=NULL;

Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

/////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////

BlynkTimer timerDHT22; // Criação do Timer do DHT22
BlynkTimer timerDS18B20;

void lerSensorDHT22() // Função para ler os parâmetros do DHT22
{
  float temperatura = dht.readTemperature(); // Comando da biblioteca que lê a temperatura adquirida pelo DHT22
  float umidade = dht.readHumidity(); // Comando da biblioteca que lê a umidade adquirida pelo DHT22

  if (isnan(temperatura) || isnan(umidade)) { // isnan = IS Not A Number <= verifica se o valor lido não é um número
    return;
  }
  Blynk.virtualWrite(V4, temperatura); // Escreve no pino virtual V4 do Blynk o valor da temperatura lido pelo DHT22
  Blynk.virtualWrite(V5, umidade); // Escreve no pino virtual V5 do Blynk o valor de umidade lido pelo DHT22
}

void lerSensorDS18B20()
{
  float tempC = sensors.getTempCByIndex(0);
  Blynk.virtualWrite(V2, tempC); 
}

///////////////////////////////////////////////////////////////////////////////////////////////////




void setup() {
  

  Serial.begin(9600);
  lcd.begin();
  lcd2.begin();
  lcd.backlight();
  lcd2.backlight();
  dht.begin(); // Inicializa o DHT22
  Blynk.begin(auth);

  timerDHT22.setInterval(2000L, lerSensorDHT22);
  timerDS18B20.setInterval(1000L, lerSensorDS18B20);

}

void loop() {

   
  while(keypressed == NO_KEY){ //As long as no key is pressed we keep showing the date and time, I'm obliged to clear the screen everytime so the numbers don't get confused
                               //And I should add that little delay so the screen shows correctly otherwise it didn't work for me
  keypressed = myKeypad.getKey();
  lcd.clear(); //Here after clearing the LCD we take the time from the module and print it on the screen with usual LCD functions
  myRTC.updateTime();

  if(myRTC.hours==A_hour && myRTC.minutes==A_minute && myRTC.seconds >= 0 && myRTC.seconds <= 2){
    while(keypressedx == NO_KEY){
      
      relays.SetRelay(1, SERIAL_RELAY_ON, 1);

      delay(100);
    lcd.clear();
    lcd.print("Get up !!!"); //Message to show when the alarm is ringing
    keypressedx = myKeypad.getKey();
    }
  }
  
  keypressedx = NO_KEY;
  lcd.setCursor(0,0);
  lcd.print(myRTC.dayofmonth);
  lcd.print("/");
  lcd.print(myRTC.month);
  lcd.print("/");
  lcd.print(myRTC.year);
  lcd.setCursor(12,0);
  lcd.print(myRTC.hours);
  lcd.print(":");
  lcd.print(myRTC.minutes);
  lcd.print(":");
  lcd.print(myRTC.seconds);
  delay(100);

  float tempS = sensors.getTempCByIndex(0);
  lcd.setCursor (0,1);
  lcd.print("Temp Solo");
  lcd.setCursor (0,2);
  lcd.print(tempS);
  lcd.print("C");

  float temperatura = dht.readTemperature(); 
  float umidade = dht.readHumidity();
  lcd2.setCursor(0,0);
  lcd2.print("T-A:");
  lcd2.print(temperatura);
  lcd2.print("C");
  lcd2.setCursor(0,1);
  lcd2.print("U-A:");
  lcd2.print(umidade);
  lcd2.print("%");
  delay(2000);

  }


 

         if (keypressed == '*') 
             {
              lcd.clear();
              lcd.print("     Setup");
             delay(1000);
              lcd.clear();
              lcd.print("Setup year");
             char keypressed2 = myKeypad.waitForKey();  
                    if (keypressed2 != NO_KEY && keypressed2 !='*' && keypressed2 !='#' && keypressed2 !='A' && keypressed2 !='B' && keypressed2 !='C' && keypressed2 !='D' )
                      {
                       c1 = keypressed2;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                 char      keypressed3 = myKeypad.waitForKey();
                    if (keypressed3 != NO_KEY && keypressed3 !='*' && keypressed3 !='#' && keypressed3 !='A' && keypressed3 !='B' && keypressed3 !='C' && keypressed3 !='D' )
                      {
                       c2 = keypressed3;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }
                   char  keypressed4 = myKeypad.waitForKey();
                   if (keypressed4 != NO_KEY && keypressed4 !='*' && keypressed4 !='#' && keypressed4 !='A' && keypressed4 !='B' && keypressed4 !='C' && keypressed4 !='D' )
                      {
                       c3 = keypressed4;
                       lcd.setCursor(2, 1);
                       lcd.print(c3);
                       }
                   char   keypressed5 = myKeypad.waitForKey();
                   if (keypressed5 != NO_KEY && keypressed5 !='*' && keypressed5 !='#' && keypressed5 !='A' && keypressed5 !='B' && keypressed5 !='C' && keypressed5 !='D' )
                      {
                       c4 = keypressed5;
                       lcd.setCursor(3, 1);
                       lcd.print(c4);
                       }

                     i1=(c1-48)*1000;        //the keys pressed are stored into chars I convert them to int then i did some multiplication to get the code as an int of xxxx
                     i2=(c2-48)*100;
                     i3=(c3-48)*10;
                     i4=c4-48;
                     int N_year=i1+i2+i3+i4;
                   delay(500);
                     lcd.clear();
                     lcd.print("Setup month");

////////////////////////////////////////////////////////////////
                     char keypressed6 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed6 != NO_KEY && keypressed6 !='*' && keypressed6 !='#' && keypressed6 !='A' && keypressed6 !='B' && keypressed6 !='C' && keypressed6 !='D' )
                      {
                       c1 = keypressed6;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed7 = myKeypad.waitForKey();
                    if (keypressed7 != NO_KEY && keypressed7 !='*' && keypressed7 !='#' && keypressed7 !='A' && keypressed7 !='B' && keypressed7 !='C' && keypressed7 !='D' )
                      {
                       c2 = keypressed7;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                    int N_month=i1+i2;
                     delay(500);

                     lcd.clear();
                     lcd.print("Setup Day");
                     
 ////////////////////////////////////////////////////////////////                    
                      char keypressed8 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed8 != NO_KEY && keypressed8 !='*' && keypressed8 !='#' && keypressed8 !='A' && keypressed8 !='B' && keypressed8 !='C' && keypressed8 !='D' )
                      {
                        c1 = keypressed8;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                      char keypressed9 = myKeypad.waitForKey();
                    if (keypressed9 != NO_KEY && keypressed9 !='*' && keypressed9 !='#' && keypressed9 !='A' && keypressed9 !='B' && keypressed9 !='C' && keypressed9 !='D' )
                      {
                        c2 = keypressed9;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                    int N_day=i1+i2;
                    delay(500);
                     lcd.clear();
                     lcd.print("Setup hour");
////////////////////////////////////////////////////////////////////////////////////:                     
                     char keypressed10 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed10 != NO_KEY && keypressed10 !='*' && keypressed10 !='#' && keypressed10 !='A' && keypressed10 !='B' && keypressed10 !='C' && keypressed10 !='D' )
                      {
                       c1 = keypressed10;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed11 = myKeypad.waitForKey();
                    if (keypressed11 != NO_KEY && keypressed11 !='*' && keypressed11 !='#' && keypressed11 !='A' && keypressed11 !='B' && keypressed11 !='C' && keypressed11 !='D' )
                      {
                        c2 = keypressed11;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                    int N_hour=i1+i2;
                    delay(500);
                     lcd.clear();
                     lcd.print("Setup minutes");
////////////////////////////////////////////////////////////////////////////////////:
                    char keypressed12 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed12 != NO_KEY && keypressed12 !='*' && keypressed12 !='#' && keypressed12 !='A' && keypressed12 !='B' && keypressed12 !='C' && keypressed12 !='D' )
                      {
                        c1 = keypressed12;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                   char    keypressed13 = myKeypad.waitForKey();
                    if (keypressed13 != NO_KEY && keypressed13 !='*' && keypressed13 !='#' && keypressed13 !='A' && keypressed13 !='B' && keypressed13 !='C' && keypressed13 !='D' )
                      {
                        c2 = keypressed13;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                    int N_minutes=i1+i2;
                    delay(500);
                     lcd.clear();

                    myRTC.setDS1302Time(22, N_minutes, N_hour, 1, N_day, N_month, N_year); //once we're done setting the date and time we transfer to values to the RTC module
                                                                                           //the 22 stands for seconds you can add a setup for it too if you want
                                                                                           //the 1 stands for day of the week, as long I don't show it on the screen I don't change it
                    keypressed=NO_KEY; //the "*" key is stored in "keypressed" so I remove that value from it otherwise it will get me in the setup again
              }
/////////////////////////////////////////Alarme setup/////////////////////////////////
              
            if (keypressed == 'A'){
              lcd.clear();
              lcd.print("  Config Alarme 1  ");
              delay(1000);
              lcd.clear();
              lcd.print("Hora");
               
               char keypressed14 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed14 != NO_KEY && keypressed14 !='*' && keypressed14 !='#' && keypressed14 !='A' && keypressed14 !='B' && keypressed14 !='C' && keypressed14 !='D' )
                      {
                       c1 = keypressed14;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed15 = myKeypad.waitForKey();
                    if (keypressed15 != NO_KEY && keypressed15 !='*' && keypressed15 !='#' && keypressed15 !='A' && keypressed15 !='B' && keypressed15 !='C' && keypressed15 !='D' )
                      {
                        c2 = keypressed15;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                     A_hour=i1+i2;
                    delay(500);
                     lcd.clear();
                     lcd.print("Minutos");
                      char keypressed16 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed16 != NO_KEY && keypressed16 !='*' && keypressed16 !='#' && keypressed16 !='A' && keypressed16 !='B' && keypressed16 !='C' && keypressed16 !='D' )
                      {
                       c1 = keypressed16;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed17 = myKeypad.waitForKey();
                    if (keypressed17 != NO_KEY && keypressed17 !='*' && keypressed17 !='#' && keypressed17 !='A' && keypressed17 !='B' && keypressed17 !='C' && keypressed17 !='D' )
                      {
                        c2 = keypressed17;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                     A_minute=i1+i2;
                    delay(500);
                     lcd.clear();
                      
                      keypressed=NO_KEY;
             }
             if (keypressed == 'D')
             {
              lcd.clear();
              lcd.setCursor(0,0);
              lcd.print("Funcao: Alarme 1");
              lcd.setCursor(0,1);
              lcd.print("Desativada");
              relays.SetRelay(1, SERIAL_RELAY_OFF, 1);
              keypressed=NO_KEY;
              delay(500);
             }
             else {
              myRTC.updateTime();
              keypressed=NO_KEY;
             }

/////////////////////////////////////////Alarme setup/////////////////////////////////
              
            if (keypressed == 'B'){
              lcd.clear();
              lcd.print("  Config Alarme 2  ");
              delay(1000);
              lcd.clear();
              lcd.print("Hora");
               
               char keypressed14 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed14 != NO_KEY && keypressed14 !='*' && keypressed14 !='#' && keypressed14 !='A' && keypressed14 !='B' && keypressed14 !='C' && keypressed14 !='D' )
                      {
                       c1 = keypressed14;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed15 = myKeypad.waitForKey();
                    if (keypressed15 != NO_KEY && keypressed15 !='*' && keypressed15 !='#' && keypressed15 !='A' && keypressed15 !='B' && keypressed15 !='C' && keypressed15 !='D' )
                      {
                        c2 = keypressed15;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                     A_hour=i1+i2;
                    delay(500);
                     lcd.clear();
                     lcd.print("Minutos");
                      char keypressed16 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed16 != NO_KEY && keypressed16 !='*' && keypressed16 !='#' && keypressed16 !='A' && keypressed16 !='B' && keypressed16 !='C' && keypressed16 !='D' )
                      {
                       c1 = keypressed16;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed17 = myKeypad.waitForKey();
                    if (keypressed17 != NO_KEY && keypressed17 !='*' && keypressed17 !='#' && keypressed17 !='A' && keypressed17 !='B' && keypressed17 !='C' && keypressed17 !='D' )
                      {
                        c2 = keypressed17;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                     A_minute=i1+i2;
                    delay(500);
                     lcd.clear();
                      
                      keypressed=NO_KEY;
             }
             if (keypressed == 'D')
             {
              lcd.clear();
              lcd.setCursor(0,0);
              lcd.print("Funcao: Alarme 2");
              lcd.setCursor(0,1);
              lcd.print("Desativada");
              
              keypressed=NO_KEY;
              delay(500);
             }
             else {
              myRTC.updateTime();
              keypressed=NO_KEY;
             }

             /////////////////////////////////////////Alarme setup/////////////////////////////////
              
            if (keypressed == 'C'){
              lcd.clear();
              lcd.print("  Config Alarme 3  ");
              delay(1000);
              lcd.clear();
              lcd.print("Hora");
               
               char keypressed14 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed14 != NO_KEY && keypressed14 !='*' && keypressed14 !='#' && keypressed14 !='A' && keypressed14 !='B' && keypressed14 !='C' && keypressed14 !='D' )
                      {
                       c1 = keypressed14;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed15 = myKeypad.waitForKey();
                    if (keypressed15 != NO_KEY && keypressed15 !='*' && keypressed15 !='#' && keypressed15 !='A' && keypressed15 !='B' && keypressed15 !='C' && keypressed15 !='D' )
                      {
                        c2 = keypressed15;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                     A_hour=i1+i2;
                    delay(500);
                     lcd.clear();
                     lcd.print("Minutos");
                      char keypressed16 = myKeypad.waitForKey();  // here all programs are stopped until you enter the four digits then it gets compared to the code above
                    if (keypressed16 != NO_KEY && keypressed16 !='*' && keypressed16 !='#' && keypressed16 !='A' && keypressed16 !='B' && keypressed16 !='C' && keypressed16 !='D' )
                      {
                       c1 = keypressed16;
                       lcd.setCursor(0, 1);
                       lcd.print(c1);
                       }
                    char   keypressed17 = myKeypad.waitForKey();
                    if (keypressed17 != NO_KEY && keypressed17 !='*' && keypressed17 !='#' && keypressed17 !='A' && keypressed17 !='B' && keypressed17 !='C' && keypressed17 !='D' )
                      {
                        c2 = keypressed17;
                       lcd.setCursor(1, 1);
                       lcd.print(c2);
                       }


                     i1=(c1-48)*10;
                     i2=c2-48;
                     A_minute=i1+i2;
                    delay(500);
                     lcd.clear();
                      
                      keypressed=NO_KEY;
             }
             if (keypressed == 'D')
             {
              lcd.clear();
              lcd.setCursor(0,0);
              lcd.print("Funcao: Alarme 3");
              lcd.setCursor(0,1);
              lcd.print("Desativada");
              
              keypressed=NO_KEY;
              delay(500);
             }
             else {
              myRTC.updateTime();
              keypressed=NO_KEY;
             }   

  sensors.requestTemperatures();
                {
  Blynk.run();
  timerDHT22.run(); // Inicializa o Timer do DHT22
  timerDS18B20.run();

} 

}

Could you please post the contents of your Serial monitor when it works / doesn’t work? :slight_smile:

@Martin

I am doing a temperature and humidity monitoring. I would like to have the information in the app and i2c display.

Every time I put Blynk.begin (auth) everything else stops working. After withdrawing it works again.

GPIO 10 is a special pin used by the Ethernet shield.

Pete.

@PeteKnight
I made the change of the por and the error continues. Have any idea what it might be?

Start with a simpler sketch (from the Sketch Builder) to verify that your hardware setup is working.
Then, read this and modify your existing sketch so that your void loop only has two lines of code in it…

Pete.

@PeteKnight: From the pins used for the external connections, Michael most likely uses a Mega and not an Uno. I.e. GPIO 10 is NO special pin used by the Ethernet shield in this case. But you’re close to hte problem :wink:

@Michael_Fernandes: On the Mega the D53 is the SPI SS pin. And D52 is the SPI SCK pin
I.e. they are part of the SPI bus that the Ethernet shield uses!!
You can NOT use these pins for anything else! (like you DO with “OneWire”)

1 Like

I was asking for the Serial monitor output as it’s a very useful tool for determining what is and isn’t happening. It’s all good that you say it “stops working” but I was hoping to get more details from the serial monitor. :confused:

This line of code that you included makes Blynk output connection information through the serial monitor. Hence it often contains useful information in these sorts of situations.

I thought all Arduino Ethernet shields used Slave Select on pin 10 to enable the Ethernet shield?

Pete.

You can use almost any pin for “Slave Select”. This is of course necessary if have multiple devices on the SPI bus. Each one needs its own dedicated “Slave Select”.
But, you must NOT use the D53 for anything else if you use the SPI bus on the Mega.

See also: https://www.arduino.cc/en/Reference/SPI

1 Like