Hi friends please help me with my bluetooth ornithopter

I really have no idea what I did
I’m trying to make an ornithopter with just 2 servos but 3 channel control
It is controlled by bluetooth

Since I’m not a PRO programmer
I have been trying to modify an existing code

The code:

// this receiver has 4 channels,

// Hardware setup:
// BT module Arduino
// GND ------- GND
// VCC ------- 5V
// TX-O ------ pin0
// RX-I ------ pin1

// RC ch out Arduino
// ch0 --------- pin4
// ch1 --------- pin5
// ch2 --------- pin6
// ch3 --------- pin7

#define bluetooth Serial
#include <Servo.h>

const int chCount = 4;

Servo ch[chCount];
int chPin[chCount] = {4, 5, 6, 7};
int chVal[chCount];

// config:
int usMin = 1000;
int usMax = 2000;

char cmd[100];
int cmdIndex;
long lastCmdTime = 60000;

boolean cmdStartsWith(char st) {
for(int i=0; ; i++) {
==0) return true;*
_ if(cmd*==0) return false;_
if(cmd_!=st) return false;;
return false;

void exeCmd() {_

* lastCmdTime = millis();*

* // example: set slider id to “ch0”, set min 1000 and set max 2000*

* if( cmdStartsWith(“ch”) ) {*
* int ch = cmd[2] - ‘0’;*
* if(ch>=0 && ch<=9 && cmd[3]==’ ') {*
* chVal[ch] = (int)atof(cmd+4);*
* }*
* }*

* // invert channel:*
* // example: set slider id to “ci0”, set min -2000 and set max -1000*

* if( cmdStartsWith(“ci”) ) {*
* int ch = cmd[2] - ‘0’;*
* if(ch>=0 && ch<=9 && cmd[3]==’ ') {*
* chVal[ch] = -(int)atof(cmd+4);*
* }*
* }*

* // use accelerometer:*
* // example: set acc y id to “ca1”*

* if( cmdStartsWith(“ca”) ) {*
* int ch = cmd[2] - ‘0’;*
* if(ch>=0 && ch<=9 && cmd[3]==’ ') {*
_ chVal[ch] = (usMax+usMin)/2 + (int)( atof(cmd+4)51 ); // 9.851 = 500 => 1000 … 2000_
* }*
* }*

* // invert accelerometer:*
* // example: set acc y id to “cb1”*

* if( cmdStartsWith(“cb”) ) {*
* int ch = cmd[2] - ‘0’;*
* if(ch>=0 && ch<=9 && cmd[3]==’ ') {*
_ chVal[ch] = (usMax+usMin)/2 - (int)( atof(cmd+4)51 ); // 9.851 = 500 => 1000 … 2000_
* }*
* }*

* // update:*
* // send something that starts with “update” periodically,*
* // in order to update channels*
* // example: set acc x id to “update”*

* if( cmdStartsWith(“update”) )*
* for(int i=0; i<chCount; i++)*

void setup() {_

* delay(500); // wait for bluetooth module to start*
* // BlueSMiRF default baud is 115200*
* bluetooth.begin(115200);*

* for(int i=0; i<chCount; i++) {*
* // attach channels to pins*
ch_.attach(chPin*, usMin, usMax);
// initial value = middle*

chVal = (usMin + usMax)/2;
* // update*
ch.writeMicroseconds( chVal );
* }*_

* cmdIndex = 0;*
char c = 0;
void loop() {

* // if contact lost for more than half second*
* if(millis() - lastCmdTime > 500) { *
* for(int i=0; i<chCount; i++) {*
* // set all values to middle*
_ ch*.writeMicroseconds( (usMin + usMax)/2 );

* if(bluetooth.available()) {*

* c = (char)bluetooth.read();*

* if(c==’\n’) {*
* cmd[cmdIndex] = 0;*
* exeCmd(); // execute the command*
* cmdIndex = 0; // reset the cmdIndex*
* } else { *
* cmd[cmdIndex] = c;*
* if(cmdIndex<99) cmdIndex++;*
* }*

* }*

Above is my original code
But I’m trying to modify it so that I could use it with an ornithopter
Here’s the reference video
2 servo control for ornithopter - 480p.mp4 - Google Drive
Pls refer the video for the controls
Pls help me
I’m really going mad with this thing
My project will be posted in instructables.com after its completion
With regards

Hi, this ornithopter project sounds really interesting! Could you post a reply here stating you support my request for a "General kinematics, dynamics, and statics for Arduino projects" sub-forum, and linking your post here? I'd like to answer it and talk more about your post.

The thing is, making (any) ornithopter, mechanically is hundreds of times more difficult than the Arduino electronic part. In fact, I googled "ornithopter project" and did not find any working examples. I did find what appeared to be models. (Let me know if I missed any - ornithopter project and ornithopter project Arduino - the first result didn't seem to show the kinds of projects like yours, the second, where I opened the instructable and the youtube video, looked like models. One was firmly attached to a table.)

I think it's certainly a viable and interesting project! I'd like you to support me in opening a sub-forum where such mechanical and of course aviation aspects could be discussed. That is, if you intend for it to fly which I assume you do (otherwise why bluetooth).

To show you how difficult/challenging this may be, in the nineteenth century there were people still declaring that heavier than air flight is not possible (despite the existence of birds). They also at that time had radio electronics, as well as strong power sources like kerosene, that have higher energy density than the batterry packs you'd be using.

So it's a challenging project if you want it to fly, but I believe we can support you. As a first step, I'd love for you to support me in opening that sub-forum, by replying supporting it / asking for it here.

then we could talk about how you might go about it :slight_smile: :slight_smile:


By the way regarding adding Bluetooth to this arduino project - I realize you may already have an approach, but you may want to see my previous write-up about it here. Maybe it includes a step you've missed.... (Or is an alternative approach.)

@SpikeMax, please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long to study quickly without copying to a text editor.

You need to tell us what the program actually does and what you want it to do.

You may find some useful stuff in Serial Input Basics


And to help get you started, (after you’ve edited to add code tags :D), since you declare an array of servos:-Servo ch[chCount];
You need to use an index when addressing them, so this:-

for(int i=0; i<chCount; i++)

should look like this:-

for(int i=0; i<chCount; i++)

I also see that you declare another variable, an ‘int’, named “ch” in your ‘if’ statements. That’s not a good idea and can lead to confusion.

And you need to add some braces to this, as well as the servo index:-

if( cmdStartsWith("update") )
    for(int i=0; i<chCount; i++)

I haven’t looked further, but there’s probably more. :slight_smile:

Thank you for your support guys
I'm good in aeronautics, robot building and electronic circuits
But my only problem is coding

But my only problem is coding

No. You also have another problem - not adding code tags when asked to do so.

It's not fair that you expect people to donate their precious time to help you, when you can't even be bothered spending 30 seconds to add code tags.

I'm outta here.

correct the code as suggested by @oldSteve, those are some valid points. Try those corrections and post the updated code, if it still not working.

Also check the voltage limit of your Rx pin of bluetooth module, if it's 3.3v, then you might need to use a level shifter by using 1k and 2k resistor.