ESP32 drone programming: what to do after you build it

14 min read

In this post

From a blinking light to your own flight code, one small step at a time. Your drone is built. The props spin, it lifts off, and you feel brilliant for about ten minutes. Then a bigger question arrives: what is actually keeping this thing in the air, and how do I start changing it? Here’s something many new builders don’t realise. A quadcopter cannot stay level on its own, not even for a moment. Code is correcting it many times every second, and once you understand that code, the drone stops being a gadget and becomes something you control. This guide covers what to do after you build a drone. If you haven’t finished assembly yet, start with our setup guide for your first drone, then come back. > Key takeaways > – Learn to fly first: a free browser simulator lets you practise before you risk your build. > – ESP32 and Arduino are both good starting boards. Pick based on what you want to learn, not on hype. > – Start small: blink an LED, read your sensors, then learn how PID keeps a drone level. > – You can write flight code from scratch to learn deeply, or build on ArduPilot to fly sooner. > – Always test new code with the propellers off.

Built your drone? Here’s what programming it really means

“Programming a drone” sounds like one big job, but it is really a ladder. At the bottom is the small task of making a light blink. At the top is a drone that flies a route on its own. You don’t have to climb it all at once. Below are five clear steps, two paths you can choose between, and the safety habits that keep your build in one piece. First, though: what is your code actually controlling?

What does a microcontroller do on a drone?

A microcontroller is a tiny computer on a single chip. On a drone, it sits on the flight controller, the board that acts as the drone’s brain. Its job is a loop that never stops:

> 1. Read the sensors. A gyroscope (gyro) measures how fast the drone is rotating. An accelerometer measures tilt and movement. > 2. Decide how far the drone is from where it should be, and what correction it needs. > 3. Act by telling each motor to spin a little faster or slower.

Then it does it all again, and again, very fast. In plain code-shaped words, it looks like this: forever: read gyro and accelerometer compare with what the pilot wants work out corrections set the speed of each motor Think of balancing a broom on your palm: your eyes are the sensors, your brain decides and your hand makes small corrections. Stop correcting, and the broom falls. A drone works the same way. So which brain should you choose?

ESP32 vs Arduino boards: which is better for drone projects?

Both are popular hobby boards, and both are good places to start. The honest answer depends on what you want to learn. What is an ESP32 drone? It is a drone whose flight controller is built around an ESP32, a microcontroller with Wi-Fi and Bluetooth built in. That’s why many ESP32 drone projects are flown from a phone or laptop over Wi-Fi, with no separate radio. A well-known open example is ESP-Drone from Espressif, the company that makes the ESP32. It is an ESP32-based mini drone with open hardware and firmware (the code that runs on the board), and its documentation is a good read for any ESP32 drone project. What is an Arduino drone? “Arduino” usually means a family of beginner-friendly boards and the Arduino IDE (the app you write code in). Classic Arduino boards are simpler and less powerful than an ESP32. Their huge strength is the community: years of tutorials, examples and forum answers. Here’s a helpful twist. You can program an ESP32 using the Arduino IDE, so the two worlds overlap more than people expect. A simple way to choose:

> * Want wireless control and room to grow? An ESP32 for your drone is a natural fit. > * Want the gentlest start, with the most examples? An Arduino-style board keeps things simple. > * Not sure? Pick whichever board you already own. The ideas carry over.

5 steps to start programming your drone

This is the path we’d suggest to a friend. Each step gives you a small win before the next one.

Step 1: Learn to fly before you code

It sounds backwards, but flying comes first. When you test code, you need to recognise instantly whether the drone is behaving well or badly. You also need the stick skills to land it calmly when something goes wrong. The cheapest crash is the one that happens on a screen. Our free BYOD flight simulator runs in your browser with no install. It has 6 missions and uses keyboard controls. Spend a few sessions there until a steady hover feels boring. Boring is good. Boring means your hands are ready.

Step 2: Set up your tools

Now for your first coding win. A common setup looks like this:

> 1. Install the Arduino IDE on your computer. > 2. If you’re using an ESP32, add ESP32 board support through the IDE’s Boards Manager. > 3. Connect your board with a USB cable, then select the right board and port. > 4. Open a “blink” sketch (a sketch is a small Arduino program) and upload it.

