loading

Have you ever wanted to control your RC airplane by means of tilting an object? I've always had the idea in the back of my head but I've never pursued it until this past week. My initial thoughts were to use a triple axis accelerometerbut then I had a idea. . .

Most of you have smart phones right? And another great majority of you electronic guys out there use Androids because of it's flexibility. I mean I love the iPhone, but it's not as versatile in the regards to connecting it via Bluetooth or hardwire to an Arduino or other microcontroller. So why not just the phone's accelerometer? So I took the idea and ran with it. Two weeks later I present you this project!

Sorry IOS users, this project only pertains to Android users.

Now this project has not control over the rudder or the throttle. If you'll notice I did add code for you to use a potentiometer on pin A1 to control the throttle, although I myself will not be using it. I'm just going to use my transmitter's throttle.

If you'd like to complete this project I suggest you watch the entire video before you start working. The electronic skills required for this project are minimal but the hard part is working with the code. So grab your soldering iron and Arduino and lets get going.

Project Cost: (Free, Low, Medium, Up there, Seriously?)

Project Difficulty: (Breezy, Easy, Medium, Hard, Expert, Master)

Project Time: (Over a cup of coffee, medium, over a pot of coffee, several days)

Below is a quick flight I had earlier when it was kinda windy!

Step 1: Watch the Full Video

The video and the text cover pretty much the same stuff except the text does not include the step by step process to building the project case and connecting everything. The text illiterates a tad bit more on some of the coding involved.

Step 2: Ingredients:

What does every good recipe need? Ingredients. Unfortunately you might need to go somewhere other than your corner grocery for these.

Ingredients:

Tools:

  • Soldering Iron
  • Wire Strippers
  • Scissors
  • Drill with various drill bits
  • Hot Glue Gun

Step 3: Downloads

If you'd like to download a .zip file of everything you will need for this i'ble you can find that here. Otherwise read below.

First of you need to download the Amarino app and the Amarino Toolkit and get it onto your phone. You could do this with a micro SD or just use your favorite file hosting website, like Google Drive.

Secondly you need to download the MeetAndroid library for the Arduino IDE. To install the library follow the steps carefully.

FOR PC:

  1. Close the Arduino IDE.
  2. Unzip the MeetAndroid folder. You should now have an unzipped MeetAndroid_4 folder. Open this folder and cut the folder inside called MeetAndroid.
  3. Navigate to C:\Program Files (x86)\Arduino\libraries and paste in the MeetAndroid. If you did everything correctly it should look like the first picture.
  4. Reopen the Arduino IDE and you should see in the libraries under 'Contributed' the MeetAndroid lib.

FOR MAC

  1. Close the Arduino IDE.
  2. Unzip the MeetAndroid folder. You should now and unzipped MeetAndroid_4 folder. Open this folder and copy the folder inside called MeetAndroid.
  3. Navigate to the Arduino application, right mouse click show package contents and then Contents/Java/libraries and paste in the MeetAndroid folder.
  4. Reopen the Arduino IDE and you should see in the libraries under 'Contributed' the MeetAndroid lib.

Lastly download both my Arduino sketches that are attached to the bottom of this step (included in the .zip).

Step 4: Configuring the HC-06

Your HC-06 Bluetooth module doesn't just come out of the box ready to use in this project. We need to change just 1 simple thing: the baud rate. Depending on who you buy yours from it may be set at different baud rates. I got two HC-06s from two different sellers, and each was running at a different baud rate. We need to change it to 115200 bits per second. Make the following connections:

HC-06 ------- FTDI Breakout Board

| -------------- |

GND -------> GND

VCC --------> 3.3v

TX ----------> RX (or DRX)

