• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
Previous Next

DC Motor Driver Breakout (L298 Chipset) on Arduino

Posted by: , September 10, 2014

[vc_row][vc_column][vc_column_text]result[/vc_column_text][vc_tour][vc_tab title=”Product introduce” tab_id=”1410331525-1-85″][vc_column_text]

600px-DC_motor

Specification:

  1. chipset: L298N
  2. Driving power supply voltage Vs: +5V  to +46V
  3. Peak current of driving power supply Io: 2A
  4. Vss: +5V to +7V
  5. Current of logic power supply: 0 – 36mA
  6. PWM control signal range:
    1. Low level: -0.3V < Vin < 1.5V
    2. High level: 2.3V < Vin< Vss
  7. Enable signal range:
    1. Low level: -0.3V
    2. High level: 2.3V < Vin< Vss
  8. Maxium power consumption: 25W
  9. Working temperation: -25C to 130C

[/vc_column_text][/vc_tab][vc_tab title=”Hardware prepare” tab_id=”1410331525-2-29″][vc_column_text]

DC Motor Driver Breakout (L298 Chipset)P Motor shield 2

Arduino Uno

Arduino diagram

Rover: WiFi Remote Control Robot with WiFi Video Camera

Motor car

[/vc_column_text][/vc_tab][vc_tab title=”Wiring diagram” tab_id=”1410331902238-2-7″][vc_column_text]

3
  • pinI1=3
  • pinI2=4
  • speedpinA=9
  • pinI3=5
  • pinI4=6
  • speedpinB=10

                

600px-DC_motor

Motor and Arduino

[/vc_column_text][/vc_tab][vc_tab title=”Code” tab_id=”1410331903410-3-7″][vc_column_text]

//. Motor driver shield- 2012 Copyright (c) Seeed Technology Inc.
// 
//  Original Author: Jimbo.we
//  Contribution: LG
//  
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

int pinI1=3;//define I1 interface
int pinI2=4;//define I2 interface 
int speedpinA=9;//enable motor A
int pinI3=5;//define I3 interface 
int pinI4=6;//define I4 interface 
int speedpinB=10;//enable motor B
int spead =127;//define the spead of motor
 
void setup()
{
  pinMode(pinI1,OUTPUT);
  pinMode(pinI2,OUTPUT);
  pinMode(speedpinA,OUTPUT);
  pinMode(pinI3,OUTPUT);
  pinMode(pinI4,OUTPUT);
  pinMode(speedpinB,OUTPUT);
}
 
void forward()
{
     analogWrite(speedpinA,spead);//input a simulation value to set the speed
     analogWrite(speedpinB,spead);
     digitalWrite(pinI4,HIGH);/ DC Motor B move clockwise
     digitalWrite(pinI3,LOW);
     digitalWrite(pinI2,LOW);/ DC Motor A move anticlockwise
     digitalWrite(pinI1,HIGH);
}
void backward()//
{
     analogWrite(speedpinA,spead);//input a simulation value to set the speed
     analogWrite(speedpinB,spead);
     digitalWrite(pinI4,LOW);/ DC Motor B move anticlockwise
     digitalWrite(pinI3,HIGH);
     digitalWrite(pinI2,HIGH);/ DC Motor A move clockwise
     digitalWrite(pinI1,LOW);
}
void left()//
{
     analogWrite(speedpinA,spead);//input a simulation value to set the speed
     analogWrite(speedpinB,spead);
     digitalWrite(pinI4,HIGH);/ DC Motor B move clockwise
     digitalWrite(pinI3,LOW);
     digitalWrite(pinI2,HIGH);/ DC Motor A move clockwise
     digitalWrite(pinI1,LOW);
}
void right()//
{
     analogWrite(speedpinA,spead);//input a simulation value to set the speed
     analogWrite(speedpinB,spead);
     digitalWrite(pinI4,LOW);/ DC Motor B move anticlockwise
     digitalWrite(pinI3,HIGH);
     digitalWrite(pinI2,LOW);/ DC Motor A move clockwise
     digitalWrite(pinI1,HIGH);
}
void stop()//
{
     digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor. 
     digitalWrite(speedpinB,LOW);
     delay(1000);
 
}

void loop()
{
  left();
  delay(2000);
  stop();
  right();
  delay(2000);
  stop();
 // delay(2000);
  forward();
  delay(2000);
  stop();
  backward();
  delay(2000); 
  stop(); 
}

[/vc_column_text][/vc_tab][vc_tab title=”Run and result” tab_id=”1410332312617-4-0″][vc_column_text]

Input the code into Arduino IDE, then click compile and upload

You will see the led light and the car will move

result

[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Share!
Tweet

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors