Introduction: DIY Arduino Motor Shield (L298N 2x4A)

Today, I'm going to show you how to make an Arduino motor shield (driver) at a low cost. It works splendidly, its posses almost all the characteristics of the original Arduino motor shield. It's almost considered as a clone. The original Arduino motor shield has the same motor driver chip (L298), the only difference with it, is the package type, my project contains the vertical version of the chip L298 (with a "N").

Structure:
It's controlled using 4 PWM pins. The connections are: 11&10 for the R-Motor and 6&5 for the L-Motor. With the help of eight fast recovery diodes (1N4937) it shows a very fast response of stopping/ braking, that's why I'm going to use it for the national SUMOBOT competition.

What Is A Motor Shield?
A motor shield is a circuit that drives different loads such as motors, lights and etc... The Arduino Board (Microcontroller) itself isn't designed to operate high current loads, that's why we use motor shields, it is a circuit that is controlled by your arduino board to drive high power accessories.

Cost:
It only cost me P363.75 (Converted: $8.87)! The prices would decrease to P262.50 (Converted: $6.40) if I sticked to the original plan, since it's for competitional purposes, I substituted some parts with a higher rate of response.

About The Guide:
The guide includes the datasheet, schematic diagram, PCB layout, Arduino test files and etc.... All you need is an hour and the 6 step instructable.

Specs:
____________________________________________________
Voltage Range: 5- 50 volts
Current Range: 2-4 Amperes
Power: 25w @75°C
Working Temparature: -40°C to 150°C
Board Compatibility: Arduino Uno
Motor Outputs: 2 Motors (Left & Right)
Possible Robot Movements: Left, Right, Forward, Backward & etc..
PWM Pins: [12&11] [6&5]

The PCB layout is my original design, it was created using Fritzing Software, please ask for permission if anyone is willing to modify and republish it.


This Instructable is dedicated to the: DB Makati ROBOTICS Team
(Merry Christmas & A Happy New Year!!)


Here's A Video Of My Sumobot Containing The DIY L298N Motor Driver Circuit:

Step 1: Parts & Materials

I bought my parts from ALEXAN, a local electronic store with tons of branches (Found Only In The Philippines). Everything is cheap here, the links that I gave are only alternative for online purchases. My real price list and spending is a lot different and cheaper. If you live in the Philippines, you can buy parts from DEECO, Alexan, E-Gizmo or Raon.

Parts:
- L298N Motor Driver Chip
- 7806 Regulator Chip 
- 1N4937 Fast Recovery Diode
- 1 Ohm ¼ watt Resistor
- Screw Terminal Blocks
- PCB Board (Regular or Photo-positive)
- Male or Female Pins (Used to connect to Arduino)
- Heatsink (Bought or DIY)

7806 Regulator Chip = (Substitute: 7805- 7809)
1 Ohm ¼ watt Resistor = (Substitute: Up to 10 Ohms)

1N4937 Fast Recovery Diode = (Substitute: 1N4007 or 4148)

Step 2: PCB Making

In this step, I will show you the schematic diagrams, datasheets and PCB layouts. Just download the files below. If you don't know how to make a PCB, please visit my other instructable guide "DIY Customized Circuit Board (PCB Making)". I used a Photo-postive PCB board instead of the traditional toner transfer. The photo-postive PCB is a bit rare in the U.S. that's why some should stick with the toner transfer method. Also don't forget to drill holes on them :)))

In making the photo-positive PCB, it's better to stay in a dark area and have a 10W fluorescent lamp beside you, also use a kitchen timer to set a 5 minute alarm for counting the exposure time.


Step 3: Soldering the Parts

I've bent the L298N chip with a pair of long nose pliers to fit into my robot (sumobot). Please pay particular attention to the part placement. The diodes should be soldered with their proper polarity. Please do not throw the leads that you have just cut since you are going to use them for your jumpers (recycle!).

The 7806 regulator chip was also bent for the whole circuit to fit in my robot. Since I could not find a heat sink that was thin and small enough for the whole circuit to fit, I made my own heat sink by using a small sheet of metal .

Almost everything is uniform in values. The diodes are all the same, and also the resistors.

