First tests with a servo

Today I did first servo tests.

Standard Servo (ordered by Conrad electronics, 2€ something...). The servo has 3 connections. (Black=Ground=0V, Red=+6V=V_in, Yellow=Control=Pin21).

A first test code goes like this:

#include "mbed.h"

PwmOut servo(p21);

int main() {
    servo.period_ms(20);
    while(1) {
        motor=0.03;    // varying the duty-cycle 
        wait(1);       // from 0.03 to 0.11
        motor=0.05;    // --> corresponds to
        wait(1);       // about a rotation of 150°
        motor=0.07;
        wait(1);
        motor=0.09;
        wait(1);
        motor=0.11;
        wait(1);
        motor=0.09;
        wait(1);
        motor=0.07;
        wait(1);
        motor=0.05;
        wait(1);
    }
}
The test was successful. :-)

 


0 comments

You need to log in to post a comment