Problem using servo and pcm sound

The ServoTimer2 library requires the write() function argument in microseconds of the pulse, not the angle.

It is also possible to convert with the map function.

// Make servo go to 0 degrees
Servo1.write(map(0, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH));
delay(1000);
// Make servo go to 90 degrees
Servo1.write(map(90, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH));
delay(1000);
// Make servo go to 180 degrees
Servo1.write(map(180, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH));
delay(1000);

Enter the angle in the first parameter of the map() function. Other value is fixed.
 


 

Also, if the servo doesn't move 180 degrees and only about 160 degrees, open the library folder ServoTimer2.h and edit the following line.

Default

#define MIN_PULSE_WIDTH       750        // the shortest pulse sent to a servo

#define MAX_PULSE_WIDTH      2250        // the longest pulse sent to a servo

to Modified

#define MIN_PULSE_WIDTH       550        // the shortest pulse sent to a servo
 
#define MAX_PULSE_WIDTH      2450        // the longest pulse sent to a servo
1 Like