MotorCell utilizes the BD67173NUX three-phase back-EMF controller with a sensorless drive system, allowing speed control via a PWM input signal duty cycle. The IN pin defaults to low, running the motor at full speed when pulled high (2.5V–5V). You can adjust the speed in 1,000 RPM increments via the duty cycle, or directly use the MotorCell library functions.
To get started, install the MotorCell library from the Arduino Library Manager:
The library includes examples to help you quickly get started with MotorCell control.
We going to start with control the speed level using the Spin function. This function adjusts the motor’s speed to the desired percentage of its maximum capability and returns the current RPM value. This value is also automatically printed on the Serial Monitor, for easy debugging. If the motor stalls, it will automatically attempt to restart.
#include <MotorCell.h>
#define IN_pin1 2
#define OUT_pin2 3
#define FR_pin2 1
MotorCell myMotorCell(IN_pin1, OUT_pin2, FR_pin2); /* Configure the MotorCell pins */
void setup() {
Serial.begin(115200); /* Set up serial - Ensure Tools/USB_CDC_On_Boot is enabled */
myMotorCell.Init(); /* Initialize the MotorCell */
}
void loop() {
uint16_t MotorRPM = myMotorCell.Spin(25); /* Set speed to 25% of maximum speed */
}
⚠ Note: For this function we recommend using an ESP32 device like the CodeCell to avoid delays when reading the RPM
This next example demonstrates how to reverse the motor’s direction every 5 seconds while running it at full speed. The MaxSpin function sets the motor to its maximum speed, while the ReverseSpin function changes its rotation direction. This alternates between clockwise and counterclockwise rotation with a 5-second delay between each direction change.
#include <MotorCell.h>
#define IN_pin1 2
#define OUT_pin2 3
#define FR_pin2 1
MotorCell myMotorCell(IN_pin1, OUT_pin2, FR_pin2); /* Configure the MotorCell pins */
void setup() {
Serial.begin(115200); /* Set up serial - Ensure Tools/USB_CDC_On_Boot is enabled */
myMotorCell.Init(); /* Initialize the MotorCell */
}
void loop() {
myMotorCell.MaxSpin(); /* Set motor to maximum speed */
myMotorCell.ReverseSpin(); /* Reverse the motor's rotation direction */
delay(5000); /* Wait for 5 seconds */
myMotorCell.MaxSpin(); /* Maintain maximum speed */
myMotorCell.ReverseSpin(); /* Reverse direction again */
delay(5000); /* Wait for another 5 seconds */
}
This final example implements a PID controller to regulate the motor speed to the desired RPM using the SpinPID function. The PID controller dynamically compensates for disturbances and load variations, ensuring smooth operation. If the motor stalls, the function will automatically restart it and notify you if the target speed cannot be reached. This is also automatically printed on the Serial Monitor, for easy debugging.
#include <MotorCell.h>
#define IN_pin1 2
#define OUT_pin2 3
#define FR_pin2 1
MotorCell myMotorCell(IN_pin1, OUT_pin2, FR_pin2); /* Configure the MotorCell pins */
void setup() {
Serial.begin(115200); /* Set up serial - Ensure Tools/USB_CDC_On_Boot is enabled */
myMotorCell.Init(); /* Initialize the MotorCell */
}
void loop() {
uint16_t MotorRPM = myMotorCell.SpinPID(15000); /* Set target RPM to 15,000 using PID */
}
⚠ Note: The SpinPID()
function uses a high-speed PWM timer, making it compatible only with CodeCell and ESP32-based devices.
With the MotorCell library installed, you can easily control speed, direction, and monitor its RPM!
Ready to start experimenting? Grab a MotorCell today and check out the MotorCell GitHub Repository for more code examples and technical documentation!
Join our Community ~ Be the first to know about new products and get exciting deals!
© 2025 Microbots.