![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkLx_Jl6WgolatneMW9eukp8DncXjbbthk0ElyL2t9zo7dOfrF9UfwVwYwEY_KjSgPG57s2E545xAEEIoGfBsX1wOaP50kYXmG6RQq9IF_1kEmtpW9ktZcMztcrcyK_OTLTZDkN8XKasY9/w400/ArduinoServoMotorControl_sm.png)
Arduino USB Control Servo Motor
Use Arduino Board to control Servo Motor.
Hardware
1. Arduino Board or compatible Board.
2. USB Cable ( A to B Male/Male )
3. Servo Motor ( We use FUTABA Model S3003 or other)
Arduino Code Download code Link
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int motor = 0;
void setup()
{
Serial.begin(9600); // initialize serial:
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.print("Arduino control Servo Motor Connected OK");
Serial.print('\n');
}
void loop()
{
// if there's any serial available, read it:
while(Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
motor = Serial.parseInt();
// do it again:
pos = Serial.parseInt();
// look for the newline. That's the end of your sentence:
if (Serial.read() == '\n') {
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
// print the three numbers in one string as hexadecimal:
Serial.print("Data Response : ");
Serial.print(motor, DEC);
Serial.print(pos, DEC);
}
}
}
//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>=1; 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
//}
//val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
//val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
//myservo.write(val); // sets the servo position according to the scaled value
//delay(15);
Program Arduino Code to Arduino Board
Video : How to upload Arduino Code
Open Arduino Program.
File Menu - Open
Select ServoControl.ino code
Verify code
Upload to Arduino Board
Command Control Testing
Command Control a,bbb < Enter> (a = Servo Motor = 1 , bbb = degree = 0-180 )
If you to control position to 90 degree.
Sent 1,90 <Enter> to Arduino Board.
Use Tools - Serial Monitor on Arduino Program.
Tools - Serial Monitor
If connect to Arduino Board. Serial Monitor response "Arduino control Servo Motor Connected OK"
Sent Command 1,90 <Enter> to set Servo Position to 90 degree.
Data Response : 15A
Use Android + Arduino controls Servo Motor
http://androidcontrol.blogspot.com/2014/01/arduino-servo-motor-control.html
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZYJAFdv6fnKAF9cdc0VRUb1nNqVpHg6etbd3sT_Rip4YFRAaIU4VnF99Kan0X3IX78-0yfOJEQUlx9-za0mSo0ZejaWozrbvP0pdaUgeM5UZ1kNAPLCW_liWsZfRT5oW_q-bbreIEJzVl/s1600/Google-Play-Badge.png)