Using Servo Motors with ESP32

How to control Servo Motors with an ESP32 – directly, using I2C, and over WiFi.

Article with code: https://dbot.ws/esp32srvo
More articles and tutorials: https://dronebotworkshop.com
Join the conversation on the forum: https://forum.dronebotworkshop.com
Subscribe to the newsletter and stay in touch: https://dbot.ws/dbnews

We are working with the ESP32 again, today we’ll see a few different methods of controlling a servo motor using this amazing 32-bit microcontroller.

The ESP32 is well-suited to controlling analog servo motors as it has 16 PWM outputs. It’s built-in WiFi and Bluetooth open the doors to all sorts of remote control possibilities.

Although the ESP32 can’t use the Arduino Servo Library there are many replacement libraries available. I’ll be working with the ESP32Servo Library for most of these experiments.

We’ll see how to interface a servo to the ESP32 and then we’ll look at a few code examples that emulate the examples included with the Arduino.

We’ll also hook up a PCA9685 PWM controller to the ESP32 using its I2C connections. This is a great way to drive a lot of servo motors as each PCA9685 has 16 PWM outputs and you can cascade them to control up to 992 motors! I’ll only be using two motors for my demo.

One great reason to use an ESP32 over an Arduino is the built-in wireless communications. In the final example, we will control a servo motor with a web-based interface over WiFi.

Here is the Table of Contents for today’s video:

00:00 – Introduction
02:51 – Servo Motors & ESP32
10:10 – Hookup & ESP32Servo Library
15:08 – Sweep Sketch
19:23 – Improved Sweep Sketch
21:36 – Knob Sketch
27:18 – ESP32 & PCA9685 –
37:46 – WiFi Web-based Servo Control

There is also an article on the DroneBot Workshop website with the code used here in case you want to try some of these experiments on your own.

I’ll be doing another project based upon ESP32 and servo motors very soon, so keep your eyes out for it by subscribing to the channel.

Thanks, and I hope you enjoy the video.

source

You might be interested in