What is a servomotor? How to use it in your project? Introduction A servomotor is a motor capable to stay in a position given by the user. A servomotor can’t exceed a position of 180°. According to the servomotor you have choosen, you can have a tork important to stay at the position choosen.All theses features make this motor a useful component to open a door, open a valve or the direction of the car.Nevertheless if you want to spin a propeller or to use the motor as a dynamo, you will need a motor dc.If you want a motor which keep the position and turn at 360 degrees, you can use a stepper motor.In this course we will see how to control your servomotor by two ways: a program which turn the servomotor from 0° to 180° and go back to the initial position and a program to control the servomotor by yourself with the serial monitor. How it works? A servomotor is composed of different elements:A small dc motorA reducer which reducing the speed of the dc motor and increase the tork to have more power to stay in the position.A potentiometer to generate a variable voltage proportionate at the angle of the output axis. The servomotor is controlled with pulse width modulation (pwm) with a fixed frequency of 50 hz (T=20 ms) and the high state of the signal determines the position of the servomotor. That’s mean that the duration of the pulse determinates the absolut angles therefore the position of the servomotor.This signal is repeated periodically, in general every 20 milliseconds, which permits at the card to control and correct the continuously the position. This one is measured by the potentiometer. The servomotor works with three wires:Red wire: the power supply between (3.3V and 5V).Black wire: The ground (0V).Yellow wire: the input of the signal. Which one to choose? If you want to use a servomotor to do Arduino, we advise you to use the MG995 or the SG90. Theses both servomotors are small and a torque of 25kg, which convenient for Arduino’s projects. Nevertheless if you need a servomotor with a torque more important, you can choose 35kg servomotors. The Servomotor library The servomotor works with a library which help you to control it. You can download the library and read our course about the libraries to install it. Control your servomotor A) Turn your servomotor from 0° to 180°In this part we will see how to turn your servomotor from 0° to 180° and back to the initial position. B) Control your servomotor with the serial monitorThis is the program to control the servomotor with the serial monitor. The circuit remains the same. This is what we can see on the serial monitor: Control the servomotor with a potentiometer We will see now how to control a servomotor with a potentiometer. This project has a lot of applications possible, such as control a robot,a mechanical arm or even open a door. How to write the program without the library? The servomotor works with a library which will simplify its use.In this part we will show the different functions contains in the library if you want to directly include it in your program.attach(pin) : Function to associate the servomotor to the pin of the Arduino card which is plugged in.Here is the program corresponding to attach(pin) function: write(angle): To indicate to the servomotor which angle its need to move.Here is the program corresponding to the function write(angle) in the library: read(pin): Its indicate the angle in which the servomotor is placed. attached: Here is the function to attach the servomotor to the pin whose plugged in.Here is the program corresponding to the writeMicroseconds function in the library: writeMicroseconds: To adjust extreme positionsThis program correspond to the function writeMicroseconds in the library: To go further: Control your servomotor with python You can also control a servomotor with python. We have made a course about it to help you.