Difference between revisions of "The Use of Servo"
(5 intermediate revisions by one other user not shown) | |||
Line 21: | Line 21: | ||
*Tech parameters | *Tech parameters | ||
**Torsion: 1.6kg-cm/4.8V &1.8kg-cm/6.0V | **Torsion: 1.6kg-cm/4.8V &1.8kg-cm/6.0V | ||
− | **Speed:0.11sec/60°4.8V & 0.10sec/60° 6.0V | + | **Speed: 0.11sec/60°4.8V & 0.10sec/60° 6.0V |
*Size | *Size | ||
**Board size: 22.4mm*12.5mm*22.8mm | **Board size: 22.4mm*12.5mm*22.8mm | ||
Line 49: | Line 49: | ||
===Preparation=== | ===Preparation=== | ||
− | *Setup | + | *Setup 1: Connect Microduino-Servo Connector and the servo together to the last row of pins. |
[[file:mCookie-Servo Connector-sensor.JPG|600px|center]] | [[file:mCookie-Servo Connector-sensor.JPG|600px|center]] | ||
− | *Setup | + | *Setup 2: Connect the Microduino-Servo Connector and the Hub's analog port IIC. |
[[file:mCookie-Servo Connector-hub.JPG|600px|center]] | [[file:mCookie-Servo Connector-hub.JPG|600px|center]] | ||
− | *Setup | + | *Setup 3: Connect all equipment to the computer with a USB cable. |
[[file:mCookie-Light-pc.JPG|600px|center]] | [[file:mCookie-Light-pc.JPG|600px|center]] | ||
Line 93: | Line 93: | ||
===Program Debugging === | ===Program Debugging === | ||
− | * | + | *Utilizes the Servo driving library in Arduino (you can find Servo.h files here). |
− | * | + | *Defines the pin(servo_pin) driving the servo in the "setup" function with "myservo.attach(servo_pin);" |
− | * | + | *Commands the servo to rotate to a specified angle(pos) using the function "myservo.write(pos);" |
− | * | + | *Use a "for" loop to implement automatic angle changes. The value of variable pos in the "for" loop is within 0-180, which can be changed by users. |
− | * | + | *Use the "delay" function to control rotation speed, which also can be changed by users to see different results. |
+ | |||
===Experiment One: Drive the Servo === | ===Experiment One: Drive the Servo === | ||
* Open Arduino IDE and copy the following code into IDE. | * Open Arduino IDE and copy the following code into IDE. | ||
Line 137: | Line 138: | ||
} | } | ||
</source> | </source> | ||
− | * Select the | + | * Select the correct port from (Tools)→(Serial Port) in Arduino IDE after compiling and then upload the program. |
[[file:upload.JPG|500px|center]] | [[file:upload.JPG|500px|center]] | ||
− | *Open the serial monitor after | + | *Open the serial monitor after uploading and enter any angle(0-180) in the serial input box, then click "Send". |
[[file:serial-.JPG|500px|center]] | [[file:serial-.JPG|500px|center]] | ||
− | *Result: You can precisely control rotation angle of the servo | + | *Result: You can precisely control the rotation angle of the servo using the serial port. |
===Program Debugging=== | ===Program Debugging=== | ||
− | *Serial port receives data and | + | *Serial port receives data and "translates" it into a character string. |
<source lang="cpp"> | <source lang="cpp"> | ||
while (Serial.available() > 0) | while (Serial.available() > 0) | ||
Line 160: | Line 161: | ||
} | } | ||
</source> | </source> | ||
− | *Since the data of the character string keeps | + | *Since the data of the character string keeps accumulating, it needs to clear previous data every time it receives new data using "" inString = ""; |
+ | |||
==Application== | ==Application== | ||
Latest revision as of 06:45, 30 September 2016
ContentsOverviewUnlike ordinary motor steering gear that will only turn around, servo can rotate according to your instructions to any 0-180 DEG or stop. So it is also called the servo motor, mainly constituted by shell, circuit board, non-core motor, gear and position detector. PrincipleIt starts from the controller sending signal to the servo, getting through the circuit board chip to judge the direction of rotation, and then driving the non-core motor to rotate. The power is transmitted to the swing arm through the reduction gear while sending back signal by a position detector to judge whether it has already reached the location. The position detector is actually a variable resistance. When the servo rotates, the resistance values will be changed accordingly. By detecting the resistance values, you can know the angle of rotation. AttentionThe steering angle is within 0 -180 degrees. When the high level pulse is greater than 2.5ms, for a steering gear that has no self protection function, it'll usually cause the angle beyond the normal range. In that case, the internal DC motor will be in the stall state. In one or two minutes, it will cause the servo burning. When using it, please let it rotate among 45 degrees to 135 degrees as far as possible. Within the range, the steering angle is also more accurate. Servo Connector
SpecificationServo
Servo Connector
DevelopmentEquipment
Preparation
Experiment One: Drive the Servo
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
#define servo_pin SDA
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(servo_pin); // attaches the servo on pin SDA to the servo object
}
void loop()
{
for (pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Program Debugging
Experiment One: Drive the Servo
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
#define servo_pin SDA
String inString = "";
int pos = 0; // variable to store the servo position
void setup()
{
Serial.begin(9600);
myservo.attach(servo_pin); // attaches the servo on pin 9 to the servo object
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
}
void loop()
{
while (Serial.available() > 0)
{
inString += char(Serial.read());
delay(2);
}
if (inString.length() > 0)
{
myservo.write(inString.toInt());
Serial.println(inString.toInt());
}
inString = "";
}
Program Debugging
while (Serial.available() > 0)
{
inString += char(Serial.read());
delay(2);
}
if (inString.length() > 0)
{
myservo.write(inString.toInt());
Serial.println(inString.toInt());
}
ApplicationVideo |