How to remove the motor from the servo. Arduino servos SG90, MG995, MG996: connection diagram and control

The simplest of robots are 2-wheeled or 4-wheeled. Such a robot could be based on a chassis from a radio-controlled car, but not everyone may have it on hand or it may be a shame to waste it. You can also make the chassis yourself, but putting the wheels directly on the motor is not very good decision, the motor needs to slow down, for this you need a gearbox. Getting a ready-made chassis or gearbox, or a motor with gearbox, turned out to be not such an easy task, unlike servos. Almost any servo drive can be easily converted into a motor with a gearbox.

Wheels can be glued directly to the rocker of such a motor, and the servo body is convenient for mounting.

ATTENTION! The design of other servos may differ, and, therefore, this manual is only partial.

The simplest and cheapest servo was taken as a basis:

First, let's take it apart.

First, we remove unnecessary electronics, bite off the driver, and control the motor directly. Next, let's proceed to modify the mechanics, remove the first gear with the external shaft and remove the travel stop from it.

We take out the resistor and bite out the limiter located on its body.

We put all the mechanics back together and check that everything moves well.

The next step is to solder the wire to the motor.

We assemble the former servo into a new motor with a gearbox.

Everything is ready, if you haven’t made any mistakes, you can enjoy your work.

This article discusses servos: their design, purpose, tips on connecting and controlling, types of servos and their comparison. Let's go ahead and start with what a servo is.

Servo concept

A servo drive is most often understood as a mechanism with an electric motor, which can be asked to turn to a given angle and hold this position. However, this is not a completely complete definition.

To be more precise, a servo drive is a drive controlled through negative feedback, allowing precise control of motion parameters. A servo drive is any type of mechanical drive that contains a sensor (position, speed, force, etc.) and a drive control unit that automatically maintains the necessary parameters on the sensor and device according to a given external value.

In other words:

    The servo drive receives the value of the control parameter as input. For example, the angle of rotation.

    The control unit compares this value with the value on its sensor.

    Based on the comparison result, the drive performs some action: for example, turning, accelerating or decelerating so that the value from the internal sensor becomes as close as possible to the value of the external control parameter.

The most common are servos that hold a given angle and servos that maintain a given rotation speed.

A typical hobby servo is shown below.

How are servos designed?

Servo drive device

Servo drives have several components.

Drive - electric motor with gearbox. To convert electricity into mechanical rotation, you need electric motor. However, the motor rotation speed is often too high for practical use. Used to reduce speed gearbox: a gear mechanism that transmits and converts torque.

By turning the electric motor on and off, we can rotate the output shaft - the final gear of the servo, to which we can attach something that we want to control. However, in order for the position to be controlled by the device, it is necessary feedback sensor - encoder, which will convert the angle of rotation back into an electrical signal. A potentiometer is often used for this. When you turn the slider of the potentiometer, its resistance changes, proportional to the angle of rotation. Thus, it can be used to determine the current position of the mechanism.

In addition to the electric motor, gearbox and potentiometer, the servo drive has electronic components that are responsible for receiving an external parameter, reading values ​​from the potentiometer, comparing them and turning the motor on/off. She is responsible for maintaining negative feedback.

There are three wires going to the servo. Two of them are responsible for powering the motor, the third delivers a control signal, which is used to set the position of the device.

Now let's see how to control a servo externally.

Servo drive control. Control signal interface

To indicate the desired position to the servomotor, a control signal must be sent along the wire provided for this purpose. The control signal is pulses of constant frequency and variable width.

What position the servo should take depends on the length of the pulses. When a signal enters the control circuit, the pulse generator present in it produces its own pulse, the duration of which is determined through a potentiometer. The other part of the circuit compares the duration of two pulses. If the duration is different, the electric motor turns on. The direction of rotation is determined by which of the pulses is shorter. If the pulse lengths are equal, the electric motor stops.

Most often, hobby servers produce pulses at a frequency of 50 Hz. This means that a pulse is emitted and received once every 20 ms. Typically, a pulse duration of 1520 µs means that the servo should take the middle position. Increasing or decreasing the pulse length will cause the servo to turn clockwise or counterclockwise, respectively. In this case, there are upper and lower limits on the pulse duration. In the Servo library for Arduino, the following pulse lengths are set by default: 544 μs for 0° and 2400 μs for 180°.

