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();
}
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…
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.
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.
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.
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.
That is the 2nd time recently I have seen this referenced attempt…
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.