DC motors are everywhere in robotics, thanks to their ease of control and ability to deliver both speed and power. But one key problem: they lack built-in feedback. So, to control their movement precisely, we need some external help.
One common way to do this is to use a servo motor, which is a DC motor with a built-in potentiometer and a control circuit. A servo motor can rotate to a specific angle based on the input signal from the controller. However, servo motors can be expensive and they may not have enough torque or speed for some applications.
Another way to control the position of a DC motor is to use a separate potentiometer as a feedback device. A potentiometer is a variable resistor that changes its resistance value based on the rotation of its knob. By attaching one to the motor shaft and measuring the voltage across it, we can estimate the motor's position. Then, an Arduino comes in to compare the desired position with the actual one, adjusting the motor's speed and direction accordingly.
In this project, I will use an N20 DC geared motor, known for its small size and impressive power thanks to its metal gearbox that increases torque while reducing speed. I will also use a 3D-printed case and gears to attach the potentiometer to the motor. The case has a slot for the motor and the potentiometer, and the gears have 10 and 30 teeth respectively, to create a 3:1 ratio between the motor and the potentiometer. This means for every full rotation of the motor, the potentiometer will only rotate 120 degrees.
I'll use an Arduino Uno along with an L293D shield to control the motor. This shield acts as a driver, capable of handling up to four DC motors or two stepper motors. It has four input and output pins for each motor, providing up to 600mA current per channel, plus a 5V regulator and power switch, and it can be stacked on top of the Arduino.
The Arduino reads the analog value from the potentiometer (mapped to a range of 0 to 1023) and the desired position sent through the computer's serial input. It then calculates the error between these two values and uses a proportional control algorithm (with a constant factor called Kp) to adjust the motor's speed and direction. This algorithm basically converts the error into an output signal (between 0 and 255) sent to the L293D shield. The shield then translates this signal into a PWM signal that controls the motor accordingly.
To keep track of what's happening, the Arduino displays the current and desired positions along with the error on the serial monitor. This lets you see how the motor behaves and even allows you to enter new desired positions to test the system's response in real-time.
With this setup, you have a cost-effective and precise way to control your DC motor's position, opening up exciting possibilities for your robotics projects!
Comments
Please log in or sign up to comment.