Please note that your specific device may not have factory default settings. Some servos use a pulse width of 760 µs. The middle position corresponds to 760 μs, similar to how in conventional servos the middle position corresponds to 1520 μs.

It's also worth noting that these are just generally accepted lengths. Even within the same servo model, there may be manufacturing tolerances that cause the operating range of pulse lengths to vary slightly. For accurate operation, each specific servo must be calibrated: through experimentation, it is necessary to select the correct range specific to it.

Something else worth paying attention to is the confusion in terminology. Often the method of controlling servos is called PWM/PWM (Pulse Width Modulation) or PPM (Pulse Position Modulation). This is not true, and using these methods may even damage the drive. The correct term is PDM (Pulse Duration Modulation). In it, the length of the pulses is extremely important and the frequency of their occurrence is not so important. 50 Hz is normal, but the servo will work correctly at both 40 and 60 Hz. The only thing you need to keep in mind is that if the frequency is greatly reduced, it can operate jerkily and at reduced power, and if the frequency is greatly increased (for example, 100 Hz), it can overheat and fail.

Servo Drive Characteristics

Now let's figure out what types of servos there are and what characteristics they have.

Torque and swing speed

First let's talk about two very important characteristics of a servo drive: o torque and about turning speed.

The moment of force, or torque, is a vector physical quantity equal to the product of the radius vector drawn from the axis of rotation to the point of application of the force and the vector of this force. Characterizes the rotational action of a force on a solid body.

Simply put, this characteristic shows how heavy a load the servo can hold at rest on a lever of a given length. If the torque of the servo drive is 5 kg×cm, then this means that the servo drive will hold a lever 1 cm long, on the free end of which 5 kg is suspended, in a horizontal position. Or, equivalently, a lever 5 cm long from which 1 kg is suspended.

Servo speed is measured by the amount of time it takes for the servo arm to rotate 60°. A characteristic of 0.1 s/60° means that the servo rotates 60° in 0.1 s. From it it is easy to calculate the speed in a more familiar value, revolutions per minute, but it so happens that when describing servos, such a unit is most often used.

It is worth noting that sometimes there is a trade-off between these two characteristics, since if we want a reliable, heavy-duty servo, we must be prepared for this mighty unit to turn slowly. And if we want a very fast drive, then it will be relatively easy to dislodge it from its equilibrium position. When using the same motor, the balance is determined by the configuration of the gears in the gearbox.

Of course, we can always take a unit that consumes more power, the main thing is that its characteristics meet our needs.

Form factor

Servos vary in size. And although there is no official classification, manufacturers have long adhered to several sizes with a generally accepted arrangement of fasteners. They can be divided into:

    small

    standard

They have the following characteristic dimensions:

There are also so-called “special type” servos with dimensions that do not fall into this classification, but the percentage of such servos is very small.

Internal interface

Servo drives are either analog or digital. So what are their differences, advantages and disadvantages?

Externally, they are no different: electric motors, gearboxes, potentiometers are the same, they differ only in the internal control electronics. Instead of a special analog servo microcircuit, the digital counterpart has a microprocessor on the board that receives pulses, analyzes them and controls the motor. Thus, in the physical design, the only difference is in the method of processing impulses and controlling the motor.

Both types of servo drive accept the same control pulses. The analog servo then decides whether to change the position and sends a signal to the motor if necessary. This usually happens with a frequency of 50 Hz. Thus, we get 20 ms - the minimum reaction time. At this time, any external influence can change the position of the servo drive. But this is not the only problem. At rest, no voltage is applied to the electric motor; in case of a slight deviation from equilibrium, a short low-power signal is sent to the electric motor. The greater the deviation, the stronger the signal. Thus, with small deviations, the servo drive will not be able to quickly rotate the motor or develop a large torque. “Dead zones” are formed in time and distance.

These problems can be solved by increasing the reception frequency, signal processing and electric motor control. Digital servos use a special processor that receives control pulses, processes them and sends signals to the motor with a frequency of 200 Hz or more. It turns out that the digital servo drive is able to react faster to external influences, quickly develop the required speed and torque, which means it is better to hold a given position, which is good. Of course, it also consumes more electricity. Also, digital servos are more difficult to manufacture and therefore cost significantly more. Actually, these two disadvantages are all the disadvantages that digital servos have. IN technically they beat analog servos hands down.

Gear materials

