Introduction: L298 (Motor Driver) and the Linkit One

Picture of L298 (Motor Driver) and the Linkit One

In this instructable I'm going to show you how to use a Linkit one to control motors, this project is for people who want to build your own robots using the Linkit One, or have a pair of steeper motors you want to control. For this project we will be using a L298 IC along with the Linkit one board. This IC is voltages of upto 50V and currents of up to 3A.

Step 1: Requirements

Picture of Requirements

Here is a list of all the electronic components required to get started with the circuit.

LinkIt One

L298 IC

PCB

Connecting wires

Motors

Step 2: L298

Picture of L298

The L298 is a great H Bridge IC and most commonly used with an arduino. It is dual channel, which means that each IC is capable of controlling two motors. The motors can be rated within 50v and can draw currents of up to 3A, the IC also supports pulse width modulation (pwm) which gives you the advantage of controlling the speed of the motors.

Step 3: Circuit

Picture of Circuit

The circuit is really very simple, you can use the IC without the breakout board, but I decided to go with the breakout board for demonstration purpose. The enable pins act as the pwm pins and gives us an option to control the speed of the motors, if you just want to control the motors and not the speed you can connect these pins to the +5v of the Linkit One.

If you are using just the IC the connections can be made as follows-

1----Ground

2----Positive terminal of Motors

3----Negative terminal of Motors

4---- +12v battery

5---- Arduino Pin 2

6---- Arduino Pin 3

7---- Arduino Pin 4

8---- Ground

9---- +5v from Arduino

15---- Ground

Step 4: Code

Picture of Code

The code can be found below and you will require a modified Arduino IDE to work with the LinkIt One board to upload the code.

This is just a sample code which makes the motor rotate in opposite directions.

int enA = 10; int in1 = 9; int in2 = 8; // motor two int enB = 5; int in3 = 7; int in4 = 6; void setup() { // set all the motor control pins to outputs pinMode(enA, OUTPUT); pinMode(enB, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); } void demoOne() { // this function will run the motors in both directions at a fixed speed // turn on motor A digitalWrite(in1, HIGH); digitalWrite(in2, LOW); // set speed to 200 out of possible range 0~255 analogWrite(enA, 200); // turn on motor B digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // set speed to 200 out of possible range 0~255 analogWrite(enB, 200); delay(2000); // now change motor directions digitalWrite(in1, LOW); digitalWrite(in2, HIGH); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); delay(2000); // now turn off motors digitalWrite(in1, LOW); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); } void demoTwo() { // this function will run the motors across the range of possible speeds // note that maximum speed is determined by the motor itself and the operating voltage // the PWM values sent by analogWrite() are fractions of the maximum speed possible // by your hardware // turn on motors digitalWrite(in1, LOW); digitalWrite(in2, HIGH); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); // accelerate from zero to maximum speed for (int i = 0; i < 256; i++) { analogWrite(enA, i); analogWrite(enB, i); delay(20); } // decelerate from maximum speed to zero for (int i = 255; i >= 0; --i) { analogWrite(enA, i); analogWrite(enB, i); delay(20); } // now turn off motors digitalWrite(in1, LOW); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); } void loop() { demoOne(); delay(1000); demoTwo(); delay(1000); }

Comments

About This Instructable

815views

7favorites

License:

Bio: Eat*Sleep*Code Repeat
More by Prem67:Build a Proximity Sensor with the Linkit OneLinkit One Play MusicLinkit One Oscilloscope
Add instructable to: