https://github.com/auralius/arduino-pid-template
A template for implementing PID control in an Arduino Uno
https://github.com/auralius/arduino-pid-template
arduino control-systems pid
Last synced: about 1 month ago
JSON representation
A template for implementing PID control in an Arduino Uno
- Host: GitHub
- URL: https://github.com/auralius/arduino-pid-template
- Owner: auralius
- Created: 2024-12-18T05:13:44.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-27T18:18:26.000Z (over 1 year ago)
- Last Synced: 2025-05-16T20:42:15.786Z (about 1 year ago)
- Topics: arduino, control-systems, pid
- Language: C++
- Homepage:
- Size: 17.6 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This repository contains a template for implementing a PID control in an Arduino Uno.
**Check the [this note](https://github.com/auralius/arduino-pid-template/blob/main/Notes%20on%20PID%20control%20with%20Arduino.pdf) on the control derivation.**
The PID is implemented as a periodic task for Timer 1. The PID runs constantly (hard realtime) at 1 kHz, while serial communication runs in the background and when the resource is available.
As an example, we use a cheap N20 DC motor that is already equipped with a quadrature encoder.

The motor was purchased from:
https://www.tokopedia.com/cncstorebandung/motor-dc-jga12-n20-dc-3-6v-high-torque-micro-dc-gearbox-jga12-n20-with-encoder-71-rpm-a1015
To drive the motor, we use an Arduino Motor Shiled rev 3. The complete system is as follows:

To avoid recompiling the codes every time we tune the controller, we propose the following input configuration:

To log and plot the motor data, we use CoolTerm and gnuplot. The logged data format is as follows:

The following GIF animation shows that the implemented controller works.
