An Arduino Library for controlling DC motors with rotary encoders. This library is an updated version and continuation of julester23 / DCMotorServo uses PID and Encoder feedback, inspired by the adafruit / AccelStepper library.
- Encoder Library, for measuring quadrature encoded signals from the Arduino library manager and also on pjrc.com/teensy/td_libs_Encoder.html
- PID Library, for using encoder feedback to control the motor from the Arduino library manager and also on github.com/br3ttb/Arduino-PID-Library
I used a 754410 quad half-H controller (a pin-compatible L293D). I'm sure it would be cheaper to make out of other components, but I've never done transistor matching, and I'm afraid of burning things.
L293D or 754410 pins | Device | |
---|---|---|
1, 9 | arduino | pin_pwm_output |
2, 15 | arduino | pin_dir |
7, 10 | arduino | pin_dir |
4, 5, 12, 13 | power | GND |
16 | power | 5V |
8 | power | 12V |
3, 14 | motor | motor pin 1 |
6, 11 | motor | motor pin 2 |
- Example 1: Move_1inch
- Example 2: XXX
Pinout for motor control uses 3 pins for output. It is somewhat wasteful, but had more flexibility. Two pins for direction control, and one for motor power (assuming PWM). Be sure to pick a PWM capable pin for pin_pwm_output.
The two input pins are for the encoder feedback.
Two directional pins allow for setting a motor brake by shorting the terminals of the motor together (set both directions HIGH, and preferably turn off the PWM)
- implement brake feature for 3-pin mode
- 2-pin constructor
- implement friendlier tuning method for PID