- Install
- Basic operation
- Basics of programming for electronic work
- Connect to micro computer
- Input / Output
- PWM Output
- Motor control
- Servo motor control
- Control servo motor using PCA9685
- Display
- Sensor
- Micro controller
- Basics of programming for Excel
- Machine learning with scikit-learn
- Visualizing data with matplotlib
- Web programming
- RPA programming
- Miscellaneous programming
- Reference
Control servo motor using PCA9685
You can control servo motors using the PCA9685, which can output PWM signals.
PCA9685-related blocks are located in the "Motor" - "PCA9685" group.
Wiring
The PCA9685 connects to the microcontroller via I2C.
The pin numbers used for I2C connection vary depending on the microcontroller.
For more information, see the "I2C Connection" page.
For example, with a plain ESP32, connect SDA to pin 21 and SCL to pin 22.
Also, connect VCC and GND to the microcontroller's 3V3 (or 5V) and GND pins.
Connect the servo motor to the 3-pin terminals for PWM/V+/GND (0-15).
Also, connect an external power supply (5-6V) to the V+ and GND terminal blocks.
When using an ESP32 as the microcontroller and connecting a servo motor to pin 0 of the PCA9685, the wiring should look like the diagram below.
Initialization
For microcontrollers with fixed I2C pin numbers, such as the original ESP32, use the "PCA9685 Initialization" block.
![]()
Also, for microcontrollers with variable I2C pin numbers, such as the ESP32-S3, use a block to specify the pin number during initialization.
Rotating a Servo Motor
You can use the rotation block to rotate a servo motor from 0 to 180 degrees.
Specify pin numbers 0 through 15 and the desired rotation angle.
![]()
Specifying the Pulse Width
Depending on the servo motor, it may not rotate sufficiently from 0 to 180 degrees.
In that case, try adjusting the pulse width corresponding to 0 and 180 degrees using the pulse width specification block.
By default, the pulse widths corresponding to 0 and 180 degrees are 500 and 2550, respectively.
Example
This example shows how to rotate two servo motors connected to a PCA9685 over a range of 0 to 180 degrees.
The microcontroller has a variable I2C interface, and SDA and SCL are connected to pins 4 and 5, respectively.
This program can be downloaded from here.