In this tutorial, we will learn how to control a Servo Motor with an Arduino. Servo motor is an electrical device that can be used to rotate the objects (like a robotic arm) precisely. It is a rotary actuator or the linear actuator which allows precise control of angular or linear position, velocity, and acceleration.
Servo motor has a rotation angle that varies from 0° to 180°.
In this tutorial, we will cover –
- Testing servo motor.
- Servo Motor speed changing.
- Control the Servo Motor speed by the potentiometer.
- Position Control of Servo Motor Shaft by the potentiometer.
Circuit Diagram For Servo Motor Arduino
|Vcc (Red Wire)
|GND (Brown Wire)
|Control (Orange Wire)
Code for Servo Motor with an Arduino
When the code starts running, the Servo motor rotates from 0° to 180° repeatedly with a pause of half-second from the start position and end position. The servo motor runs with his full speed.
Code for Changing the Servo Motor Speed
The below code is to drive the servo motor in slow motion. By changing the delay time in the “for” loop you can increase or decrease the servo motor speed.
Code for Control the speed of Servo Using Potentiometer
This code is for changing the speed of the servo motor using a potentiometer. By adjusting the potentiometer knob we will control the servo motor speed. The potentiometer will help in changing the delay time which is written in “for” loops in given code.