I tried controlling servo motor with arduino and it worked normally but when i tried same with blynk - slider with bluetooth connection is it not responding. Pls Help
Here is my code:
#define BLYNK_PRINT DebugSerial
#include <Servo.h>
int servoPin=6;
Servo myservo;
int pin=11;
int i=0;
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(0, 1); // RX, TX
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "57ac041e2a054fdb8d2368735c403f8a";
BLYNK_WRITE(V3)
{
servo.write(param.asInt());
}
void setup()
{myservo.attach(servoPin);
// Debug console
DebugSerial.begin(9600);
pinMode(11,INPUT);
pinMode(6,OUTPUT);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
}
void loop()
{i=analogRead(0);
int val=analogRead(pin);
Serial.println("Hello World!!!");
myservo.write(i);
delay(50);
Blynk.run();
}
Assuming you already removed those other commands from the void loop() then perhaps the issue is the bluetooth interface?? It isn’t the most reliable, possibly still BETA.
Nope, when i tried to control only led with Bluetooth it worked like hand to hand smoothly, but after connecting motor delay occurs don’t know why…??
Here’s what i have modified–
Nope what? Nope you didn’t remove those commands from the void loop() ?.. if they are stiil there, then that will cause unnecessary delays for the Blynk library, which could translate into the issues you are seeing… The solution to placing commands and functions in the void loop() is to use timed functions instead.
The Blynk library needs to run constantly in the background… housekeeping, running Blynk functions, maintaining the communication link to the App (via the server with normal WiFi link)… so any blocking code is BAD… that includes delays.
Proper Blynk coding edict required use of BlynkTimer to account for any required delays and timing.
And finally… In my observations, the servo library seems to react with Blynk library… perhaps the shared internal timers? (at least on Arduino MCUs) regardless, I have noticed that while sometimes subtle, the servo will jitter and move erratically at times… even when not actually being moved. I have gotten around the idle jittering by detaching the servo shortly after any movement.