Ornithopter RC Control

by ser08040421 in Circuits > Arduino

592 Views, 2 Favorites, 0 Comments

Ornithopter RC Control

3092C1DE-4D6A-4829-B425-5D877406AA0E.jpeg
13C1A885-0464-4470-95A2-AA093ADC6D14.jpeg
C55FF098-50B8-4BA5-9E0F-7C3B6BFC47C0.jpeg
B820AA4D-BEEA-4869-8194-C9383D5EAF06.jpeg
E34F4454-40A3-4526-9A3E-32FA50004B71.jpeg
CD77E44E-BA70-479A-BFA4-9160056F6182.jpeg
32CF6BA0-7B87-418F-8ED3-99DF0A349898.jpeg

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

Note: Many of these supplies can be bought together in an Arduino starter kit.

Wiring

61CA6B3C-C8AF-4EF1-8602-1458F428DB68.jpeg
626A991B-D93D-496D-9562-DCF9F8C33DD1.jpeg
31EB926F-14BE-4896-BF8D-31E13CE78213.jpeg
3154D078-CC62-4FE4-876E-5FC3AFDB0112.jpeg
CC77B860-5B24-4CCF-B290-57B734B1D1D3.jpeg
See fritzing diagrams for exact wiring of receiver and transmitter.

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

5AC65856-911E-44DD-A559-D2C58D80F31B.png
62711268-F25F-4C62-AEEE-2DE5F3F7C537.png
C8EBF772-41E1-4DDD-B8BA-D71A1246F1D3.png
B3A0B242-F174-49E7-B698-54CDBC7AD54E.png

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.