This instructable will give you an EXTREMELY simple and quick way (< 15 minutes) to have an AR Parrot Drone 2.0 fly autonomously with code written by you! The best part of this project is it only requires the drone and a laptop (mac or windows). No modifications to the drone. I will also show you how to stream the video from the drone onto your laptop. Check out a sample program I wrote for my drone:

People have done CRAZY stuff with this, including having a drone that can follow peoples faces or be attracted to objects that are red. This guide is a step-by-step on how to use Felixge's node library to control your drone. Definitely check out what he's done. I did this through trial and error and pared it down to the essentials, best of luck!

Step 1: The Drone

To program your drone, you will first need a drone! I am using an AR Parrot Drone 2.0. The first version may work, but no promises. You can find them at Radioshack, Amazon, etc.

First you will need to get comfortable just controlling the drone with you smartphone/tablet. Download one of the apps such as 'AR.FreeFlight 2.4' to control it. It might be a good idea to leave the indoor bumper hull on at first to minimize damage from collisions. I also suggest flying in an open field or park. 

Step 2: Node JS

The first thing needed for autonomously programming our drone is to download Node JS. It's awesome for web applications with JavaScript and if you are interested you can learn a bit more about it. For our purposes though just download the file. I recommend making a new folder on your computer in your 'C' drive and naming it something like 'Drone'. Move the program into this new folder.

You are halfway to controlling your drone with your laptop!

Step 3: Command Line

Now we will do a bit of work with the command line. Follow the instructions for your type of computer.

The command line program is called 'Command Prompt' and on recent windows versions can be opened by going to 'Start' and searching through the programs or viewing 'all apps'. If confused refer to this help. Once you have the program open type the following line of code and then hit enter:

npm install ar-drone

This will give you access to Felixge’s node.js library so that you can use high level commands such as 'takeoff()' and 'leftFlip' to control the drone. As long as the Command Prompt doesn't throw any errors you are all set to start controlling the drone with your computer! For help using the Command Prompt check this resource.

The command line program on a mac is called Terminal. The easiest way to open it is to click in the Spotlight search bar in the upper right hand of your desktop screen and type 'Terminal'. Then just click on the program called Terminal. Once open type the following line of code and hit enter:

sudo npm install ar-drone

This will give you access to Felixge’s node.js library so that you can use high level commands such as 'takeoff()' and 'leftFlip' to control the drone. As long as Terminal doesn't throw any errors you are all set to start controlling the drone with your computer! For help using Terminal check this resource.

Step 4: Testing

Now that you have Node.js installed with the ar-drone library we can control it with your laptop! To do this, first turn the drone on by plugging in the battery.

Next connect you laptop to the Wi-Fi network named something similar to 'drone######'.

Open up the node.js program. 

Type the next four lines of code into the node.js window and hit enter after each line. (WARNING: as soon as you hit enter on the third line the drone will take off and hover a few feet off the ground until you type the fourth line and hit enter again). Please make sure the drone is in an open space.

var arDrone = require('ar-drone');
var client = arDrone.createClient();

It works! Woohoo! This is a good way to check that everything was installed correctly. If you come across any errors you may need to go back to the last step and download the 'ar-drone' library again. 

Step 5: Autonomous Program

Now the exciting part! We will make some autonomous programs for the drone. This is a huge advantage over what we just did because rather than typing the code line by line we can send a whole program to the drone and it will execute it sequentially for some flawless and exciting flight. 

To do this we will need to write programs in JavaScript. Don't fear if you don't know JavaScript we will mostly be using the same cut and paste commands. If you are interested you can read up on it HERE. We will need a text editor to write our code in, I recommend Sublime Text. Just download it and then upon opening it will open a new file we will type all the lines of our code directly into Sublime Text, as shown in the picture for this step. Then when saving the program make sure to save the file with '.js' at the end of the name and it will automatically become a JavaScript file! 

For now copy my simple program in the picture and save it as 'test.js'. This will have the drone takeoff, hover for a few seconds, and then land. Check the next step on how to run this program.

Step 6: Running Programs

To run the program 'test.js' we first need to know where we saved the file. Move the program into the 'Drone' folder you made in your 'C' drive. Once again we will need to use the command line, for Windows open Command Prompt, and for Mac open Terminal. 

Turn your drone on and connect the laptop to its Wi-Fi connection. Type the following line of code and hit enter:
node c:\Drone\test.js

What this is doing is having the node.js program run the file test.js which is stored in the 'Drone' folder in the 'C' directory. By looking at the line of code hopefully this makes sense. When running a different program only the name 'test.js' needs to be changed as long as the program is located in the 'Drone' folder.

If the drone took off, hovered, and landed you did it! 

