My friend is a model maker of RC helicopters.
For about forty years he has been building helicopters that are big, and I find it amazing how he can make them fly. However, he has no experience in Arduino and asked my help for a specific project that he’s making.
He needs to have a stabilized camera and the rear black headlight mounted on the helicopter move with a specific rotation angle and loop when a command on the analog remote control is activated.
Specifically, we would need to connect one channel of a Futaba RC Receiver so that, by operating the channels in question from a switch on the Radio Transmitter and only then, the servo control connected to that channel starts to make a series of preset movements on Arduino, until it is always deactivated by the same switch.
More precisely:
- channel 1 switch in position 1: servo stopped in initial position with light OFF
- channel 1 switch in position 2: switch on the led light (search light)
- channel 1 switch in position 3: servo starts the movement with light ON
So we managed to get both in a room and while my friend was explaining what the servo needed to do, I was coding on the Arduino IDE.
At the end the result was done and we are here to share it with whoever may be interested.
/* Carlo Stramaglia 10 October 2021
* Code for driving a servo motor using an analog model remote conrol
*
* look at my youtube channel https://www.youtube.com/c/CarloStramaglia
*/
#include<Servo.h>
Servo servo1;
int angle=15;
int ch1;
int val1;
void setup() {
pinMode(6, INPUT); // Receiver channel 1 PIN input connection to Arduino
pinMode(2, OUTPUT); // Arduino output for LED light
pinMode(13, OUTPUT); // Internal Arduino led for debug purpose
digitalWrite(2, LOW);
digitalWrite(13, LOW);
servo1.attach(8); // Servo PIN connection on the Arduino
servo1.write(15); // Go to home position at 15 degrees
Serial.begin(9600);
}
void loop() {
ch1 = pulseIn(6, HIGH, 25000); //Configuration of the plseIN on PIN 6
if (ch1 > 1400 and ch1 < 1500){
digitalWrite(2, HIGH);
digitalWrite(13, HIGH);
}
else if (ch1 > 1900) {
digitalWrite(2, LOW);
digitalWrite(13, LOW);
//servo1.write(0);
}
else if (ch1 > 900 and ch1 < 1000) {
digitalWrite(2, HIGH);
digitalWrite(13, HIGH);
for (angle=15 ; angle <= 130; angle +=1) {
servo1.write(angle);
delay (40);
}
for (angle=130 ; angle >= 40; angle -=1) {
servo1.write(angle);
delay (40);
}
for (angle=40 ; angle <= 179; angle +=1) {
servo1.write(angle);
delay (40);
}
for (angle=179 ; angle >= 15; angle -=1) {
servo1.write(angle);
delay (40);
}
}
}