RX ----------> TX (or DTX)

  1. Plug the FTDI breakout board into your computer.
  2. Open the Arduino IDE. Select whatever com port is available. (make sure there are no Arduino's or anything else plugged into the computer).
  3. Open the Serial Monitor (no need for code!)
  4. Select 9600 for the baud rate at the bottom right of the com window. Type "AT" (it HAS to be caps) and hit send. If you don't get anything back that's fine. This means your device is configured at a different baud rate. Try a baud rate of 115200 and type "AT". If you still don't get anything try each and every baud rate and type "AT" on all of them until you get a response. If you don't get a response then most likely you haven't wired up the HC-06 correctly. Check connections.
  5. If you do get the response "OK" then awesome! If you get that response on any other baud rate then 115200, you need to change it to 115200. To do this type "AT+BUAD8". You'll get the response "OK115200". You will have to change the baud rate to 115200 to continue talking to the Bluetooth. Then you can do stuff like change the name by typing in "AT+NAMERANDOM" random being the name you want. You can now close the serial monitor.

Step 5: The Incomplete Circuit for Testing

This circuit is quite simple. You need to power the Arduino (through USB since we are going to need to upload some stuff to it), then connect the HC-06. Just connect follow the connections below.

HC-05/6 --------- Arduino

|=============|

GND --------------> GND

VCC ---------------> 5v

TX ----------------> RX

RX ----------------> TX

Step 6: Installing Amarino and the Amarino Toolkit

You should have downloaded and transferred your Amarino app and toolkit to your phone by now. But before you install it you need to change a setting on your phone. Your phone won't let you install the app at first because it is not a certified application from the Android playstore. So we will need to allow the phone to install un-certified apps. This is quite simple.

  1. Navigate to Settings/Security and scroll down. You should see a box that says Unknown Sources and a little box next to it. Tap on the box and enable. It will bring up a dialogue box telling you how risky this is; sounds good right? So tap that OK button. See pictures 1, 2, and 3.
  2. Now you can open your Amarino app and follow the onscreen instructions. Not too difficult just hit yes.
  3. Install the Amarino Toolkit. Not too difficult either.

Step 7: Setting Up Bluetooth

With your project powered (the Bluetooth chip is on) find your phone's Bluetooth settings. You need to pair your phone with the Bluetooth chip. Tap scan for devices and your device should show up as HC-05 or HC-06 unless you named it earlier. It will ask for a pin number, and it will 1234. (I know I'm a genius for hacking the device and finding the uber-secret password). See pictures 1, 2, and 3. Make sure that you are paired with the device and you are ready for the next step. NOTE: the light on the Bluetooth device will not go solid when you pair with your phone! I found that on my phone I had to restart it after this process for it to show up in the Amarino app, so go ahead and reboot your phone.

Step 8: Amarino

Time to open up Amarino. You will be presented with the release notes and tap OK. Thank you Bonifaz Kaufman for creating this wonderful app. The numbers below correspond with the picture number e.g. step 1 = picture 1.

  1. Welcome screen. Tap on "Add Device".
  2. Your device should now be in the list; tap on it. If it does not show up try rebooting your phone, and make sure that the Bluetooth device is connected to the phone.
  3. You should now come to this screen. Tap on "Connect". This may take a few seconds.
  4. If it connects then the light on the Bluetooth device will turn solid and you'll see at the top "Active Connections: 1. Now tap on the device name and NOT disconnect.
  5. Tap on "Show Events".
  6. There should be no events. Tap on "Add Event".
  7. A list will pop up and you will want to select the accelerometer. Keep in mind these other sensors that are built into your phone. They may come in handy one day for a later project!
  8. Here are just a few settings for the accelerometer. Make sure that the slider is on "very fast" and that the data visualizer is on "Text". Then tap save.
  9. If you see numbers to the right of the "Accelerometer Sensor" then you are good. You can leave your phone alone now. If you don't see numbers, long press on the gray area to bring up a menu.
  10. Select "Force Enable".
  11. Bingo! Numbers! Tilt your phone and get a feel for how the numbers correspond with the accelerometer.
  12. You can now place your phone on a flat surface and get ready to start some coding!

Step 9: Skipping the Code

So if you don't want to get your hands dirty with the code and you just want to upload and go you might be in a little bit of trouble. I've only used my phone so far so I don't know if other people phones are the same. If you download the app SensoDuino and click on the tab "Built in Sensors" you should be able to find your accelerometer. If you accelerometer is a MPU6050 then that is the same sensor that I have, and you probably don't need to do any code editing. If you have the same sensor, just try the code uploaded to this step.

If not then you will probably have to follow the next steps.

Step 10: Assigning Accelerometer Data

Now we get to the fun part, messing around with the Arduino sketch! If your sketch doesn't compile see the last step of this instructable.

At this point you should now have your Arduino connected properly to your HC-06 and you should have Amarino pushing numbers out to your Arduino via Bluetooth. Double check to make sure that the HC-06 is still bound and upload the following sketch to the Arduino. (Attached to this step).

NOTE: When uploading sketches to the Arduino you will need to unplug the TX and the RX of the HC-06 from the Arduino. The Arduino can't be uploaded to while the RX and TX are connected to something.

After uploading this sketch to the Arduino open up the Serial monitor. You should see three numbers jumbled together separated by a box (□). Example: [ 0.01□0.02□□9.21 ] The first two numbers are roll and pitch. I didn't even try figuring out what the third one was :D. Your phone may or may not be similar to this. To find out which numbers are roll and which numbers are pitch are for your phone follow these steps.

  1. Set your phone on a flat surface. Orient your phone so that the camera/ear speaker is pointing to the left and the microphone is pointing to the right. (picture 2).
  2. Tilt the left side of the phone up (picture 3) (along the Z axis, see picture 1 for the axis) to 45 degrees. Note which number changes drastically in the serial monitor. This number will be your roll.
  3. Tilt the phone toward you (picture 4) (along the X axis, see picture 1 for the axis) to 45 degrees. . Whatever number changes drastically is pitch. Record this.

