Arduino - Servo motor control rotation with Variable Resistor

A servomotor is a rotary actuator that allows for precise control of angular position, velocity and acceleration. It consists of a suitable motor coupled to a sensor for position feedback. It also requires a relatively sophisticated controller, often a dedicated module designed specifically for use with servomotors.



Potentiometer or Variable Resistor
This is a three-terminal resistor with a sliding contact that forms an adjustable voltage divider.


Towerpro MG996R 10kg Servo Motor, 55g / 10kg / .20sec
This is essentially an upgraded version of the famous towerpro MG995 servo. It now has a redesigned PCB and IC controll system which makes it far more accurate. Its internal gearing and motor are also upgraded to improve dead bandwith and centering.
All specifications are the same as the previous model MG995, however this servo is far more accurate, and safe to use in aircraft which require precise servo movements and perfect centering.

Weight- 55g
Dimension 40.7*19.7*42.9mm
Stall torque 10kg/cm
Operating speed 0.20sec/60degree(4.8v)
Operating voltage 4.8-7.2V
Temperature range 0_ 55
Servo Plug: JR (Fits JR and Futaba)


Why I choose MG-966R Servo motor? because it's use metallic gear.



Watch the video of the finished result


/*
* Date: 2014-04-12
* Author: Yongjie Huang
* Email: yongjie989@gmail.com
* Purpose: Control Servo motor using Arduino UNO
* Requirement:
* - Arduino uNO R3
* - MG-996R Servo Motor, 4.8V - 6V
*/
// Include the Servo Library.
#include <Servo.h> 

// Create the Servo instance.
Servo myservo; 
 
// Tell Arduino the VR is connection in Analog PIN 0 
int VRPIN = 0;
// This variable is should be to store the VR value when to read from "ANALOG IN" PIN 0.
int val;
 
void setup(){ 
  // Tell Arduino know our Servo PWM port is connection in "DIGTAL (PWM)" PIN 2.
  myservo.attach(2);
} 
 
void loop() { 
  // Read analog value from VR  
  val = analogRead(VRPIN);
  // Using map() function to mapping 0-1023 to 0-179 position. 
  // Why 0-179 (180)? because our Servo just can rotation from 0 to 180 degree. NOTICE: NOT 0-360 DEGREE. 
  val = map(val, 0, 1023, 0, 179);
  // Tell the Servo to rotation.
  myservo.write(val);
  // Waiting for Servo to action.
  delay(10);
} 

Comments

Popular Posts