Gears for servos come from different materials: plastic, carbon, metal. All of them are widely used, the choice depends on the specific application and what characteristics are required in the installation.

Plastic, most often nylon, gears are very light, not subject to wear, and are most common in servos. They do not withstand heavy loads, but if the loads are expected to be light, then nylon gears are the best choice.

Carbon gears are more durable, practically do not wear out, and are several times stronger than nylon ones. The main disadvantage is the high cost.

Metal gears are the heaviest, but they can withstand maximum loads. They wear out quite quickly, so you have to change the gears almost every season. Titanium gears are favorites among metal gears, and both technical specifications, and in price. Unfortunately, they will cost you quite a lot.

Brushed and brushless motors

There are three types of servo motors: regular core motor, coreless motor, and brushless motor.

A conventional core motor (right) has a dense iron rotor with a wire winding and magnets around it. The rotor has multiple sections, so when the motor rotates, the rotor causes the motor to vibrate slightly as the sections pass the magnets, resulting in a servo that vibrates and is less accurate than a servo with a coreless motor. The hollow-rotor motor (left) has a single magnetic core with a cylinder or bell-shaped winding around the magnet. The coreless design is lighter in weight and has no sections, resulting in faster response and smooth, vibration-free operation. Such motors are more expensive, but they provide more high level control, torque and speed compared to standard ones.

Servo drives with brushless motors have appeared relatively recently. The advantages are the same as those of other brushless motors: there are no brushes, which means they do not create rotational resistance and do not wear out, the speed and torque are higher with a current consumption equal to brushed motors. Brushless motor servos are the most expensive servos, but they also offer best characteristics compared to servos with other types of motors.

Connecting to Arduino

Many servos can be connected to Arduino directly. To do this, a loop of three wires comes from them:

    red - nutrition; connects to 5V pin or directly to power supply

    brown or black - earth

    yellow or white - signal; connects to the Arduino digital output.

To connect to Arduino, it will be convenient to use a port expander board such as Troyka Shield. Although with a few additional wires you can connect the servo via the breadboard or directly to the Arduino pins.

It is possible to generate control pulses yourself, but this is such a common task that there is a standard Servo library to simplify it.

Dietary restrictions

A typical hobby servo drive consumes more than 100 mA during operation. At the same time, Arduino is capable of delivering up to 500 mA. Therefore, if you need to use a powerful servo drive in a project, it makes sense to think about separating it into a circuit with additional power.

Let's look at the example of connecting a 12V servo drive:

Limitation on the number of connected servos

On most Arduino boards, the Servo library supports control of no more than 12 servos; on Arduino Mega, this number increases to 48. However, there is a small by-effect Using this library: If you are not working with an Arduino Mega, then it becomes impossible to use the analogWrite() function on pins 9 and 10, regardless of whether servos are connected to these pins or not. On Arduino Mega we can connect up to 12 servos without disrupting the PWM/PWM functionality, if we use more servos we will not be able to use analogWrite() on pins 11 and 12.

Servo library functionality

The Servo library allows software control of servos. For this, a variable of type Servo is created. Management is carried out by the following functions:

    attach() - attaches a variable to a specific pin. There are two syntax options for this function: servo.attach(pin) and servo.attach(pin, min, max) . In this case, pin is the number of the pin to which the servo drive is connected, min and max are the pulse lengths in microseconds, responsible for the rotation angles of 0° and 180°. By default, they are set to 544 μs and 2400 μs, respectively.

    write() - commands the servo to accept some parameter value. The syntax is: servo.write(angle) where angle is the angle the servo should turn through.

    writeMicroseconds() - gives a command to send a pulse of a certain length to the servo drive; it is a low-level analogue of the previous command. The syntax is: servo.writeMicroseconds(uS) , where uS is the pulse length in microseconds.

    read() - reads the current value of the angle at which the servo is located. The syntax is: servo.read() , returning an integer value between 0 and 180.

    attached() - checks whether a variable has been attached to a specific pin. The syntax is as follows: servo.attached() , returning logical true if the variable was attached to any pin, false otherwise.

    detach() - performs the opposite action of attach() , that is, it detaches the variable from the pin to which it was assigned. The syntax is: servo.detach() .

All Servo2 library methods are the same as Servo methods.

Example of using the Servo library

Instead of a conclusion