Now that we know which two sets of numbers are roll and pitch we can go and change the code. We will be taking a look at section 2.

pitch = data[0]; 
roll = data[1];  

If you looked earlier in the code, you'll notice that the accelerometer data is put into an array. The array "data" has three 'spots' called 'indexes' for numbers, index 0, index 1, and index 2. Now that you know which numbers represent pitch and roll you can assign the integer "pitch" and "roll" to the correct numbers in the array. Example: if the third set of numbers changed when your tilted your phone left/right, which is roll, then we'd change the code to this:

roll = data[2];

And it's as simple as that. If you phone is similar to mine then the first number will be pitch, the second number will be roll, and the third number we be some other aspect of the three dimensions.

Step 11: Mapping the Accelerometer Data

Once you have "roll and "pitch" assigned to the correct numbers in the array data, we can move on. Look at picture 1 all the way on the left. This is the raw data from your accelerometer. But we can't use these numbers directly we need to remap them to a value between 1000 and 2000 with a midpoint of 1500. To scale the numbers up we will multiply "roll" and "pitch" by 1000. This will get rid of all the decimals and it will give us a decent resolution. Now if you look at the numbers in the second column you can see the 'new' numbers. Lets set some in and out points!

  1. Tilt your phone to the left 45 degrees (roll) and record this number.
  2. Tilt your phone to the right 45 degrees (roll) and record this number.
  3. Tilt your phone to the forwards 45 degrees (pitch) and record this number.
  4. Tilt your phone to the backwards 45 degrees (pitch) and record this number.

If the two numbers are around the same for when you tilted your phone 45 degrees in both directions you can ditch the second number and just use the first. Create a second number by taking the negative of the first number.

Example: Tilt phone 45 degrees to the right. The number show for roll is 5500. For the second number just use -5500. This will be our in and out points. We don't want our TX to register anything more than those points. Then we need to remap those values to 1000-2000. In my case -5500 to 5500 were the numbers that I got when pitching my phone 45 degrees and when rolling my phone 45 degrees. So I used the following code: NOTE: It is now time to delete the /* and */ in section 4 to enable this code. Also delete all of section 3.

pitchval = map(pitch,-5500, 5500, 1000, 2000) -12 ;

rollval = map(roll, -5500, 5500, 1000, 2000) + 7;

Now the -12 and the +7 are adjustments to bring "pitchval" and "rollval" to a center of 1500. Make sure that your phone is on a flat surface when you make these adjustments. If your center is not at 1500 then your plane may veer off in a direction even though your have your phone level.

We need to constrain rollval and pitchval. We don't want them going anymore than 2000 or any less the 1000 or else things start messing up! So we type this. . .

pitchval = constrain(pitchval, 1000, 2000);

rollval = constrain(rollval, 1000, 2000);

Last thing we need to do with these numbers is to make sure they correspond correctly with the way we tilt our phone. Check to see if your phone is face up with your camera on the left, and the microphone on the right.

  • When you roll your phone to the left, rollval should decrease to 1000.
  • When you roll the right, it should increase to 2000.
  • When you pitch your phone backwards, pitchval should decrease to 1000.
  • When you pitch your phone forwards, it should increase to 2000.
  • Both centers should be at 1500 when you place your phone on a flat surface.

If when you roll your phone to the left and rollval increases rather than decreases, change the 1000 you multiplied "roll" by to -1000 (in section 2). The same goes for the "pitch" if the numbers are reversed.

Example code for fixing roll in the example above.

pitch = (pitch * -1000); // multiply by 1000 to get rid of the decimals

roll = (roll * -1000);

So if everything is working fine then we can add this to the final code!

  1. Open the ReadRawAccel sketch. Copy everything under the page1 maker.
  2. Open the TiltTX_Final sketch. Scroll to the bottom where it says "paste page 1 here" and replace all code under it.
  3. Upload the TiltTX_Final sketch to your arduino.

Step 12: Circuitry Time!

Now that we are done with the hard part it is time to make the circuit. You may choose not to make a shield to save time and parts but I always like to make my projects with shields in case I need to use that Arduino with another project. For this project I will be using my Arduino Nano because I want this all to fit in a small box. But you could use any other Arduino, from a Mega to a LilyPad. So study the schematic, watch the video and start soldering! I won't post all the picture here because I show you step by step how to make it in the video.

Step 13: Setting Up the Trainer

Now that you are done with the circuit power it on, connect to your phone, and plug the mono jack into the training port on the back of the radio. Set the multiplier to 1.3 and place your phone on a flat surface. Then calibrate.

