What is Servo?
Servo is a general term for a closed loop control system.
A closed loop system uses a feedback signal to adjust the speed and direction of an engine and to achieve the desired result, for example placing the engine in a specific position.
There are servomotors on the market of many types and sizes, here we refer to those used in modeling and robotics. These servomotors also operate on the above principle. They contain a small DC motor connected to the output shaft via the gears, ie a mechanical gearbox, to ensure high torque with a few turns on the servomotor. The output shaft moves an arm that is connected to a potentiometer (pot) which is part of the electronic control circuit (servo driver). The following figure shows the operating diagram of a servomotor.
Schematic diagram of a servomotor
The potentiometer provides position feedback to the control unit where the current position of the motor is compared to the target position.
According to the error, the control unit corrects the actual position of the engine so that it matches the target position.
Internal servomotor
How the servomotor works
In the figure you can see a servomotor. It is connected to three conductors. The GND ground, the 5V voltage which is usually 5 to 7 volts, and the control which is the control signal.
Servo motor connection
You can control the servomotor by sending a series of pulses to the control line. A conventional analog servomotor, such as e.g. the MG995 expects to receive a pulse approximately every 20 milliseconds (ie the signal must be at 50Hz).
The pulse length (Duty Cycle) determines the position of the servomotor. The following figure shows the position of the motor in relation to the control signal.
Servo motor drive
Application
It's time to see how a servomotor connects and works.
You will need some materials:
1. A servomotor e.g. MG995
Servo motor MG995
2. An Arduino UNO board or compatible
Arduino UNO
3. An empty Arduino UNO board on which the connections will be made and then fastened to the Arduino board.
Arduino Sield
4. A 5-7V DC power supply to power the servomotor.
5. A 10K potentiometer
You will also need some tools (soldering iron, etc.), a few meters of thin cable and a little construction experience.
To program and operate the system you must have the Ardouino IDE installed and have little experience with it. Both hardware and software are OPEN, see
https://en.wikipedia.org/wiki/Open_top_material
https://en.wikipedia.org/wiki/Open_Software
Construction
On the blank Arduino UNO board I make the connection circuit of the materials. An example of wiring can be seen at https://www.arduino.cc/en/Tutorial/Knob in which I have made the necessary modifications.
In the photo below you can see the construction is finished. Here I use two servomotors and two potentiometers, because the construction has future use. The servomotors are positioned so that the movements take place in two planes perpendicular to each other. We will use this detail in our next construction.
At the end of your article I have a video where you see the construction in operation.
Each potentiometer has three pins. The two ends are connected to the GND ground and to the 5V respectively. Depending on the rotation position of the potentiometer, the medium will have a potential between 0 and 5V. The middle pin of the potentiometer is connected to the analog input A0 of the Arduino. The values that the program will read for input A0 will be between 0 and 1023.
The servomotive usually needs more power than this can be given by the power supply of the Arduino from a USB port. For this reason we use the additional power supply. The ground of this power supply will be connected to the Arduino GND. It will be good to connect a 1000μF capacitor between the ground and the positive of the power supply, which will ensure the high current requirement when starting the motor.
Servomotors have three cables: current, ground and signal. The power cord is usually red and should be plugged into the 5-7V of the power supply. The ground wire is usually black or brown and should be connected to a ground pin on the Arduino board. The signal pin is usually yellow, orange or white and should be connected to a digital pin on the Arduino board. In our construction it will be connected to the digital pin 4.
Programming
The program I present to you moves two servomotors using two potentiometers as shown in the video. The construction was done with two servomotors because it will be used in the next experiment.
Arduino UNO enables PWM signal generation on pins 3,5,6,9,10 and 11. We use the Servo.h library to simplify programming for PWM signal output, also in the way it handles the library producing PWM signal we can use all digital pins to generate PWM signal.
/*
έλεγχος της θέσης δύο σερβοκινητήρων με τη χρήση δύο μεταβλητών αντιστάσεων – ποτενσιομέτρων
Μανώλης Αριστοβουλίδης 10/2021
*/
#include <Servo.h>
Servo servo1; // δημιουργία ενός servo object για τον έλεγχο του servo
Servo servo2;
int potpin1 = A0; // αναλογικό pin για τη σύνδεση ποτενσιομέτρου
int potpin2 = A1; // αναλογικό pin για τη σύνδεση ποτενσιομέτρου
int val1; // μεταβλητή για την ανάγνωση της τιμής του αναλογικό pin
int val2; // μεταβλητή για την ανάγνωση της τιμής του αναλογικό pin
void setup() {
servo1.attach(4); // κάνει προσάρτηση του servo στο pin 4 του servo object
servo2.attach(5); //κάνει προσάρτηση του servo στο pin 5 του servo object
Serial.begin(9600); //αρχικοποιεί τη σειριακή επικοινωνία
}
void loop() {
val1 = analogRead(potpin1); // διαβάζει την αναλογική τιμή (τιμές μεταξύ 0 και 1023)
val2 = analogRead(potpin2); // διαβάζει την αναλογική τιμή (τιμές μεταξύ 0 και 1023)
val1 = map(val1, 0, 1023, 0, 180); // μεταροπή σε κλίμακα για το servo (τιμές μεταξύ 0 και 180)
val2 = map(val2, 0, 1023, 0, 180); // μεταροπή σε κλίμακα για το servo (τιμές μεταξύ 0 και 180)
servo1.write(val1); // ρυθμίζει τη θέση του servo στην τιμή της κλίμακας
servo2.write(val2); // ρυθμίζει τη θέση του servo στην τιμή της κλίμακας
Serial.print("val1 : ");
Serial.print(val1);
Serial.print(" - val2 : ");
Serial.println(val2);
delay(20); // περιμένει για την ολοκλήρωση της κίνησης του servo
}
The code can be downloaded here http://www.avlos.gr/index.php/el/lipsis/download/16-servo-knob
In the video that follows you can see the mechanism in operation https://youtu.be/BCxv9VGqhQk






