|
I bought a couple of cheap micro servos for a future Arduino project. They are impressively small (I think) whilst still delivering the torque that I require. Two are packaged in a blister pack, together with some extra servo arms and -screws.
They're called "Dynam 7g micro servo", model number DY-1002, and the specs are:
weight: 7g torque: 1.6kg/cm (at 4.8 V) speed: 0.1sec/60° (at 4.8 V) size(mm): 24.3×11×19.8 mm (excl. mount points and arm)
Servos are controlled using pulse width modulation. Others described very eloquently and in great detail how this works, so I won't go into that, except for one thing, which is the point of this article: you need to know the two pulse width values that correspond to the minimum and maximum angle that the servo can be set to.
I used the example code of the Arduino MegaServo library, hooking up just one servo, as follows:
- servo (+) (red lead) to Arduino 5V
- servo GND (black lead) to Arduino GND
- servo control (white lead) to digital pin 2
- a 500 Ω resistor between 5V and GND, with the wiper connected to analog 0
The total angular rotation is not specified, but by carefully (!) rotating the servo arms (with the power leads disconnected) I figured it is about 160 degrees.
To find the minimum pulse width, i.e. the pulse width that drives the servo to its 0 degrees position, I connected the white lead to GND and tweaked the value of the second argument of Servos[i].attach until (1) the servo was at the end stop and (2) not buzzing as if it would go any further. Buzzing is bad, m'kay.
To find the maximum pulse width I repeated this procedure, connecting the white lead to +5V and changing the third argument of Servos[i].attach.
With a bit of trial-and-error, the values that work good for me are:
- minimum pulse width: 900 (msec)
- maximum pulse width: 2600 (msec)
Note that these values may differ slightly between servos (as I found out). Also, the servos I got differ from the product photo in that mine are black, not blue. No idea if the insides are different, too.
Now, if you connect the white lead to digital out 2, you should be able to control the servo through its range using the potentiometer.
Here's the Arduino code:
#include <MegaServo.h>
#define NBR_SERVOS 1 #define FIRST_SERVO_PIN 2
MegaServo Servos[NBR_SERVOS];
int pos = 0; // variable to store the servo position int potPin = 0; // connect a pot to this pin.
void setup() { for( int i =0; i < NBR_SERVOS; i++) { Servos[i].attach( FIRST_SERVO_PIN +i, 900, 2600); // servo pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH } }
void loop() { pos = analogRead(potPin); // read a value from 0 to 1023 for ( int i =0; i <NBR_SERVOS; i++) { Servos[i].write( map(pos, 0,1023,0,160)); // map value of 0-1023 to value of 0-160 } delay(15); }
Modifying for 360° rotation
There are a couple of ways to modify servos so they will turn through 360 degrees. Unfortunately they won't work on this servo because the outgoing gear wheel only has teeth along approx. 160 degrees of its circumference. So unless you find a fitting gear wheel it's not possible to modify this servo.
|
Great. Especially with the pulse width. My servo (same brand, but 8g) was buzzing with the default values.
Much appreciated article.
/ jonas R, Sweden