Skip to content

Use servo motors with Arduino

 

Hi Everyone, this is a tutorial on how to use the servo motors with Arduino Uno you can check it in the video, here I’m gonna post the wiring and codes I used in the video hope you like it.

Servo motors are used in a lot of projects, so everyone learning how to use Arduino should know how to use one. These motors have a high torque, up to 13 kg-cm depending on the type of motor and the operating voltage, they are mostly known for positioning and robots articulations. Also as we can see in codes used, we make them rotateĀ  by mentioning the position, they have a known angle some are between 0-180Ā° and others 0-360Ā°, once the reach their limit they should return, not like the continuous servo-motors they can rotate freely but they cannot be positioned like this and I’ll do another tutorial on these types of motors.

A variety of servo motors and their attachements. (Courtesy of Sparkfun)



Wiring:

Servo motors have three wires: GND/VCC/Signal, here in this case its powered using Arduino’s 5V, you can use 9V or 12V, but read your Servomotor datasheet first to know its supported voltage, just don’t forget Arduino and the Servo external power source should have common ground.

The Signal pin should be wired with one of Arduino’s PWM pins, they are marked with (~), the PWM signal will determine the Servo rotation angle.

Libraries:

You don’t need to install any new library for the Servo motor, there’s already a built-in one.

Codes:

Here are different codes for different tasks.

Code 1 : Simple write/rotation of the servo motor

Code2 : Sweep mode (taken from the Arduino Servo library)

 



Code 3: Simple code on rotating the servo and keep it in that position, I used it on the video so I decided to write it here too

 

Code 4: How to use the function “detach”

The “detach” function is a bit forgotten, but it turned to be important in some projects I tested with.
When you send a command to a servo motor it stays on that position until you move it by another command, but sometimes you need the servo to have some “free rotation”, this is where the function is handy, it stops the command signal and the servo can be rotated by hand or external mechanism…

 



Code 5: Code to read the postion of the Servo motor, I didn’t use it in the video but here is it, it will be useful in the future

The read function is important as well, sometimes you need to know the servo current position before proceeding to other actions, this function returns the servo current angle.

 

 

Yassine View All

Automation and Electrical Engineer, Electronics amateur trying to share my little projects.

One thought on “Use servo motors with Arduino Leave a comment

Leave a Reply

Discover more from SURTR TECHNOLOGY

Subscribe now to keep reading and get access to the full archive.

Continue reading