Servo not responding correctly with Blynk slider

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();
       
          
        }
'''

Try just setting the slider for the servo range of 0-180 (or whatever) and s simpler control function.

You will need BlynkTimer if you also use the myservo.detach(); option. I use it to stop the servo from jittering when not in actual motion…

 //===== Servo Slider Function =====
BLYNK_WRITE(V10) // Servo Slider Function
{
  myservo.attach(servoPin);
  SrvoPos = param.asInt();
  myservo.write(SrvoPos);
  timer.setTimeout(1000L, ServoDetach);
} // END Blynk Function

void ServoDetach() {
  myservo.detach();
}

Fast movement means longer, harder, current draw… and 9v batteries are well known for NOT being good current sources.

Thanks Gunner, what would you suggest to power the servo. My goal is to run 2 of them for pan/tilt for an outside garden project.

A couple of 18650 LiPOs in series will be great I think. In a pinch even a 4 pack of AA will be better than a 9v

1 Like

just use a power bank.

Power Banks generally only supply 5v The large torque servos are a bit more power hungry… the dual 18650s will supply the best voltage and current combo.

Thanks Gunner,
If i got a big LiPO pack with the right voltage such as the kind used for drones and rc cars, would that be better than using 2 small ones in series? I’m not at all familiar with electrical engineering so the less I have to modify, the better.

for example, a product like this:

That would work perfectly as well.

You will need a proper charger and a little understanding about the proper care, use and charging, as those can be potentially dangerous.

You were right! i got 2 3.7v 18650 LiPOs and connected them in series and now the servo works much better. Thanks!

1 Like