10 responses to “Sweeping servos with Arduino”

  1. Mathieu

    Hi, i got a question. I’m an artist and not quite handy in programming, even not Arduino. Mostly after looking for different codes on internet for days I probably manage to get the arduino done what I want it to do. Though right now I’m quite in a hurry to get my actual project done for a show.

    What I want to do:

    I send audio impulses in form of a square wave with just one peak to analog In (0) of the arduino. If the analog in reads a certain value, then something else has to happen. Tested that with a simple LED which lights up as soon as the value is bigger than the threshold, otherwise it’s off. But now I’d like to control a servo with it. The idea is as followed:

    The servo’s startposition is always 0°.

    case 1:

    if analog value > or = threshold (only once within 500ms)
    sweep servo from 0° to 180°
    after reaching end position, hold it.

    if the analog value > or = threshold (twice within 500ms)
    sweep servo back from 180° to 0°
    after reaching end position, hold it.

    Could you help me with the code, how I would have to write it to achieve my aim? You would really help me big times. It’s driving me nuts. Really.

    Hope to hear from you soon, thanks already

    Greetings, Mathieu

  2. Alicia Eggert

    Hi there,

    Thanks for posting this info. I just imported the VarSpeedServo library and tried verifying your code, and got the following error:

    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp: In function ‘void handle_interrupts(timer16_Sequence_t, volatile uint16_t*, volatile uint16_t*)’:
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:91: error: ‘LOW’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:91: error: ‘digitalWrite’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:122: error: ‘HIGH’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:122: error: ‘digitalWrite’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:126: error: ‘clockCyclesPerMicrosecond’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp: At global scope:
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:266: error: ‘boolean’ does not name a type
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp: In constructor ‘VarSpeedServo::VarSpeedServo()’:
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:283: error: ‘clockCyclesPerMicrosecond’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp: In member function ‘uint8_t VarSpeedServo::attach(int, int, int)’:
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:297: error: ‘OUTPUT’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:297: error: ‘pinMode’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:304: error: ‘isTimerActive’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp: In member function ‘void VarSpeedServo::detach()’:
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:315: error: ‘isTimerActive’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp: In member function ‘void VarSpeedServo::write(int)’:
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:326: error: ‘map’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp: In member function ‘void VarSpeedServo::writeMicroseconds(int)’:
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:334: error: ‘byte’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:334: error: expected `;’ before ‘channel’
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:335: error: ‘channel’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:343: error: ‘clockCyclesPerMicrosecond’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp: In member function ‘void VarSpeedServo::slowmove(int, uint8_t)’:
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:377: error: ‘map’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:380: error: ‘byte’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:380: error: expected `;’ before ‘channel’
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:381: error: ‘channel’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:388: error: ‘clockCyclesPerMicrosecond’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp: In member function ‘int VarSpeedServo::read()’:
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:407: error: ‘map’ was not declared in this scope
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp: In member function ‘int VarSpeedServo::readMicroseconds()’:
    /Users/aeggert/Documents/Arduino/libraries/VarSpeedServo/VarSpeedServo.cpp:414: error: ‘clockCyclesPerMicrosecond’ was not declared in this scope

    Any ideas as to why it wouldn’t be working for me?

    Thanks for your help!
    Alicia

  3. Alicia Eggert

    Thanks for your reply. I figured it out – just had to replace WProgram.h with Arduino.h in the VarSpeedServo.cpp file (like you said in the beginning!). It works great now.

  4. Philip van Allen

    I recently adopted the VarSpeedServo.h library, and have updated it for Arduino 1.0 and added some new features, including allowing you to have a write() function block until the move is complete, and the ability to create and run sequences of moves asynchronously. I also added example code to the library.

    Enjoy!

    https://github.com/netlabtoolkit/VarSpeedServo

  5. Alfi

    Hi, I have to control servo sweep with arduino
    but, can I use a looping to make the servo on for 2 minute and off for 10 minute?
    Thanks

  6. Sam

    I need to move the servo randomly and slowly..do you any code block for that please ?

  7. omkar

    hi
    we have made a pick and place robo using arduino.
    we used varspeedservo library but as we used mg958 servo motors it aint working properly and we are unable decode why is this happening and where is the fault?
    please let us know why is this happening.

Leave a Reply

*