Ornithopter RC Control
This Instructable will explain how to build the electronics of a remote-controlled ornithopter (with a forked-tail steering mechanism). I've attached a few rough designs of how one might build the ornithopter itself, and the details regarding the steering mechanism. However, this instructable focuses only on the electronics, not the ornithopter itself. Note that these instructions could, with perhaps a few modifications, work for any other RC machine that uses two-servo steering and a larger main DC motor for locomotion.
Supplies
- Arduino Uno (1)
- Arduino Nano (1)
- RF Modules (1 pair; transmitter and receiver)
- Joystick (1)
- 4200 KV Brushless Outrunner Motor (1)
- ESC (with correct specifications for motor) (1)
- 9g Servos (2)
- Potentiometer (1)
- 2s 7.4V 800mAh LiPo Battery (1)
- Wires
Note: Many of these supplies can be bought together in an Arduino starter kit.
Wiring
I included breadboards on both to make the wiring simpler to follow. However, you might want to wire the receiver directly (without a breadboard) in order to minimize weight on the ornithopter.
Also, the fritzing diagram for the receiver uses an Arduino uno. When wiring the actual ornithopter, use an Arduino nano (again, to minimize weight). The wiring should be exactly the same—refer to the image of the labeled Arduino nano pins to convert from the Arduino uno instructions to Arduino nano.
Code
This code was written with Arduino IDE 1.0.4.
Make sure to install the correct libraries before running the code.
Transmitter:
#include
const int numberOfAnalogPins = 4;
int data[numberOfAnalogPins];
const int dataBytes = numberOfAnalogPins * sizeof(int);
void setup() {
// pinMode(13, OUTPUT);
// Initialize the IO and ISR
vw_set_ptt_inverted(true);
vw_setup(2000);
}
void loop() {
int values = 0;
// digitalWrite(13, HIGH);
for(int i=0; i <= numberOfAnalogPins; i++) {
data[i] = analogRead(i);
}
send((byte*)data, dataBytes);
delay(10);
//digitalWrite(13, LOW);
}
void send (byte *data, int nbrOfBytes) {
vw_send(data, nbrOfBytes);
vw_wait_tx();
}
Receiver:
#include <SoftwareServo.h>
#include <SoftwareSerial.h>
#include <VirtualWire.h>
#include <ServoTimer2.h>
ServoTimer2 myservo1;
SoftwareServo myservo2;
SoftwareServo myservo3;
SoftwareServo myservo4;
const int numberOfAnalogPins = 4;
int data[numberOfAnalogPins];
int value[numberOfAnalogPins];
const int dataBytes = numberOfAnalogPins * sizeof(int);
byte msgLength = dataBytes;
void setup() {
myservo1.attach(9); //Flapping (main motor)
myservo3.attach(8); // Left Elevator
myservo4.attach(12); // Right Elevator
Serial.begin(9600);
#ifdef DEBUG_MODE
Serial.println("Ready");
#endif
=
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_rx_pin(11);
vw_rx_start();
}
void loop(){
if (vw_get_message((byte*)data, &msgLength)) {
#ifdef DEBUG_MODE
Serial.println("Got: ");
#endif
if(msgLength == dataBytes){
for (int i = 1; i < numberOfAnalogPins; i++) {
#ifdef DEBUG_MODE
Serial.print("pin ");
Serial.print(i);
Serial.print("=");
Serial.println(data[i]);
#endif
value[0]=map(data[0],0,1023,1000,2000);
value[i]=map(data[i],0,1023,0,179);
}
myservo1.write(value[0]);
myservo2.write(value[1]);
myservo3.write(value[2]);
myservo4.write(value[3]);
delay(50);
SoftwareServo::refresh();
}
else {
#ifdef DEBUG_MODE
Serial.print("unexpected msg length of ");
Serial.println(msgLength);
#endif
}
#ifdef DEBUG_MODE
Serial.println();
#endif
}
}
Running
Upload the code to both Arduinos.
Make sure to look up the setup instructions for the transmitter/receiver you buy, then follow these instructions to connect them.
Use an adaptor suited to your battery to connect power (5V on the Arduino) on the receiver to the LiPo battery.
Once the transmitter and receiver are connected, you should be able to move the joystick and potentiometer, and see how the servos and motor move.
Adjust the code to get the servos and motor to move at the speeds you need them to.