Source: https://mokxi.com/learn/pid-control-course
Updated: 2026-11-11

Embedded track
PID control

# Learn PID control by standing up a balance bot

Read tilt from an IMU, see what the wheels do to it, then write and tune the PID loop that keeps a two-wheel robot upright.

Free In your browser 2 courses, 10 lessons, about 6 hours

Start free Balance bot 1: read the tilt See the course

Overview

## How you will learn it

PID control is how a drone holds its height, a printer holds its temperature and a robot keeps its balance: measure the error, then push back in proportion to it, to how long it has lasted and to how fast it is changing. It is much easier to understand by tuning one than by reading the formula.

Build a balance bot gets there on a simulated Uno: read the tilt, see what the motors do to it, then write the PID and tune P, I and D while the robot falls over and finally stands.

Outcomes

## What you will learn

- Read tilt from an MPU6050 and filter it.
- Explain what P, I and D each do, from watching them.
- Write a PID loop with a fixed sample time.
- Tune gains by a method, not by luck.

Your route

## The courses and lessons to take

Every lesson opens in the editor right away, signed in or not, and the simulator checks each step.

- Step 1 · 3 lessons · 2 h

### Build a balance bot

The whole build.

- Balance bot 1: read the tilt Wake the robot’s MPU6050 and turn its readings into a tilt three ways: from gravity, from the gyro, and with a complementary filter that blends the two. Then watch them follow the robot as it falls.
- Balance bot 2: what the wheels do Drive the wheels forward and the body tips back: the move every balancing robot is made of. Then balance on P and D alone and see why that is not quite enough.
- Balance bot 3: the PID that stands it up The finished balance bot: a complementary filter, a PID with three knobs for Kp, Ki and Kd, and the angle and gains on an OLED. Push it, turn the knobs, and tune it.
Every lesson in the course
- Step 2 · 7 lessons · 4 h

### Motors and motion

The motor driving and encoder reading underneath.

- A DC motor on a driver: speed and direction Two gear motors on an L298N: why a pin cannot run a motor, two inputs for direction, PWM on the enable for speed, and the volts a bipolar driver keeps for itself.
- An encoder: measure what the motor really did A gear motor with a Hall encoder on an L9110S pumps an exact dose: count pulses on an interrupt, work out speed from them, and slow down before the mark so it stops on it.
Every lesson in the course

Keep going

## Guides and tools on the same subject

Simulator

### PID simulator

Open it

Guide

### Arduino self-balancing robot

Open it

Library

### Arduino PID library

Open it

Track

### Embedded track

Arduino, ESP32, Raspberry Pi Pico and STM32: pins, timing, buses, motors, WiFi, registers and debugging, every lesson checked on a simulated board.
See the whole track

Questions

## Questions people ask

What does PID stand for?

Proportional, integral and derivative: three terms that push back against the present error, the error built up over time, and how fast the error is changing.

Do I need calculus for PID?

No. The integral is a running sum and the derivative is the change since the last reading. The lesson writes both as plain code.

How do I tune a PID controller?

Start with P alone until it oscillates, add D to calm it, then a little I to remove the last offset. The lesson walks through this on the robot so you can see each step.
