A feature of the servomotors is that their connection cables in addition to the power supply have a third control cable. This is due to the fact that servomotors incorporate a PWM circuit (pulse width modulation) that controls the angle of rotation by means of the value of a pulse signal.
When the pulse of the signal has a certain value the motor does not rotate it remains with an angle of 0º. The greater the pulse, the greater the rotation of the motor in a certain direction. The same happens in the opposite direction when we decrease the pulse.
The great disadvantage of servomotors is that their movement is limited between 0 and 180º. For this reason, and to achieve a complete 360º rotation, it is necessary to remove the stops of the gearbox, but it is also necessary to replace the potentiometer with two resistors of the same value.
In this way the control circuit will have the signal of 90º and will continue to rotate.
In our practice we have connected a servo motor to the ARDUINO board, connecting the power cables to ground and +5 respectively and the control one to pin 9. Loading in ARDUINO the following program:
"
#include <Servo.h>
Servo myservo;
int angulo = 0;
void setup()
{
myservo.attach(9);
}
void loop()
{
for(angulo = 0; angulo < 180; angulo += 2)
{
myservo.write(angulo);
delay(20);
}
for(angulo = 180; angulo>=1; angulo-=2)
{
myservo.write(angulo);
delay(20);
}
}
"
The <Servo.h> command imports the program from the Servo library
The result is:


No hay comentarios:
Publicar un comentario