MotorDriverL9110S

From ArduinoInfo
Jump to navigation Jump to search

Motor Driver L9110S



The HG7881 (L9110S) Dual Channel Motor Driver Module is a compact board that can be used to drive very small robots.
This tiny module has two independent HG7881 (L9110S) motor driver chips which can each drive up 800mA of continuous current. The boards can be operated from 2.5V to 12V enabling this module to be used with both 3.3V and 5V microcontrollers.
A set of male header pins is used to connect this module to your robot's microcontroller brain. The motors are attached via two sets of screw terminals.
A PWM Pulse Width Modulation signal is used to control the speed of a motor and a digital output is used to change its direction. This module can also be used to drive a single four line two phase stepper motor. Four holes make this board easy to mount onto your robot or other project.

Motor Control Interface

Pin Description

B-IA Motor B Input A (IA)

B-IB Motor B Input B (IB)

GND Ground

VCC Operating Voltage 2.5-12V

A-IA Motor A Input A (IA)

A-IB Motor A Input B (IB)

Motor Truth Table

IA IB Motor State

L L Off

H L Forward

L H Reverse

H H Off


Motor Control Interface||~ Pin

Description
B-IA
Motor B Input A (IA)
B-IB
Motor B Input B (IB)
GND
Ground
VCC
Operating Voltage 2.5-12V
A-IA
Motor A Input A (IA)
A-IB
Motor A Input B (IB)
Motor Truth Table||~ IA
IB
Motor State
L
L
Off
H
L
Forward
L
H
Reverse
H
H
Off



We recommend applying a PWM signal to input IA to control the motor speed and a digital output to input IB to control its direction.
Note that the actual direction that "forward" and "reverse" turn your motor will depend on how it is oriented and wired. If your motor spins the wrong way, either swap the motor wires that connect to the output terminals or change the way the IA and IB bits get set in your program.

The HG7881 (L9110) is a compact motor driver chip that supports a voltage range from 2.5-12V at 800mA of continuous current. These chips have built-in output clamp diodes to protect your sensitive microcontroller electronics. They are suitable for very small robot projects.
Each HG7881 (L9110) chip is able to drive a single DC motor using two digital control inputs. One input is used to select the motor direction while the other is used to control the motor speed. Speed is controlled by using PWM Pulse Width Modulation. Motor drivers typically have what is called a truth table that determines the effect of its inputs. The truth table for a single HG7881 (L9110) chip is as follows:
HG7881 (L9110) Truth Table||||~ Input

Output
IA
IB
OA
IB
Description
L
L
L
L
Off
H
L
H
L
Forward
L
H
L
H
Reverse
H
H
H
H
Off

Note that the actual direction of "forward" and "reverse" depends on how the motors are mounted and wired. You can always change the direction of a motor by reversing its wiring.
The HG7881 (L9110) Dual Channel Motor Driver Module uses two of these motor driver chips. Each driver chip is intended to drive one motor, so having two means that this module can control two motors independently. Each motor channel uses the same truth table as above. Each set of screw terminals is used to connect a motor. Refer to the table below for pin header connections.
HG7881 (L9110) Dual Channel Motor Driver Module Connector||~ Pin

Description
B-IA
Motor B Input A (IA)
B-IB
Motor B Input B (IB)
GND
Ground
VCC
Operating Voltage 2.5-12V
A-IA
Motor A Input A (IA)
A-IB
Motor A Input B (IB)

We recommend using input 1A to control the speed of each motor and input 1B to control the direction.

EXAMPLE CODE

/*
  HG7881_Motor_Driver_Example - Arduino sketch
   
  This example shows how to drive a motor with using HG7881 (L9110) Dual
  Channel Motor Driver Module.  For simplicity, this example shows how to
  drive a single motor.  Both channels work the same way.
   
  This example is meant to illustrate how to operate the motor driver
  and is not intended to be elegant, efficient or useful.
   
  Connections:
   
    Arduino digital output D10 to motor driver input B-IA.
    Arduino digital output D11 to motor driver input B-IB.
    Motor driver VCC to operating voltage 5V.
    Motor driver GND to common ground.
    Motor driver MOTOR B screw terminals to a small motor.
     
  Related Banana Robotics items:
   
    BR010038 HG7881 (L9110) Dual Channel Motor Driver Module
    https://www.BananaRobotics.com/shop/HG7881-(L9110)-Dual-Channel-Motor-Driver-Module
 
  https://www.BananaRobotics.com
*/