Step 7: Functions

Now you have everything you need to autonomously fly your drone. To write more complicated programs you will just have to know a few functions that the drone is capable of. Below I show the name and describe what they do. You should also check out Felixge's README file that was included with the ar-drone library as it has tons of beneficial information.

takeoff() - has the drone takeoff and hover above the ground
land() - has the drone land
up(speed) - has the drone gain altitude at a speed between 1 (max speed) and 0 (still).
down(speed) - makes the drone reduce altitude
clockwise(speed) - drone spins clockwise
counterClockwise(speed) - drone spins counter-clockwise
front(speed)/back(speed) - changes the pitch causing horizontal movement
left(speed)/right(speed) - changes the roll causing horizontal movement
stop() - keeps the drone hovering in place
(for complex functions like flips and manuevers, check out the README file linked above)

All of these functions can be used in a long list with a dedicated time between them by using the format:

    .after(5000, function() {
    .after(3000, function() {

The amount 5000 is the time in milliseconds that the drone will turn clockwise for at 0.5 of its top turning rate (1 being max and 0 being still). We can see for the stop function that it doesn't have a speed because it takes care of that itself. By making a long list of commands like this we can set up an autonomous task list to carry out. I have copied the code that my drone ran, in the video on the first page, below:

var arDrone = require('ar-drone');
var client  = arDrone.createClient();


  .after(2000, function() {
  .after(2000, function() {
  .after(1000, function() {
    this.animate('flipBehind', 500);
  .after(1000, function() {
  .after(1000, function() {
    this.animate('flipRight', 500);
  .after(5000, function() {
  .after(2000, function() {
  .after(5000, function() {
  .after(2000, function() {

Hopefully this will give you a good idea of how your program outline will look.

Step 8: Streaming Video

For all the super awesome applications like face tracking you will have to stream the video from the ar drone. One easy way to do it is to download ffmpeg. After downloading go ahead and run it. A command line type window will pop open (you can see a picture of mine on this step). You will need to make a new JavaScript program using the Sublime Text editor as described in step 5. Copy and paste the code below into a file and save it as 'video.js' in your 'Drone' folder (Sorry I couldn't upload any '.js' files).

var arDrone = require('ar-drone');
var http    = require('http');

console.log('Connecting png stream ...');

var pngStream = arDrone.createClient().getPngStream();

var lastPng;
  .on('error', console.log)
  .on('data', function(pngBuffer) {
    lastPng = pngBuffer;

var server = http.createServer(function(req, res) {
  if (!lastPng) {
    res.end('Did not receive any png data yet.');

  res.writeHead(200, {'Content-Type': 'image/png'});

server.listen(8080, function() {
  console.log('Serving latest png on port 8080 ...');

Now run this program by typing the following line into the command line window that opened when you ran ffmpeg. Don't forget to hit enter.
node c:\Drone\video.js

Go to your web browser (any one will work) and go to the following website (you can just copy/paste it):

You will now be getting a stream of the video that your drone is viewing through the front camera! You can see a picture of what mine was viewing along with some of my bookmarks :)

CONGRATS! You are now set to begin doing some awesome stuff with you drone. Feel free to check out Felixge's library if you are interested in using the video feed from the drone to do things such as track and follow people's faces (this uses a program called OpenCV). Best of luck.

<p>Hello<br>Please help. I have an issue with a warning that happens after npm install.</p>
<p>Hi. What does the warning that you get say? I might be able to help since I have completed this project many times. Thanks!</p>
<p>I will answer you soon. please bear with me.</p>
<p>This is the error </p>
<p>Looks like you aren't running the file in the directory/folder where you saved it. Before you run npm install ar-drone you need to get in to the directory where you installed .json. Your error indicated that npm install is looking for the .json file in the current directory.</p><p>Thanks and good luck.</p>
<p>Hi all, Im fairly new in regard to programming for a drone so please bare with me if my questions sound &quot;newb-ish&quot;. Everything regarding programming for the Parrot AR drone is a few years old. It seems odd because I've found alot of cool things with the AR drone 2.0. Has anyone else noticed that? Is there a better, more accurate, newer model of a drone for this sort of programming? My background is in C++ but I'm open to trying any language to make an autonomous obstacle avoiding drone.</p>
<p>You can try the Parrot Bebop 1 or Parrot Bebop 2.</p><p>Thanks!</p>
<p>Hey great work but i would like to know would this be possible of a self made fpv drone , what all components would be needed and how would it be programmed ? </p>
<p>Great instructable Patrick! One very quick question. Would this work with the first generation of Parrot Drone ? I'm not too familiar with the protocols used as my drones all use 2.4GHz transmitter/receiver. Is the basic communication API the same between the 2 Parrot versions. Many Thanks</p>
<p>So I did all these steps and when I was trying to make the drone use my test.js program nothing happened it just sat there and no errors popped up but nothing happened. what am i doing wrong?</p>
<p>Try this as your program. The program in the instructions is having the drone takeoff, immediately land (so fast that it doesn't even take off), then land again after a certain amount of time. I think there is just an error with the instructions.</p>
<p>Great instructions. Love it! Just one thing I wanted to mention to the community, your example program in step five doesn't work (for me at least). It is having the drone takeoff, immediately land (so fast that it doesn't even take off), then land again after a certain amount of time. I believe it should be:</p><p>var arDrone = require('ar-drone');</p><p>var client = arDrone.createClient();</p><p>client.takeoff();</p><p>client</p><p>.after(5000, function() {</p><p>this.land();</p><p>});</p><p>Thanks.</p>
This is awesome!!! I had no idea I could do this with my parrot
<p>Will this program work with other drones?</p>
<p>Wow, that actually sounds pretty interesting. Definitely worth checking out and maybe upgrading the Parrot if I can do it right :) Thanks! If I may, you can also check out <a href="http://mydronelab.com/reviews/parrot-ar-drone-2-0.html" rel="nofollow">this review</a>, and take a look how these guys took a different approach with this model.</p>
<p>Someone please help me before I shoot myself. I had everything going well, then started a 'client.createrepl()' in node. Now I can't do anything because within terminal everything I write comes back with:</p><p>ReferenceError: client is not defined</p><p> at repl:1:1</p><p> at REPLServer.defaultEval (repl.js:262:27)</p><p> at bound (domain.js:287:14)</p><p> at REPLServer.runBound [as eval] (domain.js:300:12)</p><p> at REPLServer.&lt;anonymous&gt; (repl.js:431:12)</p><p> at emitOne (events.js:82:20)</p><p> at REPLServer.emit (events.js:169:7)</p><p> at REPLServer.Interface._onLine (readline.js:211:10)</p><p> at REPLServer.Interface._line (readline.js:550:8)</p><p> at REPLServer.Interface._ttyWrite (readline.js:827:14)</p><p>I have tried stopping it, ctrl D, system/stop 0 and nothing works. Now I am at a loose end and considering suicide.</p><p>Please help me. Thank you in advance.</p>
<p>Not sure if you figured this out already but the command should be as followed: client.createRepl()</p><p><br>Take not of the capital letter on the command. :)</p><p>Be sure that you are defining the ar-drone library and create the client before trying the command:</p><p>var arDrone = require('ar-drone');<br>var client = arDrone.createClient();</p>
Thank you, eventually I did figure it out. Each time I closed the terminal it wanted me to reinstall the library. I didn't know this so was just trying to continue as I was. It was driving me crazy.<br><br>Eventually i changed to using Ruby as the programming language and everything fell into place perfectly. I need to remember there's always more than one way to skin a cat (program a drone). <br><br>I very much appreciate you taking the time to reply. Thank you again.
<p>You're very welcome!<br><br>Have fun :)</p>
<p>I'm currently working on a 3d reconstruction project. so i need to capture multiple view images of the object. Anyone knows how to make the drone go in a circular orbit around an object? Please help!</p>
<p>ardrone-autonomy would be able to approach this &quot;mission&quot;. You could get it to orbit an object fairly easily.</p>
<p>Anyone knows if it is possible that the ar.drone can fly alone without existing wirelless connection during the flight ? Since there is only connection when the command is given by the node.js and send it to certain points GPS</p>
<p>I'm on a windows 8.1 and I've done everything correctly yet npm install ar-drone command keeps giving me an ENOENT error. Is this not compatible with windows 8.1? Please advise !!</p>
<p>open command prompt.</p><p>type: cd c:\[NameOfYourFolder] [enter]</p><p>type: npm install npm -g [wait]</p><p>when complete, </p><p>type: npm install ar-drone [enter\</p><p>it should work from here.</p><p>I would like to note that when writing scripts, there is no way to stop your drone unless it finishes the script, so start small and work your way up. or try ez-builder.</p>
<p>i got to my folder n when i got to ur 2nd part type: npm install npm -g [wait] nothing happens? do i wait longer?</p>
to be honest, and in sorry, I don't remember writing this.
<p>its all good if anyone else can help that'll b appreciated</p>
<p>what you need help with? Got this working and its great, feel free to email me any questions you got!</p>
<p>I have this same exact issue, its sad nobody gave a reply after 3 monts.</p>
I haven't tried it yet but how do u send the program to the drone and can I do this with any drone, preferably one I have made
<p>I think you can only do it with this drone do to its open source community and plugins that are supported such as node js, if your drone is supported by javascript and node and has a wifi port you can connect to from your computer, then yeah give it a shot!</p>
<p>I seems that the drone will except the commands only while connected to the laptop via wifi. </p><p>Do you know a way to run your program while the drone is disconnected from the phone or computer?</p><p>It should involve installing the program on the drones onboard computer.</p><p>Any ideas ?</p>
<p>Unfortunately, what the author presents here is actually not a drone's autonomous flight - it's rather laptop-controlled flight without human intervention.</p><p>I guess this might be interesting for autonomous flying: <a href="http://wiki.paparazziuav.org/wiki/Main_Page" rel="nofollow">http://wiki.paparazziuav.org/wiki/Main_Page</a></p>
<p>Maybe this will work for you. I've yet to test this myself but it is on the &quot;to do list&quot;</p><p><a href="https://github.com/daraosn/ardrone-wpa2" rel="nofollow">https://github.com/daraosn/ardrone-wpa2</a></p>
<p>In steps 5 and 7 you have to comment out or delete the first client.land(); line or the program will not work. Please update!</p>
<p>when i am testing and i type the first two commands, the var ones it says undefined, when i say takeoff or land it says true, i am probally doing something incerdibly wrong but i don't know what. please help me</p>
<p>After ( i use terminal) writing the lines;<br>&gt; var arDrone = require('ar-drone');</p><p>&gt; var client = arDrone.createClient();</p><p>I also get undefined, just continue with:</p><p>client.(the command)<br><br>So for instance</p><p>client.takeoff();</p><p>or</p><p>client.land();</p>
<p>Hey, I'm running into an issue when attempting step 8, running ffmpeg's FF Prompt and entering the node... command doesn't do anything except throw an error about 'node' being an unknown command :/ how do I resolve this?</p>
<p>Video Won't stream unless constantly refresh page??</p>
<p>I have the same problem</p>
<p>Will the code let it fly exact pathes? as i want it to fly a very specific route trough my home.</p>
<p>you could use painters tape, get it in green or blue from the dollar store (cheap and you will use a lot of it ) and you and tape out a colored track for it to fly but that's for close to the ground flying</p>
<p>I've done something very similar with my AR Drone:<br><a href="http://www.webondevices.com/fly-an-ar-drone-with-an-xbox-controller-and-javascript/" rel="nofollow">http://www.webondevices.com/fly-an-ar-drone-with-a...</a><br><br>I was thinking about using the Web Speech API to control it with my voice. I might do that later :)</p>
<p>Is it possible to save the latest .png file that is viewed in the browser to my Drone file (i.e., save the image generated in step 8)? I want to be able to analyze these frames in real time for tracking purposes.</p><p>Thanks</p>
<p>I have got most things working and BTW thanks for a clear simplistic how to.</p><p>I have got to the Run a Program section and cannot get a .js program to run. In the node.js console I get an UNDEFINED error after I execute the </p><p><strong>var arDrone = require('ar-drone');<br>var client = arDrone.createClient();</strong></p><p>lines of code, however, the next two lines for take-off and land work and the AR-Drone flies.</p><p>Now when I make a test.js file and try to load it using the node.exe command prompt I get three dots ... on the following line, so something seems to be running but the AR-Drone is not responding.</p><p>Any clues to what I might be doing wrong?</p>
<p>Try closing node.js and just using the regular cmd. Type <strong>node c:\Drone\test.js or </strong>whatever folder you saved the test.js in. Also, you need to remove the first <strong>client.land(); </strong>from the script. Basically, the script is telling the drone to take off and immediately land. The last 5 lines of the script are what tells the drone to land after 5000 ms.</p>
<p>Have you already found a way to fix this? I have the exact same problem and can't figure out why it won't work. The script has no faults and the drone seems to be receiving it but it won't do anything except for blinking it's green led's..</p>
<p>Hi yuckoz, griegt1 - did you guys manage to get this going at all. The test.js file in neither being seen by 'command prompt' [cmd] or node.exe</p><p>I'm totally clueless after spending a day so far installing and uninstalling trying to work this out - patience is a virtue as they say.</p>
<p>sorted so it's all cool... back on track and the learning curve is slow but meaningful... cat doesn't like the drone flying in the house :)<br><br>Check out this site as well: <a href="http://nodecopter.com" rel="nofollow"> http://nodecopter.com</a><br><br>A lot of useful tips</p>

About This Instructable




Bio: I hope to help people with the things I make.
More by Patrick S:Guitar Backpack DIY Prosthetic Leg Foam Cover (Cosmesis) Tact: Low-cost, Advanced Prosthetic Hand 
Add instructable to: