I tried to change it a little bit so that every time i move the gimbal towards same direction the servo goes +10 each time, but it only goes +10 once and doesnt respond thereafter...what can i change?
// ***------ 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>
//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;
//Attach each servo variable to a pin
void setup() {
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
else if(channel2>1550){
for(int i = 0; posServo1 < 10; posServo1 ++){
servoMotor1.write(posServo1);
i = posServo1;
delay(1);
}
}
delay(100); //Time for Monitoring values
}
Thank it works, i also tried it on AC servo PUL and DIR and it works, but i cannot make it go faster it rotates very slowly, what can i do?
// ***------ 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);
}
if(channel2 < 1450){
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, HIGH);
delayMicroseconds(1);
digitalWrite(stepPin, LOW);
delayMicroseconds(1);
}
}
//Time for Monitoring values
i tried to add channel3, when the left (other) gimbal is above 1550 it increases variable speed and vice versa, but i didnt get it right, what do you think?
// ***------ 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 channel3;
int mSpeed = 0;
//Attach each servo variable to a pin
void StepPulse()
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(1);
digitalWrite(stepPin, LOW);
delayMicroseconds(1);
}
void StepPulse2()
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(1);
digitalWrite(stepPin, LOW);
delayMicroseconds(1);
}
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);
pinMode(8, 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);
channel3 = pulseIn(8, 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(channel3 > 1550) {
for (int s=50; s < ((mSpeed * 2) + 1); s++) {
}
}
if(channel3 < 1450) {
for (int s=50; s < ((mSpeed * 2) + 1); s--) {
}
}
if(channel2 > 1550) {
digitalWrite(dirPin, HIGH);
for (int i=0; i < mSpeed; i++) {
StepPulse();
}
}
if(channel2 < 1450) {
digitalWrite(dirPin, LOW);
for (int i=0; i < mSpeed; i++) {
StepPulse2();
}
}
}
//Time for Monitoring values
only using one motor, i fixed it stepPulse..... channel2 is the one that moves the motor which works great. channel3 changes variable speed, this part isnt working.