Fig. 1
Click for larger image.
Arduino Constant Current H-Bridge Motor Control
by Lewis Loflin
Follow @Lewis90068157
See related videos at YouTube:
Arduino CCS H-Bridge with Large DC Motor
Program Code Arduino CCS H-Bridge Motor Control
This project is the culmination of several earlier projects. This will use an Arduino or other microcontroller (uPC) to control a constant current source (CCS).
This CCS supplies power to an H-bridge control circuit and associated DC motor. The microcontroller controls both speed and direction of the DC motor.
The constant current circuit is placed between the H-bridge and the motor power supply.
Both the CCS circuit and H-bridge circuit are electrically isolated from the microcontroller through the use of optocouplers.
The motor in Fig. 1 was salvaged from a treadmill and is rated 100V at 2.9 hp. The motor has a heavy flywheel and will be operated at 20V.
The H-bridge when turned off "grounds" out the motor winding creating a braking action to stop the motor. This will actually throw the motor around if not secured due to the energy in the flywheel.
When first turned on motor current is heavy until the flywheel comes up to speed. The current drops back to 600mA to sustain the rotation. This is expected.
Fig. 2
Fig. 2 is a basic Arduino control. Uses only three outputs and two inputs. The program reads the state of SW1 and SW2 to determine direction of motor rotation, off-on. A 10K potentiometer is used in manual mode to control speed of motor.
Fig. 3
Click for larger image.
Fig. 3 illustrates a typical opto-isolated constant current source using an LM317 and MJ2955 PNP transistor. This has been covered extensively elsewhere. Maximum current is preset with the 200-Ohm potentiometer.
The addition of an opto-isolator is new. See the following:
- YouTube
- Adjustable LM317 High Power Current Source
- Current Boost LM317 Adj. Power Supply
- LM317 Constant Current Source Circuits
Fig. 4
Click for larger image.
Fig. is a basic 4 MOSFET H-bridge covered elsewhere. The optocouplers isolate the microcontroller from the higher motor voltage.
The IRFZ44N (Q3, Q4) is an N-channel device rated at 55V and RDS(on) resistance of 0.032 Ohms max. The IRF4905 (Q1, Q2) is a P-channel device rated at 55V and a RDS(on) of 0.02 Ohms max.
The optocouplers used here are PC817.
Fig. 5
Click for larger image.
Fig. 5 is the H-bridge in the "brake" condition. With no input to the optocouplers Q1 and Q2 are turned off. Q3 and Q4 are turned on through the 10K pullup resistors.
This shunts mother motor connection to ground "braking" the motor.
The Arduino code is presented below. This is a series of "if" statements that toggle the H-bridge control pins Din1 and Din2.
The pulse-width-modulation is only on when either H-bridge control pins (DP10, DP11) are HIGH. The speed is set by the 10k potentiometer on Arduino Analog 0.
When either switch is pressed the h-bridge outputs are placed in the "brake" mode and delayed a half second. Then the motor direction control pin is turned on.
/* Constant current control of DC motor speed with H-bridge. Uses opto-isolators control direction and isolate PWM. Two push buttons connected to ground, uses internal pull ups. by Lewis Loflin lewis@bvu.net https://www.bristolwatch.com */ #define pot 0 // 10K potentiometer analog pin 0 #define PB1 2 // PB connected to GRD #define PB2 3 // PB connected to GRD #define MotorSpeed 9 // PWM to CCS optocoupler #define HB1 11 // Output to h-bridge Din1 #define HB2 10 // output to h-bridge Din2 int val = 0; // variable to store the pot value void setup() { pinMode(MotorSpeed, OUTPUT); digitalWrite(MotorSpeed, LOW); pinMode(HB1, OUTPUT); pinMode(HB2, OUTPUT); digitalWrite(HB1, LOW); digitalWrite(HB2, LOW); pinMode(PB1, INPUT); pinMode(PB2, INPUT); // HIGH is switch open // same as INPUT_PULLUP digitalWrite(PB1, HIGH); // pullup on digitalWrite(PB2, HIGH); // pullup on } void loop() { if (digitalRead(PB1) == 0 && digitalRead(PB2) == 1) { analogWrite(MotorSpeed, 0); // pwm off digitalWrite(HB1, LOW); // brake digitalWrite(HB2, LOW); delay(500); digitalWrite(HB1, HIGH); digitalWrite(HB2, LOW); } if (digitalRead(PB1) == 1 && digitalRead(PB2) == 0) { analogWrite(MotorSpeed, 0); // pwm off digitalWrite(HB1, LOW); // brake digitalWrite(HB2, LOW); delay(500); digitalWrite(HB1, LOW); digitalWrite(HB2, HIGH); } // read latches HB1 and HB2, if either HIGH PWM ON if (digitalRead(HB1) == 1 || digitalRead(HB2) == 1) { val = analogRead(pot) / 4 ; // read the input pin analogWrite(MotorSpeed, val); // ADC values 0-255 } else { analogWrite(MotorSpeed, 0); // pwm off } // end else if (digitalRead(PB1) == 0 && digitalRead(PB2) == 0) { digitalWrite(HB1, LOW); // brake digitalWrite(HB2, LOW); delay(500); } } // end loop
- TL431 Battery Charger Voltage Detector Circuits Schematics
- Arduino Constant Current H-Bridge Motor Control
- TL431 Battery Charger Voltage Detector Circuits Schematics
- TL431 Sink Mode Constant Current Circuits
- Alternate H-Bridge Circuits
- IGBT Based High Voltage H-Bridge DC Motor Control
- Arduino Controlled IR2110 Based H-Bridge HV Motor Control
Fig. 6
Click for larger image.
In Fig. 6 a low value resistor and an LM358 op-amp enables a microcontroller to measure motor load current.
See
- Arduino Measures Current from Constant Current Source
- Measure Current from Constant Current Source with Arduino
- Arduino Controlled Power Constant Current Source
- Arduino Controlled Constant Current Source YouTube video
- YouTube
- Short Video Using PuTTY Terminal Program and USB to RS-232 May 2020
- Basic Hall Effect Sensors 1 Dec. 2010
- PIC programming
- How to Use K150 PIC Programmer Oct 2016
- Using Velleman K8048 PIC Development Board Oct 2016
Fig. 7 Modules used: constant current source, Arduino breakout board, and basic MOSFET H-bridge.
- 3 Bipolar Transistors in Parallel and Other Issues
- How and Why to Connect Bipolar Transistors in Parallel
- LM317 High Powered Current Source 2024
- Using TL431A Li-Ion Battery Charger Tutorials
- TL431A Lithium-Ion Cell Charging Circuits
- Charging Multi-Cell Lithium-Ion Battery Packs
- TL431 Over-Voltage, Under-Voltage Detector Circuits
- TL431A Constant Current Source Working Circuits Demo
- Power TL431 Constant Current Source Circuits
- LM317 Adjustable Current Boost Power Supply
- Constant Current Circuits LM334, LM317
- Build LM317 0-34 Volt Power Supply
- LM334 Constant Current Source with Resistive Sensors
- LM317 High Power Constant Current Source Circuit
- LM317 Constant Current Source Circuits
- Test SCRs and Triacs
- Basic MOSFET Transistor Test Circuits
- High Voltage MOSFET Switching Circuits
- 3 Amp LM741 Op-Amp Constant Current Source
- Current Limiter Testing of Zener Diodes
- Current Limiter for Opto-Coupler Inputs
- LM317 CCS for Light Emitting Diodes
Other Circuits
- Hall Effect Magnetic Switches and Sensors
- Comparator Theory Circuits Tutorial
- ULN2003A Darlington Transistor Array with Circuit Examples
- Transistor-Zener Diode Regulator Circuits
- AC Power Supply Rectification
- Coils for Highly Selective Crystal Radio
- Neon (NE-2) Circuits You Can Build
- Photodiode Circuits Operation and Uses
- Photodiode Op-Amp Circuits Tutorial
Web site Copyright Lewis Loflin, All rights reserved.
If using this material on another site, please provide a link back to my site.