Avatar
PID DC BRUSHED MOTOR CONTROL
Aug 19th, 2019 | by: ELECTRONOOBS | Views 3137
Views 3137
In this tutorial we will see how to control one axis but using BRUSHED DC MOTORS. Usually CNC axis will move using stepper motors in an open loop control. Here we will see an example of close loop control with an optic encoder as feedback. Why do this? well, for bigger motors, the price of stepper motors and drivers could get very high. Using DC brushed motors with a gear box and close loop control could get cheaper. Lets see how to do this. 
What we need

I will make just only one axis. See full part list also here on this link. For that we need the parts below. The motor with the encoder in quadrature, the H bridge driver, the Arduino with a potentiometer and the rest of components. For the motor you could get only the motor and then make your own gear system or buy directly the motor witha gear box. See the scheamtic for all the connections.

We need:

 

  1. 1 x Arduino NANO/UNO: LINK eBay
  2. 1 x DC motor with encoder: LINK eBay
  3. 1 x H bridge L298N: LINK eBay
  4. 1 x end stop SWITCH: LINK eBay
  5. 1 x Potentiometer 10 turns: LINK eBay
  6. 2 x smooth rod 8mm: LINK eBay
  7. 1 x lead screw: LINK eBay
  8. 4 x lineal bearing LM8UU: LINK eBay
  9. 1 x STL 3D files: LINK eBay
  10. 1 x GEARS: LINK eBay
  11.  

 

    • Extra wire, solder, soldering-iron, breadboard, etc

I've mounted everything on a plywood baord. We also need some M3 screws for that or maybe some glue. Some lubrificant for the rods and lead screw also would be good. 

Schematic

Make the connections as below. Supply a different connection to the H bridge with enough current. Remember to share GND with all the modules. The End stop swithc will need a pullup and give a low pulse when the siwthc is pressed, otherwise you will need to change that in the code. The encoder needs 5V, GND and two encoder outputs

Schematic
Code

Copy the code from below or download it from the link. You will need to install the needed libraries. Go to the link below and find those libraries and install them to your Arduino IDE. Read all the lines in the code to understand more. The setpoint is given with the potentiometer but you could use Serial read for example and give precise values for the setpoint and see the results.


//Include the libraries we need
#include <PinChangeInterrupt.h>
#include <PinChangeInterruptBoards.h>
#include <PinChangeInterruptPins.h>
>#include <PinChangeInterruptSettings.h>
#include <TimerOne.h>
 


Video

See the video for more information and see what options you have for the encoder, how to detect the pulses and so on. I hope you will like this project. Comment below and help the community. COnsider supporting me on PATREON.

1 Comment

  • Noob 4248

    about 3 years ago

    Hola !!! Estoy tratando de recrear el proyecto de PID balanza con motores Brushels y estoy teniendo algunos inconvenientes, estoy utilizando el codigo que ustedes facilitaron pero solamnete me gira un solo motor, PORFAAA !!! necesito su ayuda, gracias.

Login or Sign Up to post comments on this tutorial.