When working with brushed DC motors, controlling their speed and direction is key to building functional robotics, automation systems, and interactive projects. DriveCell is a tiny compact motor driver based on the DRV8837 H-Bridge, simplifies this process by providing an easy-to-use library. In this guide, we'll explore how DriveCell works, how to control a DC motor, and how to connect multiple motors efficiently.
A brushed DC motor is a simple type of electric motor where current flows through a set of brushes and a commutator to create rotational motion. It operates based on the principle of electromagnetic induction, which generates a magnetic field inside the motor, pushing it into continuous rotation.
Unlike servo motors or stepper motors, brushed DC motors require two input signals to control their movement:
This is where H-Bridge drivers like the DRV8837 in DriveCell come into play. The H-Bridge circuit allows current to flow in both directions, enabling bidirectional motor control with just two input pins.
Before connecting your motors, it's essential to understand the DriveCell's electrical limitations:
If your motor requires less than 0.5A, you can also connect two motors in parallel and drive them using a single DriveCell.
Here’s how to wire a single DC motor to DriveCell:
If your motors consume less than 500mA each, you can connect two motors in parallel:
This setup will drive both motors synchronously, making them spin in the same direction at the same speed.
To make motor control simple, DriveCell provides an software library. Below are the key functions you’ll need:
The following example demonstrates how to control two motors at different speeds:
#include <DriveCell.h>
#define IN1_pin1 2
#define IN1_pin2 3
#define IN2_pin1 5
#define IN2_pin2 6
DriveCell Motor1(IN1_pin1, IN1_pin2);
DriveCell Motor2(IN2_pin1, IN2_pin2);
void setup() {
Motor1.Init();
Motor2.Init();
}
void loop() {
delay(3000);
Motor1.Drive(1, 40); // Move Forward at 40% speed
Motor2.Drive(1, 80); // Move Forward at 80% speed
delay(3000);
Motor1.Drive(0, 50); // Move Backward at 50% speed
Motor2.Drive(0, 50); // Move Backward at 50% speed
delay(3000);
Motor1.Drive(0, 0); // Set to 0% speed
Motor2.Drive(0, 100); // Move Backward at 100% speed
}
⚠ Note: The Drive()
function in this example uses a high-speed PWM timer, making it compatible only with CodeCell and other ESP32-based devices.
Below is another example that can be used with other microcontrollers like the Arduino Uno:
#include <DriveCell.h>
#define IN1_pin1 2
#define IN1_pin2 3
DriveCell myDriveCell(IN1_pin1, IN1_pin2);
void setup() {
myDriveCell.Init();
}
void loop() {
myDriveCell.Run(1000); // Run motor forward for 1 second, then reverse
}
This example will spin the motor in one direction for 1 second and then reverse its direction, creating a simple oscillating motion.
The tiny DriveCell module makes DC motor control simple and easy to use! Check out the DriveCell GitHub Repository for more code examples and technical documentation!
Erfahren Sie als Erster von neuen Projekten und sichern Sie sich spannende Angebote!
© 2025 Microbots.