We note in the specification that the operating voltage is 4.8 V - 5.0 V, it is enough to operate it with the microcontroller.
What we also need is to know about the pinout and to know where each pin goes on the microcontroller, from the datasheet
there are three main pins on the servo:
The PWM pin: which should be connected to the digital pwm pin on the microcontroller,
The VCC: must be connected to the power pin and must be in the range of 4.6V to 6.0V
The GND: This is the ground pin.
Part |
Description |
Feature |
Manufacture |
Datasheet |
SG90 |
Micro Servo |
SG90 9 g Micro Servo Tiny and lightweigh t with high output power.
Servo can rot ate approximately 180 degrees (90 in ea ch direction), and works just like the standard kinds but smaller.
You can use any servo code, hardware or library to control these servos.
Good for beginne rs who want to make stuff move without building a motor controller with feedba ck & gear box, especially since it will fit in small places.
It comes with a 3 horns (arms) and hardware.
Specificati ons
• Weight: 9 g
• Dimension: 22.
2 x 11.
8 x 31 mm approx.
• Stall torqu e: 1.
8 kgf·cm
• Operating speed: 0.
1 s/60 degree
• Operatin . |
Tower Pro |
Download SG90 Datasheet |
Using the test code
I will use the example found in Arduino to test the servo motor:
Master Ulises Gordillo, one of the great instructors, showed us the use of the code, I learned something new for me in terms of programming the servomotor
#include is used to call the servo library that allows an Arduino board to control RC (hobby) servo motors.
myservo.attach(pin) The syntax is used to declare the pin number the servo motor is attached to.
myservo.write()The syntax is used to control the axis of the motor and set the angle.
What I do first is look under "examples" for the programming code for the servomotor in the arduino menu. Then I compiled and ran.
First I do the simulation in TINKERCAD
Testing the operation of the Servomotor
I wanted to test the operation of the servomotor with the arduino UNO to make sure it works well before doing it with my electronic board.
Now it was the turn of my Attiny 85, I connected it to be able to record the arduino code for the servomotor.