Controlling an infrared helicopter with Arduino

So I’ve gone ahead and bought myself an infrared controlled helicopter in a local shop. At the time of writing, it’s Christmas so it’s kind of like a present I’ve got for myself. If you live in Belgium or the Netherlands, I’m talking about Action :-).

It looks like this and it retails for about € 15. However, buyer beware: I’m no expert but it flies like absolute *****. It does not really hover and despite my best efforts to calibrate it, it keeps on rotating.

On the bright side it uses infrared for it’s remote control. Since I’ve been teaching my students in one of my classes about infrared I’ve gotten up to speed on the basics. I was confident I could spoof the remote control commands with an IR LED and an Arduino. Turns out I was right.

Note: if your thinking about autonomous flight using this particular helicopter… move on to another model because in my opinion, it’s not really possible unless the helicopter can stabilize itself and remain in position. This helicopter simply can’t do that.

If you want to simply do a proof of concept then by all means, read on.

What you’ll need

  • An IR RC helicopter from Action
  • An Arduino (I’ve got a Leonardo)
  • An IR LED (38 kHz) and 220 Ohm resistor
  • A breadboard
  • Optional: an IR receiver

Deciphering the protocol

This step is optional and I’ve basically done all the work here. By using an IR receiver I’ve reverse engineered the commands sent by the real remote control. I’ve done this by using the IRLIB2’s rawRecv sample code, pressing buttons on the remote control and then looking at the data. This was a process that required some patience.

I’ve discovered that, per ‘command’, 36 ‘timing values’ are sent to the helicopter but only four of them are unique:

  • Approximately 1900
  • Approximately 315
  • Approximately 950
  • 1000

An intercepted ‘command’ looks, for example, like this:

1902 330
306 334 310 330 286 354 310 330
310 962 950 962
310 966 946 962
310 330
310 330 946 966 946 966
310 326 310 334
942 334 946 330
310 1000

Each value at approximately 315, we interpret as a ‘0’ and each value at approximately 950 we interpret as a 1. The values in red are regarded as a header and trailer and do not count as meaningful data.

The translated ‘command’ then looks like this:

1902 0
0 0 0 0 0 0 0 0
0 1 1 1
0 1 1 1
0 0
0 0 1 1 1 1
0 0 0 0
1 0 1 0
0 1000

The first 8 bits represent the throttle value. 00000000 is of course: 0 and 01111111 is the maximum at 127.

The next 4 bits represent the left / right value where 0111 is idle, 0000 is left and 1111 is right.

The next 4 bits represent the forward/backward value where 0111 is idle, 0000 is forward and 1111 is backward.

The next 2 bits represent the channel. 00 is A, 01 is B and 11 is C

The following bits contain calibration information but I have not really bothered with that. I’ve always left it at it’s defaults: 001111 0000

The last 4 bits is the checksum and this was a tough one for me to find. It’s basically the data grouped in pairs of 4 bits and then you XOR them together. The result is XOR’ed again with 0101.

So it’s like this:

0 0 0 0
0 0 0 0
0 1 1 1
0 1 1 1
0 0 0 0
1 1 1 1
0 0 0 0
0 1 0 1
 1 0 1 0

Now we have everything we need to spoof commands to the helicopter :-).

The schematics

Basically this is an Arduino with an IR LED and resistor. You connect an IR LED just the same as a normal LED.

The only caveat is that you should wire the LED to pin 9 on a Leonardo as this is different from the UNO.

The code

I’ve written a lot of comments in the code so it should be fairly self explanatory. Upload to the Arduino and you’re ready for takeoff.

 

Leave a Reply

Your email address will not be published. Required fields are marked *