Hi,
I’ve been struggling with this for a few days now. Here’s what is happening - If I move the slider very slowly, it seems to control the servo correctly, but if i move it quickly, the servo doesn’t keep up and it stops moving. I added a short delay and that seems to help somewhat. The strange thing is that the servo.read value appears to be different than the actual physical position of the servo. What i mean is that the servo.read value keeps changing even though the servo is not moving. Any advice?
hardware:
board - esp8266nodemcu
Servo - 17kg large torque. 15 kg·cm (208 oz·in) @6.6V; 17 kg·cm (236 oz·in) @7.4V
servo powered by 9v battery, board powered by usb
note: servo works perfectly when controlled locally with a potentiometer
Code below:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxx";
char pass[] = "xxxxx";
Servo servo1;
int ServoPin = 5;
int currentServoPos = 0;
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
servo1.attach(ServoPin);
}
BLYNK_WRITE(V5)
{
int pinValue = param.asInt(); // assigning incoming value from pin V5 to a variable
int mappedServo = map(pinValue, 0, 1023, 1, 180);
currentServoPos = servo1.read();
Serial.print(" current servo Position is: ");
Serial.println(currentServoPos);
Serial.print(" current slider Position is: ");
Serial.println(mappedServo);
if ( mappedServo < currentServoPos)
{
delay(100);
servo1.write(mappedServo -1);
}
else if (mappedServo > currentServoPos)
{
delay(100);
servo1.write(mappedServo +1);
}
}
void loop()
{
Blynk.run();
}
'''