Here’s a generic blink sketch. It isn’t drone code yet, just proof that your tools work: // Generic example for learning. Not Aasma kit or AVO firmware. const int LED_PIN = 2; // check your board’s pinout; this varies by board

void setup() { pinMode(LED_PIN, OUTPUT); }

void loop() { digitalWrite(LED_PIN, HIGH); // LED on delay(500); // wait half a second digitalWrite(LED_PIN, LOW); // LED off delay(500); } If the upload fails, check three things first: is the cable a data cable rather than a charge-only one, is the right port selected, and does your computer need a USB driver for the board? When that light blinks, you have just written ESP32 code (or Arduino code) and run it on real hardware. Small, but real.

Step 3: Read your sensors with the propellers off

Before your code moves a single motor, make it listen. Remove the propellers, put the drone on your desk and power the board over USB. Most gyro and accelerometer modules have a library you can install in the Arduino IDE. Its examples will print sensor readings to the Serial Monitor, a window that shows text your board sends back to the computer. Now tilt the drone gently by hand and watch the numbers change. Lean it left: which number moves? Spin it slowly: what does the gyro do? This is the moment drone code stops being abstract. And you’ve built the most important habit of all: props off on the bench.

Step 4: Understand stabilisation and PID

This is the hardest idea in the guide, so let’s use a shower. You turn on the shower and it’s cold. You know how to fix it, and you are already using the three parts of a PID controller, the method many drones use to stay level:

> * P (proportional): the colder the water, the further you turn the knob. A big error gets a big correction. > * I (integral): if it has been slightly cold for a while, you nudge the knob a bit more. Small errors that last get fixed. > * D (derivative): if the water is heating up fast, you ease off before it scalds you. It stops you overshooting.

On a drone, the “temperature” is the angle or rotation the gyro measures. The “knob” is motor speed. The PID controller runs separately for roll (tilting side to side), pitch (tilting forward and back) and yaw (turning on the spot). Tuning means choosing how strong each part is. Too much P and the drone wobbles; too little and it feels lazy and drifts. This is why tuning is famously fiddly, even for experienced builders. > Try it at the keyboard. In the free simulator, try to hold a perfectly steady hover. Every small correction you make is your brain doing the same job a PID controller does.

Step 5: Add one small feature of your own

Now make something that is yours. Pick a project you can see working, and keep the props off while you build it.

> * Status LEDs: one colour when the battery reads low, another when the board is ready. > * Logging: print sensor readings with a time stamp, then open them in a spreadsheet and draw a graph of a tilt. > * A simple timed command: on the bench, have the code run one motor slowly for two seconds, then stop. > * For ESP32 builders: show live sensor readings on your phone over Wi-Fi.

Each of these is a proper ESP32 drone project or Arduino drone project in miniature. Each one teaches you how your code talks to real hardware. Once you’ve done this, a bigger choice is waiting.

Two paths: write your own code or build on ArduPilot?

There are two main roads from here. Neither is “right”. They teach different things.

Writing an ESP32 drone from scratch

Building an ESP32 drone from scratch means writing the whole loop yourself: reading sensors, combining them into an angle, running PID and driving motors. It teaches you the most, because nothing is hidden. It also takes the longest. Expect lots of bench testing and wobbly first hovers, and expect tuning to test your patience. Reading open projects like ESP-Drone or the Crazyflie firmware from Bitcraze helps, because you see how experienced teams have structured the same problem.

Using ArduPilot on an Arduino-compatible flight controller

ArduPilot is a mature open-source autopilot for copters, planes and rovers, built by a large community. It is widely used in education and research. Instead of writing stabilisation yourself, you install ArduPilot, set it up and tune it with a ground control station: software on your computer such as Mission Planner (Windows) or QGroundControl (cross-platform). This route gets you flying sooner. Your learning shifts to configuration, missions and safety features. And because ArduPilot is open source, you can still read its code whenever you’re curious how something works. ESP32 fans should know about ArduPilot’s ESP32 port. It is experimental, so treat it as a project to explore rather than something to rely on. For context, Aasma’s own AVO flight controllers run ArduPilot and are Arduino-compatible.

Where does Python fit in?

Can you program a drone with Python? Yes, but usually not in the place most people imagine. The fast control loop on the flight controller is normally written in languages like C or C++. Python usually runs on a computer and sends higher-level commands, such as “take off”, “fly to this point” or “land”. Those commands travel using MAVLink, a message language that autopilots like ArduPilot and PX4 use to talk to ground stations. To try it, look at pymavlink, which gives Python access to MAVLink messages. You could also look at MAVSDK-Python, a Python API (a ready-made set of commands) for PX4 and MAVLink drones. If you’re learning how to program a drone with Python, this is where your code will live.

Safe testing habits for new drone coders

New code is untested code. These habits protect your drone, your fingers and everyone nearby:

> * Props off for every first test of new code. Always. > * Unplug the flight battery while uploading over USB, unless your board’s guide says otherwise. > * Set up a quick kill switch. Know exactly how to cut the motors instantly before you arm (switch the motors live). > * Go low and slow. First flights of new code should be short, low hovers. Some builders tether the drone to a weight with a short line. > * Open space, people back. Keep others well away, and never test over people. > * One change at a time, so you know what caused any difference.

For rules about where and how you may fly in India, check the official government source: https\://www.dgca.gov.in/. Rules can change, so always read the latest version there.

Mistakes almost every new drone coder makes

> * Flashing new code and arming straight away “just to see”. Bench test first. > * Changing several PID values at once, then not knowing which one helped. > * Mixing up motor order or spin direction, so the drone flips the moment it lifts. > * Skipping the simulator, then learning stick skills with a real build.

You’ll make some of these anyway. Everyone does. Debugging is part of the fun.

For parents: is drone coding a good next step?

If your child has built a drone and wants to code it, that curiosity is worth backing. Drone programming for kids blends three things: logic (writing steps a machine follows), physics (why tilting makes you move) and debugging (calmly working out what went wrong). The best bit is the feedback. Code that works makes something move, in the real world, in front of them. Flying something you wrote yourself is a feeling no certificate can match. A gentle way to begin is the free browser simulator together, then the props-off bench steps above. Let them lead, and ask them to explain what their code does. You’ll be surprised how much they’ve picked up.

How Aasma helps you go from building to coding

Aasma Aerospace builds flight controllers and drone learning kits for students in India, with 4,000+ students trained so far. Our idea is simple: Build it. Fly it. Code it. The building part is covered in our guides on DIY drones. The flying part starts free in the simulator. When you’re ready to get your hands on a real build, there’s the Aasma BYOD kit.

Frequently asked questions

Can you build and program a drone with an ESP32?

Yes. The ESP32 is a popular choice for small drones, partly because it has Wi-Fi and Bluetooth built in. Open projects like Espressif’s ESP-Drone show how it’s done, and you can program an ESP32 using the Arduino IDE.

What is the best way to start learning drone programming?

Learn to fly first, ideally in a simulator. Then go step by step: get a blink sketch working, read your sensors with the props off, understand PID, and add one small feature of your own.

Can I program a drone with Python?

Yes, mostly for higher-level control. Python usually runs on a computer and sends commands like “take off” or “fly here” over MAVLink, using tools such as pymavlink or MAVSDK-Python. The fast stabilisation loop on the flight controller is usually written in C or C++.

Is Arduino or ESP32 better for a drone project?

Neither is better for everyone. ESP32 gives you built-in wireless and more processing power, while classic Arduino boards are simpler and have a huge library of beginner examples. Choose based on what you want to learn, or start with the board you already have.

Is drone programming suitable for kids?

It can be a great project for curious young learners, especially with an adult nearby for bench testing and flying. They practise logic, physics and debugging, and they see their code make something move. Starting in a free simulator keeps the first steps low-pressure.

Your next step

Before you write a single line of flight code, get your hands ready. Practise your flying for free in the browser at sim.aasmaaerospace.in: no install, 6 missions, just your keyboard. When hovering feels easy, take the next step with the Aasma BYOD kit. Then a fun question to sit with: once your drone can hold itself level, what would it take to make it fly a square all by itself? That’s where missions come in, and you’ll find more beginner guides on our blog.

Free in your browser

Practise free before you fly

Try the Aasma browser simulator: no install, 6 missions, keyboard controls. Teaching a class? We can bring this topic to your college as a hands-on workshop.

Share with a friend who builds drones

Free in your browser

Fly before you code

6 missions, keyboard controls, nothing to install.

For colleges

We teach this as a workshop module

Hands-on sessions in your lab, with our drones and the free simulator.

Keep reading

Scroll to Top