We just need to define the pin to which the servo is connect, define that pin as an output, and in the loop section generate pulses with the specific duration and frequency as we explained earlier. Now let’s take a look at the Arduino code for controlling the servo motor. The Servo MIN_VALUE and MAX_VALUE can be adjusted to avoid hitting the servo stops Uses built-in Servo.h library */ #include "Servo.h" #define SERVO_PIN 9 // Can use any PWM pin #define POT_PIN A0 // Can use any analog pin #define MIN_VALUE 0 // Minimum Servo position #define MAX_VALUE 180 // Maximum Servo position Servo servo // creates servo object used to control the servo motor int value_pot = 0 // Current value of the potentiometer int value_servo = 0 // Current servo position int value_servo_old = 0 // Used to hold old servo value to look for change.See Also Arduino Brushless Motor Control Tutorial | ESC | BLDC Servo Motor Control Arduino Code Servo Motor Micro SG90 Test Program /* Exercise Servo motor Use a potentiometer on pin A0 to command a servo attached to pin 9 to move to a specific position. The constants MIN_VALUE and MAX_VALUE are used to set the 2 end-points in the program below. This setup can also be used to determine the limits of the servos range by running the servo near its end-points and observing where it mechanically stops relative to the position command that is being issued. The program below can be used to exercise a servo motor by using a potentiometer to set the position of the servo. By placing a fairly large electrolytic cap of around 470-1000uF across the power and ground on the breadboard, that will help to insulate the Arduino from some of the power surges of the motor. If you do decide to run it directly off the Arduino, you can help avoid most problems by running the power and ground from the Arduino over to a breadboard and then to the servo. It is always better to drive them directly off of a power supply rather than trying to power from the on-board Arduino regulator whenever possible One SG90 can typically be driven off the power pin of an Arduino when experimenting, but motors in general are electrically noisy and power hungry devices. Current draw can get up to a maximum of 360mA under a stall condition. The servo runs on 5V with a current draw about 10mA at idle and 100mA to 250mA when being commanded to move depending on how it is being operated. We also didn’t have any issues with stripping the nylon gears when pushed to their max. ![]() In our testing these servos can lift about 3.75lbs that is positioned on an arm 1cm out from the shaft, so they are actually fairly strong little motors. The built-in cable has a 3-pin female connector that is usually mated with a standard 0.1″ male header Pulses with values between these can be used to position the shaft arbitrarily. A 2 mSec pulse positions the shaft at 180 degrees. A 1.5mSec pulse positions the shaft at 90 degrees (centered in its range). A 1mSec pulse positions the shaft at 0 degrees. The pulse can vary between 1mSec and 2mSec. The pulse is active HIGH and the width of the pulse determines the position (angle) of the servos shaft. Servos expect to see a pulse on their PWM pin every 20 mSec. This causes a high stall current condition and has the potential of stripping gears and damaging the motor, so it is best to either drive it to a safely reduced range such as 20-160 or experiment a bit to determine the actual usable range if you want to maximize the range. If the motor is run all the way to 0 or 180, it may start making unhappy sounds and start vibrating as it tries to drive to a position that it cannot get to. Frequently the actual range is less than the full 180 degrees and is limited by the mechanical gears and potentiometer used for position sensing that is contained in the device. This is usually specified as 180 degrees. Standard servos have a specified limited range. ![]() Servo motors are comprised of a DC motor, gears, a potentiometer to determine its position and a small electronic control board. Servo motors can be commanded to go to a specific position and so are the usual go-to motor when accurate positioning is needed, such as for turning the front wheels on an RC model for steering or pivoting a sensor to look around on a robotic vehicle. Gears are nylon which is the case with most lower cost Servos. The Servo Motor Micro SG90 work well for basic servo experimentation and can be used in applications where small size is a virtue and that don’t require a huge amount of torque, but they are still pretty strong. Can lift 3.75lb positioned 1cm from center of shaft.Screws for mounting arms to the servo and mounting the servo.3 arms/horns for various interface applications.1 SG90 Servo motor with attached 9.5″ control cable.The Servo Motor Micro SG90 is a very common and inexpensive servo in a compact micro size package.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |