Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Servo speed

Servo speed

Scheduled Pinned Locked Moved Development
1 Posts 1 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ben999B Offline
    ben999B Offline
    ben999
    wrote on last edited by
    #1

    Hi guys

    I am in the process of automating my central heating system (network gas boiler for heaters and tap water)

    A part of this project is to use a RC servo to control the thermostat knob

    Rotation of the knob has to be done much slower than the average servo speed

    Using delay() in sketches in order to slow down servo travel is a non-sense

    I tried VarSpeedServo library : but servo movement wasn't neat and it looks like it's using delay()...

    So i wrote that little bit of sketch:

    #include <Servo.h>
    Servo myservo;  // create servo object to control a servo
    #define servoMin 10
    #define servoMax 170
    int servoTarget = 90;               // incoming serial data - servo target position
    int servoPos    = 90;               // actual servo position
    unsigned long servoDelay = 1000;    // time delay between 2 servo position increments
    unsigned long servoPrevMillis;
    
    void setup() {
      myservo.attach(9);    // attaches the servo on pin 9 to the servo object
      Serial.begin(9600);   // opens serial port, sets data rate to 9600 bps
      Serial.print("Servo at ");
      Serial.println(servoTarget);
      myservo.write(servoTarget);
    }
    
    void loop() {
      if (Serial.available() > 0)  {
        servoTarget = Serial.parseInt();
        Serial.print("I received: ");
        Serial.println(servoTarget);
      }
      if ( (servoTarget != servoPos)
           && (servoTarget < servoMax) && (servoTarget > servoMin)
           && ( (millis() - servoPrevMillis) >= servoDelay) ) {
        if ( servoTarget > servoPos )
          servoPos++;
        else
          servoPos--;
        myservo.write(servoPos);
        delay(10);                     // wait for the servo to get there
        Serial.println(servoPos);
        servoPrevMillis = millis();
      }
    }
    

    As i am quite happy with the result i though i would share it!

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    22

    Online

    11.7k

    Users

    11.2k

    Topics

    113.0k

    Posts


    Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • MySensors
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular