tutorial:
Hi, this tutorial taught me how to move servo through RC radio via arduino....then i was able to move an AC servo that uses PUL and DIR, but it rotates very slowly, what can i fix to make it go fast....
// ***------ RC Servo control -----***
// ***---- K. Michalsky / 2015 ----***
//Arduino Pins
// Pin7 to channel2 of receiver
// Pin9 to Signal of Servo1
//Include Servo library.The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega.
#include <Servo.h>
#define dirPin 2
#define stepPin 3
//Create servo objects to control the servo motors
//Servo servoMotor1;
//Define variables for the position of the servos
//int posServo1 = 0;
//Define a variable for the channel of the Receiver with which you want to control the servos, in this case channel2 (ailerons channel from my receiver)
int channel2;
int mSpeed = 0;
//Attach each servo variable to a pin
void setup() {
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
// Set the spinning direction CW/CCW:
digitalWrite(dirPin, HIGH);
//servoMotor1.attach(9); //Servo1 attached to pin 9
//Define the input Pin for the Receiver
pinMode(7, INPUT);
Serial.begin(9600); //Serial comunication for later monitoring of channel signal value
}
void loop() {
//Read the pulse from Pin7 either HIGH or LOW
channel2 = pulseIn(7, HIGH);
//Monitor channel value
Serial.print("Channel 2:");
Serial.println(channel2);
//Define a range of the channel value to center the servo when the stick of the transmiter is centered. This range can variate depending on which servos and Transmiter you are using. Servos are centered at 90 degrees
//if((channel2 >= 1450) && (channel2 <= 1550)){
//posServo1 = 0;
//servoMotor1.write(posServo1);
//}
//If the channel value is bigger than the highest value of the range do following
if(channel2 > 1550){
digitalWrite(dirPin, HIGH);
digitalWrite(stepPin, HIGH);
delayMicroseconds(1);
digitalWrite(stepPin, LOW);
delayMicroseconds(1);
}
delayMicroseconds(1);
if(channel2 < 1450){
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, HIGH);
delayMicroseconds(1);
digitalWrite(stepPin, LOW);
delayMicroseconds(1);
}
}
//Time for Monitoring values