.

Arduino controls large motor through a constant current source and H-bridge circuit.
Fig. 1
Click for larger image.

Arduino Constant Current H-Bridge Motor Control

by Lewis Loflin


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.

Arduino used as a motor direction and speed controller.
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.

Opto-isolated constant current source using an LM317 and MJ2955 PNP transistor.
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:

A basic 4 MOSFET H-bridge.  Optocouplers isolate the microcontroller from the higher motor voltage.
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

Measure load current motor Arduino pulse-width modulation.
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

Modules used: constant current source, Arduino breakout board, and basic MOSFET H-bridge.
Fig. 7 Modules used: constant current source, Arduino breakout board, and basic MOSFET H-bridge.


Other Circuits


 

Web site Copyright Lewis Loflin, All rights reserved.
If using this material on another site, please provide a link back to my site.