Servo drives are different, some are better - others are cheaper, some are more reliable - others are more accurate. And before you buy a servo, it is worth keeping in mind that it may not have the best characteristics, as long as it is suitable for your project. Good luck in your endeavors!

To disassemble our servo drive we need a screwdriver. Because I'm disassembling a very small servo drive, so I need a corresponding screwdriver. Personally, I use screwdrivers from some cheap Chinese set. I bought it at a kiosk in the underground passage for about $5, so it’s not very expensive.

To open the servo drive you only need to unscrew four screws. They are located on the bottom cover. Unscrew:

By removing the cover you can examine the control unit. I won't go into details, I'm going to remove it from here anyway. You can also see the motor to which two wires lead.

There is also a cover on top, after removing which you can see the gears of the gearbox. It is worth noting that two of them are attached to the potentiometer - this is quite important, since in order for the gearbox to continue to perform its function, we will have to actually break the potentiometer - we will simply use it as an axis for the gears.

Actually, you need to remove all the gears from the servo drive and put them aside for a while. We take out the potentiometer (by the way, it’s also variable resistor) from the housing by gently pushing it from the underside of the servo with a screwdriver.

Now, in fact, the moment of no return has arrived. Of course, it will always be possible to solder everything back together, but this is more difficult. So - the potentiometer bites off.

Then, using the same method, we separate the control board with power and signal wires.


Then we bite off the wires from the motor. Be careful here and do not bite off the contacts from the motor itself - if you are not sure, it is better to leave the wire with a reserve. Then it can be desoldered. I bite the wire right down to the contact.

Let's take an inventory.

Everything seems to be in place. Now let's pick up our potentiometer.

The fact is that now it also rotates only at a certain angle. And since it is the axis and the largest gear is attached to it, on which we will actually attach the wheel later, we must make sure that it rotates constantly. We take out two metal plates that prevent this. We get:

I hope the photo shows what I did. I tore it out with small pliers, since there was nothing more suitable at hand.
Now you need to cut off the limiter on the gear itself. It looks like a protrusion from the bottom of the gear. It's easy to find, it looks like this.

We cut it.

And after that, you can start assembling the gearbox back into the housing. We insert back the axis we made earlier from the potentiometer.

Next, one gear at a time, starting with the smallest one. Be careful when inserting the last gear - it is specially attached to the axis of the former potentiometer, since the tip of the axis is made in the shape of a letter D. This protrusion must fit into the recess in the gear. It turns out something similar to the following picture.

We put the top cover on the gearbox so that it does not fall apart during further work.

Well, there's not much left. We take the wire with the connector that we previously bit off from the board and separate the wiring in it. You shouldn’t separate them over a long distance; in fact, one centimeter is quite enough.

We clear two of them (basically any, but I used red and green). It is enough to cut off about 3mm of insulation. For our purposes - more than.

We simply bend the remaining unstripped wire so that it does not interfere with us.

Let's move on to the hot stuff. It's time to heat up the soldering iron. While the soldering iron was heating up, I made the servo drive in the grip more comfortable.

The first thing we need to do is remove the remnants of old solder that remain on the motor contacts. I do this using a desoldering pump, after preheating the contact with a soldering iron to such a state that the solder melts. The main thing here is not to overdo it - back cover The motor is still plastic and does not like to warm up for a long time. The process looks something like this:

I understand that it may not be very noticeable what I did, but there was practically no solder left on the contacts, which is what I wanted.

There are wonderful articles on soldering in DI HALT. He is generally a genius, it seems to me. Link to his blog, there is actually a lot of stuff besides soldering, just do a search.
In short, in order to make a good solder, you must always get rid of the old solder first.
There are two wires left to solder. Anyone familiar with soldering can do it in 5 seconds. For someone like me who normally took up a soldering iron for the second time in my life, it will take a little more time, but still - it’s very simple, anyone can do it.
When soldering, I use flux, which, admittedly, makes the work much easier and the quality of soldering is much easier to ensure with it. Personally, on the advice of, again, DI HALT, I already fell in love with LTI-120 on his blog. I have it in such a fashionable jar with a brush.

Tighten the four screws.

That's all, the modification of the servo is over. Having reattached the servo drive more comfortably and firmly in the grip, you can begin testing.

This time I won’t get fancy with the controller, but will simply apply 5V voltage from the power supply to the green and red wires. Attention, in the video there is quite a loud sound from the drive.