Note, channel 0 is throttle, channel 1 is roll, and channel 2 is pitch.

If you want to change these go into the code here:

ppm[0] = throttle;
ppm[1] = rollval; 
ppm[2] = pitchval;

Step 14: Conclusion

Some people have had the issue of the code not compiling. Why I don't know because it work fine for me on both my platforms, but if you get the error messsage (error not defined in this scope) then you need place line 1 after void error loop.

1. MeetAndroid meetAndroid(error); //The Android bluetooth stuff. Don't touch this.
void error(uint8_t flag, uint8_t values) // more bluetooth stuff. { Serial.print("Error: "); Serial.println(flag); }

When you're done it should look like this:

void error(uint8_t flag, uint8_t values) // more bluetooth stuff.
{
  Serial.print("Error: ");
  Serial.println(flag);
} 

MeetAndroid meetAndroid(error); //The Android bluetooth stuff. Don't touch this.

I really hope you found this instructable interesting and fresh. I tried to make sure that it is easy to follow. Should you be confused with anything the video goes into a bit more detail then the instructable does. If you run into any trouble please contact me and I'll be happy to help as long as your question is relevant. Please give this instructable a vote and post a picture below to your replication, and if you made a video, post a link! Be sure to leave feedback below!

HavocRC,

~AJ

Awesome instructable! This is an amazing build, it totally deserved my vote. <br><br>Have you had any issues with the smartphone's accuracy? Mine always seems to need recalibration.<br><br>Have a great day! :-)
Thanks man!<br><br>Um the only real issues I've had is the speed at which my Arduino gets the accelerometer data from my phone. It's too slow and make the servos a bit twitchy. I think it has to do something with the Meetandroid library but I'll have to look into that another day. <br><br>As far as calibration as long I place my phone on a flat surface and calibrate it with my radio it works fine. I mean it's just like hooking up another radio, you have to calibrate every time. <br>Post a photo!
<p>Can we use avionic 6-channel 2.4 GHz transmitter or Avionix 9-channel 2.4 GHz transmitter in place of Turnigy 9-x?</p><p>If yes,what are all the procedures ,we need to follow other than trainer mode as one of the transmitter which we have ,doesn't include trainer mode settings, while avionix has trainer mode but how to change multiplier to 1.3 ? </p><p>If you could help ,it would be nice of you..</p>
please tell suggest me $10 transmitter as I am low on money and I want to build a plane
The cheapest you'd want to get is the turnigy 9X from hobbyking, you can get them as low as 50 dollars
Cool project!<br>Do you think this could work on a non programmable cheap transmitters like the one from hobbyking? because there is no trainer mode but it has a mono port.
The mono is usually only an output
<p>Wow! Is fantastic!</p><p>I want to control a Quadricopter using your solution. </p><p>I don't want to use a RC transmitter but i want to control the Quadricopter ONLY from smartphone.</p><p>Do you think it's possible?</p><p>Thank you</p>
<p>It's totally possible, but if you use only Bluetooth you will have a very short range. You can do it by using an arduino + HC-06 + Xbee modules, the range will be according with the power of your Xbee modules. And if you decide to do this, you need to re-write all the code. I'm working on a similar project.</p><p>Note: I am not fluent in english</p>
<p>It's not possible in the sense of using just a phone for sensors. You need to be able to actively use the throttle and the rudder, which are essential to flying a quad. </p>
I'm trying to develop an app for this, I will use a bar on the touch screen for yaw and throttle. So I know it's possible but also I know it's not recommended to use only the smartphone because it's not secure like a rc transmitter, if there is a break or a delay for some reason, your quad would crash. <br><br>My email is ricardo.carvalhosoft@hotmail.com
<p>Hi, could you kindly send me your e-mail address so we can talk about my idea?</p><p>If you want i can help you for the DIY controller!</p><p>I'm not fluent in English too.. :)</p><p>Thank you</p><p>Andrea</p>
<p>Very nice project</p>
Even if I use two xbee ?
<p>Good luck!</p>
<p>Fantastic!</p><p>Do you think is possible to control a quadcopter only through smartphone? (using your Arduino solution). I don't want to use an RC transrmitter.</p><p>Thanks</p>
<p>what kind of rc plane is that?</p>
https://m.instructables.com/id/Complete-Guide-to-Building-Your-First-DIY-RC-Foamb/
congratulation!!
<p>So cool!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!</p>
Thanks!

About This Instructable

12,898views

195favorites

License:

Bio: 19 year old hobbyiest and future EE.
More by HavocRC:DIY FPV Antenna Protector Case Control Your RC Plane With Your Phone's Acclerometer DIY Receiver Controlled Switch (Cheap and Easy) 
Add instructable to: