[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4756: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3891)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4758: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3891)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4759: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3891)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4760: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3891)
Hacker.instanet.net • View topic - Hobby Servo

Hobby Servo

Anything Arduino

Hobby Servo

Postby Tim Laren » Fri Sep 21, 2012 12:29 am

Image
The Hobby Servo is a device that provides us with motion control and is easy to control with the Arduino. The servos come in all different sizes, power and use a common control method. They were originally designed for Radio Control airplanes and now used in all remote controlled hobby devices and robots.
The Hobby Servo contains a motor, gears, shaft, shaft position sensor and drive electronics. Most Hobby Servos run on 6 Volts DC but operate just fine on 5 Volts also. If we look at the specs then you will see they are a little slower and cannot push as hard on 5 Volts as with 6 Volts. The servo requires + power, ground and a control signal. We send a signal over the control line to tell the servo what position we want the shaft to be in and the electronics use the shaft sensor detects the shafts current position of the shaft. Then the electronics power the motor to correct any error in the current position compared to the requested position. Once the shaft sensor detects that the shaft is in the requested position then the electronics hold the motor in that position.
The SG90 is a Micro Servo that is very small and provides 9 Grams of torque.
The control signal to the servo required a special pulse to be repeated at a minimum of once every 40ms but typically every 10 to 20ms. This pulse has a width of 1 to 2ms. At 1ms the shaft is positioned at 0 degrees. With a pulse of 2ms the shaft will be at 180 degrees. When the pulse is at 1.5ms the shaft will be at the 90 degrees position.
Image
This pulse is called Pulse Width Modulation or PWM signal for short. The Arduino has many PWM pins and we can use the Analog Write command to control them.
Image
The only problem is the Analog Write creates a PWM signal that goes from 0% to 100% duty cycle that is not compatible with the servo control line. Luckily there is a library included with the Arduino IDE that supports the Hobby Servo. The library is the Servo library and we include it using the following:
#include <Servo.h>
First we will need to connect the servo to our Arduino. For this ‘test’ we can power it from the Arduino. Because the servo has a motor that can draw a lot of current, when we actually use the servo to do work we will want to power it from a separate power supply and not from the Arduino. The regular on the Arduino can only supply about 500 mA for the Arduino and everything you connect to it.
Make sure that the Arduino is not powered up and disconnected from the computer first before connecting your wires as follows. Connect the Black (Brown) wire of the servo to the GND pin of the Arduino. Connect the Red wire from the servo to the 5V pin of the Arduino. The sample sketch used pin 9 as the control signal to the servo so we will connect the Orange (Yellow) wire from the servo the pin 9 of the Arduino.
Image
This is the example code that is included with the Arduino IDE and can be loaded by selecting File -->Examples-->Servo-->Sweep.
Connect the Arduino to your computer and load the sketch and click RUN. After the sketch loads the servo should start sweeping back and forth. If all works as expected then we can modify the values in the sketch. The example moves the servo arm from 0 degrees to 180 degrees and then back to 0 degrees. Change it to go from 45 degrees to 135 degrees. You can also change the delay and make the servo move faster or slower.
If you want you can wire up the second servo and control the both of them at one time. You will have to add in the attach command for the second servo. You will also have to wire both servos to a power source other than the Arduino. Remember to connect the Arduino to the common ground of the servo power supply as it is required as a reference for the control signal.
Also see my article about making a Halloween animation for your home using a servo, UNO and some miscellaneous art supplies.
At:
Image
Tim Laren
Site Admin
 
Posts: 137
Joined: Thu Mar 04, 2010 8:25 pm

Return to Arduino

Who is online

Users browsing this forum: No registered users and 2 guests

cron