As you can see, now nothing prevents our servo from rotating without stopping. The sound produced by the drive is actually not quiet, but in principle it is tolerable. That's probably all for today.

Servos typically have a limited rotation angle of 180 degrees. In this case, we will consider a “modified” servo with an unlimited axis rotation angle.


Performance characteristics from the seller's page

Size:40*20*37.5+5mm drive shaft
weight:38 g
wire length: 320 mm

Speed:0.19sec/60 degree (4.8V)
0.22sec/60 degree (6 V)
the speeds are most likely mixed up, the servo should be faster by 6 volts
torque: 5kg. cm. at (4.8 V)
5.5kg.cm.at (6 V)
voltage:4.8V-6V

Standard delivery set

4 rocking chairs of different shapes
4 bushings, 4 rubber dampers and 4 screws for attaching the servo
and another small screw for attaching the rocker to the shaft escaped from the photo :)

Appearance inspires confidence, the touch is also okay, small jambs of casting only in the area of ​​​​the mounting ears, the sticker is slightly crooked (a tautology, yes!). The wire is soft, the connector fits well on the pins.

Well, now the autopsy:

Who didn’t know how it works: in the case there is a motor, a control board and a variable resistor, based on the position of which the servo determines the angle of the axis.
The gearbox in this servo is plastic, the service life is less than that of a metal one and does not like heavy loads. The bushing for the central axis is copper or some kind of alloy. There is a bearing on the output shaft. Lubricants can be added

Electrical part

Brains that control the direction and speed of rotation, variable speed and electric motor.

And now, attention, a “life hack”, how to turn a regular servo into a constant rotation servo

In the original, the variable with its axis is stuck into the output shaft from inside the servo; in the modified version, the shaft was bitten off/broken off, apparently at the assembly stage, the resistor is set to the central position so that the shaft does not rotate at rest. If you go further, you can throw it out completely and replace it with 2 identical constant resistors; it’s convenient to put something SMD on the control board.

Total:
serva as serva, not space, but not consumer goods either,
can be found cheaper and with a metal gearbox

PS
As correctly noted in the comments, I completely forgot to mention how the servo is controlled; the servo is supplied with 5-6 volts and a ppm signal via the third wire.

The most common control options:
1) connect the power on one side, on the other the output to 3 “consumers” (servers, motors, etc.) power and PPM signal, you can use the handle to adjust the speed and direction of rotation of the servo
2) RC equipment at the receiver outputs is the same ppm signal.
3) steer with an arduino

Video

Pps
As a result of the “modification”, the servo has lost feedback, the brain does not know the real position of the shaft and the direction of rotation, take this point into account if you are going to buy it.

I'm planning to buy +17 Add to favorites I liked the review +31 +56

In this article we will talk about servos in Arduino projects. It is thanks to servo motors that ordinary electronic projects become robotic. Connecting a servo to an Arduino project allows you to respond to sensor signals with some precise movement, for example, open a door or turn sensors in the desired direction. The article discusses the issues of controlling servos, possible schemes connecting servo to Arduino, as well as examples of sketches.

A servo drive is a type of drive that can precisely control motion parameters. In other words, it is a motor that can rotate its shaft through a specific angle or maintain continuous rotation at a precise period.

The servo drive's operating circuit is based on the use of feedback (a closed circuit in which the input and output signals are not matched). The servo drive can be any type of mechanical drive, which includes a sensor and a control unit that automatically maintains all the parameters set on the sensor. The servo drive consists of a motor, a position sensor and a control system. The main task of such devices is implementation in the field of servomechanisms. Also, servo drives are often used in such areas as material processing, production of transport equipment, wood processing, metal sheet production, construction materials production and others.

In Arduino robotics projects, servo is often used for simple mechanical actions:

  • Rotate the rangefinder or other sensors to a certain angle to measure distance in a narrow field of view of the robot.
  • Take a small step with your foot, move your limb or head.
  • To create robotic manipulators.
  • To implement the steering mechanism.
  • Open or close a door, flap or other object.

Of course, the scope of application of servo is real projects much wider, but the examples given are the most popular schemes.

Scheme and types of servos

The operating principle of a servo drive is based on feedback from one or more system signals. The output indicator is fed to the input, where its value is compared with the setting action and the necessary actions are performed - for example, the engine is turned off. The simplest implementation option is a variable resistor, which is controlled by the shaft - when the parameters of the resistor change, the parameters of the current supplying the motor change.