Step 4: Installation of Motor Driver

The whole thing should fit snugly on top of your Arduino board, before powering it, be sure to check that nothing protrudes on your board that could cause short circuiting between both boards (crystal, Atmega Chip, IDE, USB, Pins & etc...)

Anyways, the motor outputs doesn't have a label of polarity, it's all about your codes, it has a reverse function, that's why the output polarity is interchangeable. 

For the power, the left side of the terminal block is the positive and the right is the negative. There's no need for connecting a power cable to your Arduino since the 6v regulated power supply of the Motor driver circuit is connected to the "vin" pin of your Arduino board. The power input should now be connected to your Motor Driver circuit instead of the Arduino's DC Jack.

Step 5: Testing Your Motor Driver (Programming & Codes)

Here's an Arduino code used to TEST the motor driver circuit. There are two options, it's either your copy and paste it or just download the Arduino file below, please do not remove the file from the folder after extracting, since the file will corrupt.

Movements After Observing:
1st.) Forward Clockwise Motor Movement (slow)
2nd.) Forward Clockwise Motor Movement (medium)
3rd.) Forward Clockwise Motor Movement (fast)
4th.) Complete Stop
5th.) Reverse Counter-clockwise Motor Movement (medium)

Here's A Video On How The Codes Would Work: (Use headphones to hear the motors)




int outPin = 5;
int outPin2 = 6;
int outPin4 = 10;
int outPin3 = 11;
void setup()
{
Serial.begin(9600); // setup serial
pinMode(outPin, OUTPUT);
pinMode(outPin2, OUTPUT);
pinMode(outPin3, OUTPUT);
pinMode(outPin4, OUTPUT);
}
void loop()
{
delay(3000);
analogWrite(outPin, 50);
digitalWrite(outPin2, LOW);
analogWrite(outPin3, 50);
digitalWrite(outPin4, LOW);
Serial.print(" ");
Serial.print("slow");
delay(3000);
analogWrite(outPin, 150);
digitalWrite(outPin2, LOW);
analogWrite(outPin3, 150);
digitalWrite(outPin4, LOW);
Serial.print(" ");
Serial.print("med");
delay(3000);
analogWrite(outPin, 255);
digitalWrite(outPin2, LOW);
analogWrite(outPin3, 255);
digitalWrite(outPin4, LOW);
Serial.print(" ");
Serial.print("fast");
delay(3000);
analogWrite(outPin, 0);
digitalWrite(outPin2, LOW);
analogWrite(outPin3, 0);
digitalWrite(outPin4, LOW);
Serial.print(" ");
Serial.print("stop");
delay(3000);
analogWrite(outPin2, 100);
digitalWrite(outPin, LOW);
analogWrite(outPin4, 100);
digitalWrite(outPin3, LOW);
Serial.print(" ");
Serial.print("backwards");
delay(3000);
analogWrite(outPin, 0);
digitalWrite(outPin2, LOW);
analogWrite(outPin3, 0);
digitalWrite(outPin4, LOW);
Serial.print(" ");
Serial.print("stop");
}

Step 6:

Your'e Done!!

Enjoy your DIY made motor driver! Have fun making Robots!

Troubleshooting:
- Repair damaged Foil layout
- Wrong Part Placement
- Damaged Chip (L298N/ 7806)
- Burnt Diode and Resistors
- Short Circuiting 
- Missing Jumpers
- etc..........


Please leave a comment or contact me if you are having trouble with your motor driver circuit. Be sure to rate the ible' 

Merry Christmas and a Happy New Year !!! (12/24/12)

Comments

author
Bozhidar Evdokimov (author)2013-06-07

First of all, thank you for the great instructable!!
Unfortunately, I have a problem- my motor shield only drives the motor when the usb cable of the arduino is connected. I really can't understand why this is happening.. Can you think of a possible reason?

author

I just reviewed the PCB board layout and it does appear to connect Vin and GND correctly on the pins. If you use a 7805 voltage regulator - it may be the problem. Follow my logic. The Vin goes through the Arduino on board voltage regulator and if it is getting 5 volts, it won't be able to supply 5 volts. Based on the datasheet of the 7805 - you should have at least 2 volts higher then the voltage out. So it needs to be at least 7 volts. So they may keep the arduino from running correctly. I don't know the tolerances of the Vin voltage and from arduino to ardunio, it may also very.

