Need help with connecting Wifi shield with Blynk

Hi guys,
I’m really new in all this Arduino stuff with very poor coding skills so please be gentle…
I’m trying to control a servo manually (using push button) and also via Wifi (using blynk). I’m using Arduino Uno + Wifi shield.
Please see my sketch, when I’m trying to run this code the serial shows shows:
Connecting to blynk-cloud.com:80 again and again.
I see many topics describing the same issue and I tried to follow the instructions but still facing the same issue.

I tried to change it to use Blynk.config(wifi, auth) in the setup and also to connect to hotspot instead of my router but still the same issue… Can you help me understand what am I doing wrong?


#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <SPI.h>
#include <BlynkSimpleWifi.h>
#include <LiquidCrystal.h>
#include <Servo.h>


LiquidCrystal lcd(A5, A4, A3, A2, A1, A0); /*Initialize the LCD and
                                        tell it which pins is
                                        to be used for communicating*/

////////////////////////////////////////////////////////////////////////////////////////////////////////////////Blynk code
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "1234";


////////////////////////////////////////////////////////////////////////////////////////////////////////////////WiFi code
// Set password to "" for open networks.
char ssid[] = "123";
char pass[] = "123";

int status = WL_IDLE_STATUS;     // the Wifi radio's status

////////////////////////////////////////////////////////////////////////////////////////////////////////////////Servo code
int button = 2; //button pin, connect to ground to move servo
int press = 0;
Servo servo;
boolean toggle = true;

/////////////////////////////////Blynk + servo
BLYNK_WRITE(V3)
{
servo.write(param.asInt());
}


void setup() {
  lcd.begin(16,2);
  // initialize serial:
  Serial.begin(9600);

  // attempt to connect using WPA2 encryption:
  Serial.println("Attempting to connect to WPA network...");
  Blynk.begin(auth, ssid, pass);
  lcd.print("Trying to");
  lcd.setCursor(0,2);
  lcd.print("connect...");
  delay(2000);
  lcd.clear();

  
  ////Servo code
  pinMode(button, INPUT); //arduino monitor pin state
  servo.attach(6); //pin for servo control signal
  digitalWrite(5, HIGH); //enable pullups to make pin high
  

  // if you're not connected, stop here:
  if ( status != WL_CONNECTED) { 
    Serial.println("Couldn't get a wifi connection");
    lcd.print("Couldn't connect");
    while(true);
  } 
  // if you are connected, print out info about the connection:
  else {
    Serial.println("Connected to network");
    lcd.print("Connected to");
    lcd.setCursor(0,2);
    lcd.print("network");
    delay(5000);
    lcd.clear();
  
  }
}

void loop() {
/////Servo
press = digitalRead(button);
  if (press == LOW)
  {
    if(toggle)
    {
      servo.write(160);
      toggle = !toggle;
    }
    else
    {
      servo.write(20);
      toggle = !toggle;
    }
  }
  delay(500);  //delay for debounce
  Blynk.run();  
}
    

Hmmmm, where to begin?

Let’s start with the way the code you posted displays. You didn’t use backticks at the beginning and end, as explained in the pre-populated text that you deleted. Edit your posts I g the pencil icon at the bottom and add the required backticks and cpp…

Blynk%20-%20FTFC

Then there’s your void loop. Read this:

I’m not familiar with the Wi-Fi shield you’re using, but I’m guessing it’s the equivalent of an ESP-01 connected via serial to your Uno, acting as a Wi-Fi modem.
If that’s the case then you have a problem, because the UNO has only one serial UART and you’re using that for your serial debug messages.
The normal solution would be to use softwareserial to emulate a second serial port and use this for communication with your Wi-Fi shield. You may have some jumpers available on your shield to allow this, but as I said, I’m not familiar with your hardware and I’d guess that there are dozens of similar shields out there - all of which will work slightly differently.

You’d be better using one of the simple sketches in the Sketch Builder:
https://examples.blynk.cc/?board=Arduino%20Uno&shield=Arduino%20WiFi%20Shield&example=GettingStarted%2FBlynkBlink
to get a basic sketch running first, then take it from there.

Pete.

Thanks Pete.

  1. ok. done - sorry :slight_smile:
  2. I’m using this: https://www.arduino.cc/en/Guide/ArduinoWiFiShield WiFi shield, and I used the simple sketch generator for the code.

Any suggestions?

Okay, so it’s an SPI communication protocol rather than serial.

Use the simple Blynk blink code to get things working, rather than including all that LCD and Servo stuff.

Pete.

Thanks mate…

Still, same results:
[10001]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.5.4 on Arduino Uno

[10122] Connecting to blynk-cloud.com:80
[21166] Connecting to blynk-cloud.com:80
[31168] Connecting to blynk-cloud.com:80
[41170] Connecting to blynk-cloud.com:80

Try adding #define BLYNK_DEBUG as the very first line of your code and seeing what that gives in your serial monitor.

If you decide to post the results then use backticks at top and bottom again.

Pete.

This is the results I’m getting:

[2023] WiFi firmware: 1.0.0
[2024] Connecting to 123
[12025] IP: my IP
[12026] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.4 on Arduino Uno

[12147] Connecting to blynk-cloud.com:80
[23192] Connecting to blynk-cloud.com:80
[33195] Connecting to blynk-cloud.com:80
[43197] Connecting to blynk-cloud.com:80
[53199] Connecting to blynk-cloud.com:80
[63201] Connecting to blynk-cloud.com:80
[73203] Connecting to blynk-cloud.com:80
[83205] Connecting to blynk-cloud.com:80
[93207] Connecting to blynk-cloud.com:80

Doesn’t look like full Blynk debug output to me.

Are you sure you added #define BLYNK_DEBUG as the very first line of your code?

Pete.

Yes. Do I need to leave the: #define BLYNK_PRINT Serial under this line?

OK. I see it’s necessary…
Maybe it has something to do with one of the libraries?
I had some trouble with downloading the <BlynkSimpleWifi.h> folder. It didn’t work with the last git file I downloaded, I needed to look for an older version.

Yes, that’s fine.

Pete.

You could try re-installing, but I think you’d get compile errors if it wasn’t installed. You could try using verbose messages in Arduino IDE preferences and make sure that if you’re getting messages saying that multiple libraries were found that the one which is being used is the correct one.

Pete.

Thanks a lot for your help!
I tried to use ESP8266 instead of using the WiFi Shield and it worked!
Maybe it has something to do with the WiFi Shield firmware.

Now I need to learn how to control the Servo using the Timer widget in the app and I’m done.

Thanks again :slight_smile:

That is the 2nd time recently I have seen this referenced attempt… :thinking:

Well a bit of advice from that other topic… the Timer Widget only outputs a 0 or 1, so look at using the timer in the Eventor, or better yet, just use the timer to call a function that runs the desired servo commands accordingly.

Feel free to create a new topic with details if you require further suggestions.