In real servos, the control mechanism is much more complex and uses built-in controller chips. Depending on the type of feedback mechanism used, there are analog And digital servos. The former use something similar to a potentiometer, the latter use controllers.

The entire servo control circuit is located inside the housing, control signals and power are supplied, as a rule, through three wires: ground, supply voltage and control signal.

Continuous rotation servo 360, 180 and 270 degrees

There are two main types of servomotors - with continuous rotation and with a fixed angle (most often, 180 or 270 degrees). The difference between servo limited rotation lies in the mechanical elements of the design that can block the movement of the shaft outside the angles specified by the parameters. Having reached an angle of 180, the shaft will affect the limiter, and it will give a command to turn off the motor. Continuous rotation servomotors do not have such limiters.

Servo gear materials

For most servos, the connecting link between the shaft and external elements is a gear, so it is very important what material it is made of. There are two most affordable options: metal or plastic gears. In more expensive models you can find elements made of carbon fiber and even titanium.


Plastic options are naturally cheaper, easier to manufacture, and are often used in inexpensive servos. For educational projects where the servo makes a few movements, this is not a big deal. But in serious projects, the use of plastic is impossible, due to the very rapid wear of such gears under load.

Metal gears are more reliable, but this, of course, affects both the price and the weight of the model. Thrifty manufacturers can make some parts plastic and some metal, this should also be kept in mind. And, naturally, in the cheapest models, even the presence of a metal gear is not a guarantee of quality.

Titanium or carbon gears are the most preferable option if you are not limited by budget. Lightweight and reliable, such servos are widely used to create models of cars, drones and aircraft.

Advantages of servo motors

The widespread use of servo drives is due to the fact that they have stable operation, high resistance to interference, small size and a wide range of speed control. Important features of servos are the ability to increase power and provide information feedback. And it follows that in the forward direction the circuit is a transmitter of energy, and in the reverse direction it is a transmitter of information that is used to improve control accuracy.

Differences between a servo and a conventional motor

Turning normal on or off Electrical engine, we can generate a rotating motion and make wheels or other objects attached to the shaft move. This movement will be continuous, but in order to understand at what angle the shaft has turned or how many revolutions it has made, you will need to install additional external elements: encoders. The servo drive already contains everything necessary to obtain information about the current rotation parameters and can turn off independently when the shaft rotates to the required angle.

Differences between servo and stepper motor

An important difference between a servo motor and a stepper motor is the ability to work with high accelerations and under variable loads. Also, servo motors have higher power. Stepper motors do not have feedback, so the effect of loss of steps may be observed; in servomotors, loss of steps is excluded - all violations will be recorded and corrected. With all these obvious advantages, servomotors are more expensive devices than stepper motors, have a more complex connection and control system and require more qualified maintenance. It is important to note that stepper motors and servos are not direct competitors - each of these devices has its own specific area of ​​application.

Where to buy popular servos SG90, MG995, MG996

The most affordable servo option SG90 1.6KG Servo drives SG90 and MG90S for Arduino at a price below 70 rubles
Another option for the SG90 Pro 9g servo from a trusted supplier on Ali Servo SG90 from reliable supplier RobotDyn
Servo tester Several options for servo testers
Protected servo drive with a torque of 15 kg Servo JX DC5821LV 21KG Full waterproof Core mental gear 1/8 1/10 RC car Scaler Buggy Crawler TRAXXAS RC4WD TRX-4 SCX10 D90
Servo MG996R MG996 Servo Metal Gear for Futaba JR Servo 13KG 15KG Servos Digital MG995 MG996 MG996R Servo Metal Gear

The decisive factor in controlling servo drives is the control signal, which consists of pulses of constant frequency and variable width. Pulse length is one of the most important parameters that determines the position of the servo. This length can be set in the program manually using the corner selection method or using library commands. For each brand of device, the length may be different.

When the signal enters the control circuit, the generator delivers its pulse, the duration of which is determined using a potentiometer. In another part of the circuit, the duration of the applied signal and the signal from the generator are compared. If these signals are different in duration, the electric motor is turned on, the direction of rotation of which is determined by which of the pulses is shorter. When the pulse lengths are equal, the motor stops.

The standard frequency at which pulses are given is 50 Hz, that is, 1 pulse every 20 milliseconds. At these values, the duration is 1520 microseconds, and the servo is in the middle position. Changing the pulse length leads to rotation of the servo drive - when the duration increases, the rotation is clockwise, and when it decreases, it is rotated counterclockwise. There are duration limits - in Arduino in the Servo library, for 0° the pulse value is set to 544 μs (lower limit), for 180° - 2400 μs (upper limit).

(Image used from amperka.ru)

It is important to consider that on a specific device, the settings may differ slightly from the generally accepted values. For some devices, the average pulse position and width may be 760 µs. All accepted values ​​may also vary slightly due to errors that may occur during the production of the device.

The drive control method is often mistakenly called PWM/PWM, but this is not entirely correct. Control directly depends on the pulse length; the frequency of their occurrence is not so important. Correct operation will be ensured at both 40 Hz and 60 Hz; only a strong decrease or increase in frequency will contribute. If there is a sharp decline, the servo drive will begin to operate jerkily; if the frequency is increased above 100 Hz, the device may overheat. Therefore, it is more correct to call it PDM.

Based on the internal interface, analogue and digital servos can be distinguished. There are no external differences - all the differences are only in the internal electronics. The analog servo drive contains a special chip inside, while the digital servo drive contains a microprocessor that receives and analyzes pulses.

When receiving a signal, the analog servo decides whether or not to change the position and, if necessary, supplies a signal with a frequency of 50 Hz to the motor. During the reaction time (20 ms), external influences may occur that change the position of the servo drive, and the device will not have time to react. A digital servo drive uses a processor that supplies and processes signals at a higher frequency - from 200 Hz, so it can respond faster to external influences and quickly develop the desired speed and torque. Therefore, the digital servo will be better able to hold the set position. At the same time, digital servo drives require more electricity to operate, which increases their cost. The complexity of their production also makes a big contribution to the price. High cost is the only drawback of digital servos; technically, they are much better than analog devices.

Connecting a servo motor to Arduino

The servo drive has three contacts, which are painted in different colors. The brown wire leads to ground, the red wire leads to the +5V power supply, and the orange or yellow wire leads to the signal wire. The device is connected to the Arduino via a breadboard in the manner shown in the figure. The orange wire (signal) is connected to the digital pin, the black and red wires are connected to ground and power, respectively. To control the servomotor, you do not need to connect specifically to shim pins - we have already described the principle of servo control earlier.

It is not recommended to connect powerful servos directly to the board, because... they create a current for the Arduino power circuit that is not compatible with life - you’ll be lucky if the protection works. Most often, the symptoms of overload and improper power supply of the servo are the “jerking” of the servo, an unpleasant sound and the board rebooting. For power supply, it is better to use external sources, be sure to combine the grounds of the two circuits.

Sketch for controlling a servo in Arduino

Controlling a servo directly by changing the pulse duration in the sketch is a rather non-trivial task, but fortunately we have an excellent Servo library built into the Arduino development environment. We will consider all the nuances of programming and working with servos in a separate article. Here we will give simplest example using Servo.

The operating algorithm is simple:

  • First we connect Servo.h
  • Create an object of the Servo class
  • In the setup block we indicate which pin the servo is connected to
  • We use the object's methods in the usual C++ way. The most popular is the write method, to which we supply an integer value in degrees (for a 360 servo these values ​​will be interpreted differently).

An example of a simple sketch for working with a servo drive

An example of a project in which we immediately first set the servo motor to zero angle and then rotate it 90 degrees.

#include Servo servo; // Create an object void setup() ( servo.attach(9); // Indicate to an object of the Servo class that the servo is attached to pin 9 servo1.write(0); // Set the initial position ) void loop() ( servo.write (90); // Rotate the servo 90 degrees delay(1000); servo.write(1800); delay(100); servo.write(90); delay(1000); servo.write(0); delay(1000 ); )

Sketch for two servos

And in this example we work with two servos at once:

#include Servo servo1; // First servo drive Servo servo2; // Second servo void setup() ( servo1.attach(9); // Indicate to the Servo class object that the servo is connected to pin 9 servo2.attach(10); // And this servo is connected to pin 10 ) void loop() ( // Set the positions servo1.write(0); servo2.write(180); delay(20); // Change the positions servo2.write(0); servo1.write(180); )

Servo control using potentiometer

In this example, we rotate the servo depending on the value received from the potentiometer. We read the value and convert it to an angle using the map function:

