Position: Index > Bridge Circuit >

L298N Dual H-Bridge connected to a bi-polar stepper motor

2016-05-16 15:16  
Declaration:We aim to transmit more information by carrying articles . We will delete it soon, if we are involved in the problems of article content ,copyright or other problems.

     L298N Dual H-Bridge connected to a bi-polar stepper motor

 L298N Dual H-Bridge connected to a bi-polar stepper motor

The L298N is an integrated monolithic circuit in a 15-lead Multi watt and PowerSO20 packages. It is a high voltage, high current dual full-bridge driver designed to accept standard TTL logic levels and drive inductive loads such as relays, solenoids, DC and stepping motors. Two enable inputs are provided to enable or disable the device independently of the input signals. The emitters of the lower transistors of each bridge are connected together and the corresponding external terminal can be used for the connection of an external sensing resistor. An additional supply input is provided so that the logic works at a lower voltage.

 

Connecting the Arduino to a L298N H-Bridge Earlier we looked at L298N Motor Controller Theory and Projects to understand the basic operation of the L298N dual H-bridge motor controller. In this section I've connected the L298N to a bi-polar stepper motor and connected it to the ATMega168 aka Arduino micro-controller. Note the motor voltage is the voltage rating of the stepper motor up to 40 volts and a current limit of four amps.The Arduino series of micro-controllers are an outstanding value for the hobbyist and student to learn the basics of programming and interfacing micro-controllers. In this example in both hardware and programming the code below will operate the stepper motor through the L298N. The steppers I used in the example are all 7.5 degrees per-step and require 48 steps to go 360 degrees. Stepper motors are very accurate and often don't need feedback to tell position.A bi-polar stepper motor has only two coils and operates by reversing the polarity unlike a unipolar stepper motor that operates by switching four coils on/off.L298N Dual Full-Bridge DriverHere we have used only three connections to the Arduino micro-controller to operate the stepper motor. We tied ENA and ENB together and used two inverters from a 74LS04. We could still leave ENA and ENB separate if one wishes. In the program below simply remove any statements relating to ENB, yellow, or black which will free up three digital pins. It would also be a good idea change "#define orange 11" to #define orange 10" then wire digital pin 10 to IN3.  This demo uses a L298N dual H-bridge to operate a bi-polar stepper motor. The colors are the actual color of the wires on several units removed from junk printers.   Numbers such as PM425-048 and PM35s-048.  This also worked on a unipolor stepper such as a Portescape s6mo48 from Ebay leaving the red/green wires that went to +12 disconnected and operating at 24 volts.  */  #define CW 2#define CCW 3 #define ENA 8#define ENB 13 #define black 9  // IN1#define brown 10  // IN2#define orange 11  // IN3#define yellow 12  // IN4   void setup()  {   DDRB = 0x3f; // Digital pins 8-13 output  PORTB = 0x00; // all outputs DP8-13 set to off    pinMode(CW, INPUT);  pinMode(CCW, INPUT);   digitalWrite(CW, 1); // pullup on  digitalWrite(CCW,1); // pullup on   }   void loop() {   if (!digitalRead(CW)) forward(480, 0);  if (!digitalRead(CCW)) reverse(480, 0);  } // end loop  void reverse(int i, int j) {   // Pin 8 Enable A Pin 13 Enable B on  digitalWrite(ENA, HIGH);  digitalWrite(ENB, HIGH);   j = j + 10;  while (1)   {     digitalWrite(black, 0);    digitalWrite(brown, 1);    digitalWrite(orange, 1);    digitalWrite(yellow, 0);    delay(j);      i--;    if (i < 1) break;      digitalWrite(black, 0);    digitalWrite(brown, 1);    digitalWrite(orange, 0);    digitalWrite(yellow, 1);    delay(j);    i--;    if (i < 1) break;      digitalWrite(black, 1);    digitalWrite(brown, 0);    digitalWrite(orange, 0);    digitalWrite(yellow, 1);    delay(j);      i--;    if (i < 1) break;     digitalWrite(black, 1);    digitalWrite(brown, 0);    digitalWrite(orange, 1);    digitalWrite(yellow, 0);    delay(j);    i--;    if (i < 1) break;  }   // all outputs to stepper off  digitalWrite(ENA, LOW);  digitalWrite(ENB, LOW); }  // end reverse()   void forward(int i, int j) {   // Pin 8 Enable A Pin 13 Enable B on  digitalWrite(ENA, HIGH);  digitalWrite(ENB, HIGH);   j = j + 10;  while (1)   {     digitalWrite(black, 1);    digitalWrite(brown, 0);    digitalWrite(orange, 1);    digitalWrite(yellow, 0);    delay(j);    i--;    if (i < 1) break;        digitalWrite(black, 1);    digitalWrite(brown, 0);    digitalWrite(orange, 0);    digitalWrite(yellow, 1);    delay(j);      i--;    if (i < 1) break;     digitalWrite(black, 0);    digitalWrite(brown, 1);    digitalWrite(orange, 0);    digitalWrite(yellow, 1);    delay(j);    i--;    if (i < 1) break;     digitalWrite(black, 0);    digitalWrite(brown, 1);    digitalWrite(orange, 1);    digitalWrite(yellow, 0);    delay(j);      i--;    if (i < 1) break;    }   // all outputs to stepper off  digitalWrite(ENA, LOW);  digitalWrite(ENB, LOW); }  // end forward()L298N Dual Full-Bridge Driver application circuitShown above is a pre-assembled board I bought off Ebay for $8 with shipping. This included power connectors, diodes, LED indicators, and even a 5-volt regulator. This is in my opinion the smart way to go to save time, money, and effort.