// wired connections
#define HG7881_B_IA 10 // D10 --> Motor B Input A --> MOTOR B +
#define HG7881_B_IB 11 // D11 --> Motor B Input B --> MOTOR B -

// functional connections
#define MOTOR_B_PWM HG7881_B_IA // Motor B PWM Speed
#define MOTOR_B_DIR HG7881_B_IB // Motor B Direction

// the actual values for "fast" and "slow" depend on the motor
#define PWM_SLOW 50  // arbitrary slow speed PWM duty cycle
#define PWM_FAST 200 // arbitrary fast speed PWM duty cycle
#define DIR_DELAY 1000 // brief delay for abrupt motor changes

void setup()
{
  Serial.begin( 9600 );
  pinMode( MOTOR_B_DIR, OUTPUT );
  pinMode( MOTOR_B_PWM, OUTPUT );
  digitalWrite( MOTOR_B_DIR, LOW );
  digitalWrite( MOTOR_B_PWM, LOW );
}

void loop()
{
  boolean isValidInput;
  // draw a menu on the serial port
  Serial.println( "-----------------------------" );
  Serial.println( "MENU:" );
  Serial.println( "1) Fast forward" );
  Serial.println( "2) Forward" );
  Serial.println( "3) Soft stop (coast)" );
  Serial.println( "4) Reverse" );
  Serial.println( "5) Fast reverse" );
  Serial.println( "6) Hard stop (brake)" );
  Serial.println( "-----------------------------" );
  do
  {
    byte c;
    // get the next character from the serial port
    Serial.print( "?" );
    while( !Serial.available() )
      ; // LOOP...
    c = Serial.read();
    // execute the menu option based on the character recieved
    switch( c )
    {
      case '1': // 1) Fast forward
        Serial.println( "Fast forward..." );
        // always stop motors briefly before abrupt changes
        digitalWrite( MOTOR_B_DIR, LOW );
        digitalWrite( MOTOR_B_PWM, LOW );
        delay( DIR_DELAY );
        // set the motor speed and direction
        digitalWrite( MOTOR_B_DIR, HIGH ); // direction = forward
        analogWrite( MOTOR_B_PWM, 255-PWM_FAST ); // PWM speed = fast
        isValidInput = true;
        break;

      case '2': // 2) Forward      
        Serial.println( "Forward..." );
        // always stop motors briefly before abrupt changes
        digitalWrite( MOTOR_B_DIR, LOW );
        digitalWrite( MOTOR_B_PWM, LOW );
        delay( DIR_DELAY );
        // set the motor speed and direction
        digitalWrite( MOTOR_B_DIR, HIGH ); // direction = forward
        analogWrite( MOTOR_B_PWM, 255-PWM_SLOW ); // PWM speed = slow
        isValidInput = true;
        break;

      case '3': // 3) Soft stop (preferred)
        Serial.println( "Soft stop (coast)..." );
        digitalWrite( MOTOR_B_DIR, LOW );
        digitalWrite( MOTOR_B_PWM, LOW );
        isValidInput = true;
        break;

      case '4': // 4) Reverse
        Serial.println( "Fast forward..." );
        // always stop motors briefly before abrupt changes
        digitalWrite( MOTOR_B_DIR, LOW );
        digitalWrite( MOTOR_B_PWM, LOW );
        delay( DIR_DELAY );
        // set the motor speed and direction
        digitalWrite( MOTOR_B_DIR, LOW ); // direction = reverse
        analogWrite( MOTOR_B_PWM, PWM_SLOW ); // PWM speed = slow
        isValidInput = true;
        break;

      case '5': // 5) Fast reverse
        Serial.println( "Fast forward..." );
        // always stop motors briefly before abrupt changes
        digitalWrite( MOTOR_B_DIR, LOW );
        digitalWrite( MOTOR_B_PWM, LOW );
        delay( DIR_DELAY );
        // set the motor speed and direction
        digitalWrite( MOTOR_B_DIR, LOW ); // direction = reverse      
        analogWrite( MOTOR_B_PWM, PWM_FAST ); // PWM speed = fast
        isValidInput = true;
        break;

      case '6': // 6) Hard stop (use with caution)
        Serial.println( "Hard stop (brake)..." );
        digitalWrite( MOTOR_B_DIR, HIGH );
        digitalWrite( MOTOR_B_PWM, HIGH );
        isValidInput = true;
        break;

      default:
        // wrong character! display the menu again!
        isValidInput = false;
        break;
    }
  } while( isValidInput == true );

  // repeat the main loop and redraw the menu...
}
/*EOF*/




https://github.com/helreizer/Arduino-projects/tree/master/Libraries/Moto
zz