//Fragment of a standard example of using the Servo library void loop() ( val = analogRead(A0); // Read the value from the pin to which the potentiometer is connected val = map(val, 0, 1023, 0, 180); // Convert the number in the range from 0 to 1023 to the new range - from 0 to 180. servo.write(val); delay(15); )

Characteristics and connection of SG-90

If you are going to buy the cheapest and simplest servo drive, then the SG 90 will be the best option. This servo is most often used to control small, lightweight mechanisms with a rotation angle from 0° to 180°.

SG90 Specifications:

  • Command execution speed 0.12s/60 degrees;
  • Power 4.8V;
  • Operating temperatures from -30C to 60C;
  • Dimensions 3.2 x 1.2 x 3 cm;
  • Weight 9 g.

Description SG90

Wire colors are standard. The servo drive is inexpensive and does not provide precise settings for the start and end positions. In order to avoid unnecessary overloads and the characteristic crackling sound in the 0 and 180 degree position, it is better to set the extreme points at 10° and 170°. When operating the device, it is important to monitor the supply voltage. If this indicator is greatly overestimated, the mechanical elements of the gear mechanisms may be damaged.

Servo drives MG995 and MG996 tower pro

The MG995 servo is the second most popular servo model most often connected to Arduino projects. These are relatively inexpensive servo motors with much better performance than the SG90.

Specifications MG995

The output shaft on the MG995 rotates 120 degrees (60 in each direction), although many sellers indicate 180 degrees. The device is housed in a plastic case.

  • Weight 55 g;
  • Torque 8.5 kg x cm;
  • Speed ​​0.2s/60 degrees (at 4.8V);
  • Working power 4.8 – 7.2V;
  • Operating temperatures – from 0C to -55C.

Description MG995

The connection to the Arduino also occurs via three wires. In principle, for amateur projects it is possible to connect the MG995 directly to the Arduino, but the motor current will always create a dangerous load on the board inputs, so it is still recommended to power the servo separately, not forgetting to connect the ground of both power circuits. Another option that makes life easier would be to use ready-made servo controllers and shields, which we will review in a separate article.

MG996R is similar to MG995 in its characteristics, only it comes in a metal case.

Converting a servo drive into a continuous rotation servo

As described above, the servo is controlled by variable width pulses that set the angle of rotation. The current position is read from the potentiometer. If you disconnect the shaft and the potentiometer, the servomotor will take the position of the potentiometer slide as at the midpoint. All these actions will lead to the removal Feedback. This allows you to control the speed and direction of rotation via the signal wire, and create a continuous rotation servo. It is important to note that a constant rotation servo cannot rotate through a certain angle and make a strictly specified number of revolutions.

To perform the above steps, you will have to disassemble the device and make changes to the design.

In Arduino IDE you need to create a small sketch that will put the rocker in the middle position.

#include Servo myservo; void setup())( myservo.attach(9); myservo.write(90); ) void loop())( )

After this, the device needs to be connected to Arduino. When connected, the servo will begin to rotate. It is necessary to achieve its complete stop by adjusting the resistor. After the rotation stops, you need to find the shaft, pull out the flexible element from it and install it back.

This method has several disadvantages - setting the resistor to a complete stop is unstable; with the slightest shock/heating/cooling, the adjusted zero point may be lost. Therefore, it is better to use the method of replacing the potentiometer with a trimmer. To do this, you need to remove the potentiometer and replace it with a trimmer resistor with the same resistance. The zero point must be adjusted using a calibration sketch.

Any method of converting a servo into a continuous rotation servo has its drawbacks. Firstly, it is difficult to adjust the zero point; any movement can throw it off. Secondly, the control range is small - with a small change in the pulse width, the speed can change significantly. You can expand the range programmatically in Arduino.

Conclusion

Servos play a very important role in many Arduino projects, from robotics to smart home systems. Everything related to movement traditionally requires special knowledge, and creating a full-fledged, properly functioning drive is not an easy task. But with the help of servo motors, the task can be simplified in many cases, which is why servo is constantly used even in entry-level projects.

In this article, we tried to cover various aspects of using servos in Arduino projects: from connecting to writing sketches. By choosing the simplest servo model (for example, sg 90), you can easily repeat the examples given and create your first projects in which something moves and changes. We hope this article will help you with this.

If you find an error, please select a piece of text and press Ctrl+Enter.