If the pictures - he show a 7806.

author
ASCAS (author)Bozhidar Evdokimov2013-06-09

That happened to me several times, I also felt frustration before, but I solved the problem. I manufactured 10 of these shields for the school. Be sure to read my instructions below thoroughly, and inspect your PCB carefully!

1st.) Power source should be connected to the Motor shield
2nd.) You forgot to solder the 7805 regulator chip
3rd.) The 7805 Regulator's pins aren't connected properly
4th.) You forgot a jumper (the short one in the lower right)
5th.) There's a broken line in your PCB

If this doesn't work try to contact me again. Thanks!



author
ferespo (author)2012-12-30

Hi, excellent instructable.
If you put a silicon diode (1N4001) in forward mode between pin 2 of 7805 and ground you will have aprox 5.7 volts at the output pin.

Regards

author
ASCAS (author)ferespo2012-12-30

I'm not sure. I only use the circuit with PWM pins coming from the Arduino. Probably it will work, but i don't think the output pin will retain the voltage from the input pin.

author
james.m.k (author)2012-12-30

Very cool!

author
diy_bloke (author)2012-12-30

Indeed I was impressed by your heat sink

author
tboultwood1 (author)2012-12-28

Very interesting instuctable. I was surprised how well your pcb came out. All the ones I make turn out rubbish! Any special tricks? :) Thank you again and ill be reading this in depth later!

author
diy_bloke (author)tboultwood12012-12-30

I print only one time on glossy paper. Transfer that to a clean piece of copper pertinax board, put a hot iron ont for 3 min, then use the point of the iron to really press down the edges and then throw it in water and rub off the paper.
Etching in HCl H2O2. No real problems

author
ASCAS (author)tboultwood12012-12-28

Thanks! The trick is in the toner ink transfer method is to use a sheet of acetate then, over lap them three times :)))

author
diy_bloke (author)ASCAS2012-12-30

you mean print it 3 times on the same sheet?

author
diy_bloke (author)2012-12-30

looks great!!
Did not know Alexan. May come in handy

author
ajoyraman (author)2012-12-25

Great Instructable for the Robotics Community !

author
fretted (author)2012-12-24

Merry Christmas to you as well and a most prosperous new year

Great Ible well done

author
Eron JoshF (author)2017-08-07

Hi! May I ask. What type of sensor you used for the floor and face? Thanks!

author
Eron JoshF (author)2017-08-07

Hello po. Ask ko lang if what kind of sensor you used for the floor sensor and for the face sensor? Thanks!

author
HeatBl (author)2017-07-15

Hi great tutorial is the test coding above for only one motor?

author
ManishP82 (author)2017-06-11

what power supply is needed

author
ManishP82 (author)2017-06-11

where is the circuit diagram

author
moh2016 (author)2016-08-02

please i wnat the fritzing file of this project plese

author
OlcayÇ (author)2016-04-30

thanks

author
JetJ2 (author)2016-03-09

can this run servo motors?

author
saintofinternet (author)2016-02-26

hey... can you help me make a 20A or 30A motor Sheild for Arduino??

author
Thijsluiten (author)2016-02-04

thanks this one really helped me with my robot

author
diy_bloke (author)2016-01-28

well done.

As you mention price as a factor, can i advise a ready made motor shield such as this one

http://www.aliexpress.com/item/L293D-Motor-Drive-S...

for only 2.10 euro = about 100 php

author
alys5 (author)2015-06-09

why do you use 4 pwm pins every motor uses only 1 pwm pin my project need to use the 4 left pwm if I connect 2 pwm to this motor controller and by the way very nice instructable it really helped

author
hemcrop made it! (author)2015-05-31

Finally i made it. Still Haven't tested it... Will update shortly. Thanks a lot for this awesome instructable.

IMG_20150531_214317701.jpgIMG_20150531_214312947.jpg
author
sami2000 (author)2015-04-20

can i use this motor driver in the following project

https://www.instructables.com/id/Arduino-Ultimate-O...

please tell me its urgent

author
UjjvalK (author)2015-01-14

Hey its not necesary to give 18v everytime right?

author
julsalmira (author)2015-01-11

Thanks for this instructables, i was inspired to do my own but unfortunately there is something wrong with my design. The only difference with my design to yours was i did not connect the enable pins to vcc. I'll used it for my pwm signal.

the problem is when i connect a power supply of around 12 volts, the dc power supply shut down, especially when i connect the +5v and ground to microcontroller vin and gnd. What is the possible reason? Im not that expert so please help me. Thanks in advance.

md.png
author
Hero.Arante (author)2014-10-25

On your schematic, is that 18v supply on the diodes and in the lm7805? If yes, where will i get that?

author
axel.rousselot.3 (author)2014-10-23

Great tuto ! :D

Does the L298HN work for that ? ( http://www.rs-particuliers.com/WebCatalog/Circuit_... )

Can I have the fritzing project please ?

Thank you ;)

author
gabrielgbst made it! (author)2014-07-02

very good project, easy to do and use.

it took me about 3 hours to execute the full project, from the corrosion until programing the arduino.

thanks for all ;)

IMG_1834.JPGIMG_1836.JPG
author
ASCAS (author)gabrielgbst2014-07-03

Awesome! :D

author
gabrielgbst (author)gabrielgbst2014-07-02

Ps: i made it with just scrap material

author
ishan553 (author)2014-04-03

can we use it for ur Phone Controlled FPV Rover (Fast & Agile) project

author
ASCAS (author)ishan5532014-04-05

Yes and I mentioned it clearly in the FPV Rover instructable.

author
ishan553 (author)ASCAS2014-04-05

sorry i asked this before reading the other lible

author
andromeda2020 (author)2014-04-05

Hi. The L298N schematic what are the inputs for pin 12, 10, 7, 5(inputs 4, 3, 2, 1)?

author
ASCAS (author)andromeda20202014-04-05

It should be connected to the Arduino's PWM pin.

author
enguilo (author)2014-03-27

I could provide circuit diagrams for sensors and motors, help me please, thanks you, great instructable

author
ASCAS (author)enguilo2014-03-28

No need, there's a schematic diagram above. What can I help you with?

author
enguilo (author)ASCAS2014-03-31

Ok but what did you use to power circuit and motor circut to connect ultrasonic sensors, see what happens q bakelite and there are many circuits of these, thanks!

author
ASCAS (author)enguilo2014-03-31

It looks like you're new to Arduino :| You have to learn the basics of Arduino before attempting this project. Here's a great tutorial: Beginner Arduino

author
dpineda3 (author)2014-03-21

I am kind of confused about the bottom part since Im a newbie in electronics. you see, you made the top part which is the clone wbout the bottom part where the clonse is sitting on?, did you buy it or did you also made it?

author
brij_malhotra (author)2014-03-10

I have soldered the circuit but I am getting two pins shorted on the L298N IC when tested using multimeter. Please help

THANK YOU !!

author
kberce (author)2014-03-06

Hello. I have one question. Current range is from 2 to 4 Amps. Is this for one motor or both? Because i have two 3.3A motors. If not, is there any way to modify the motordriver for higher current?

author
akusalewicz made it! (author)2014-03-05

Hey, congrats on your great instructable!
Could you please tell me, if there should be connection between paths as shown in the attached image(green colour)? Without any modification, the circuit is open for right motor. Greetings! :)

circuit.jpg
author
ASCAS (author)akusalewicz2014-03-06

Thanks!

Yup, there should be a line there but it doesn't really matter since the other pin is for wider screw posts. You can just connect the gap with lead.

author
Amgaa97 (author)2013-07-28

Can i use it for my tamiya double gearbox? with 4xAA NiHM batteries for motor supply?

About This Instructable

173,879views

552favorites

License:

Bio: Hi I'm Angelo! I am a 18 y/o college sophomore taking my majors in BS-ECE at the DLSU. I use my course as ... More »
More by ASCAS:DIY Motorized Fidget Spinner! (Contest Entry)DIY Motorized Fidget Spinner! Build A Bluetooth Boombox Speaker (from scratch)
Add instructable to: