DIY Arduino Motor Shield (L298N 2x4A)

183,698

559

94

About: Hi I'm Angelo! I am a college student taking my engineering majors in BS-EE/ BS-ECE at the DLSU. I use my course as an inspiration for making my current projects! I've been posting projects here ever since I...

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)

3 People Made This Project!

Recommendations

  • Toys Contest

    Toys Contest
  • Make it Glow Contest 2018

    Make it Glow Contest 2018
  • PCB Contest

    PCB Contest

94 Discussions

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?

2 replies

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.

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!



0
None
ferespo

5 years ago on Introduction

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

1 reply
0
None
ASCASferespo

Reply 5 years ago on Introduction

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.

0
None
diy_bloke

5 years ago on Step 3

Indeed I was impressed by your heat sink

0
None
tboultwood1

5 years ago on Introduction

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!

3 replies
0
None
diy_bloketboultwood1

Reply 5 years ago on Introduction

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

0
None
ASCAStboultwood1

Reply 5 years ago on Introduction

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

0
None
fretted

5 years ago on Introduction

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

Great Ible well done

0
None
CosmosD1

Question 3 months ago on Step 4

I have a 1.7V, 0.8A rated (6wire) stepper motor.....which driver is suitable for this motor?

0
None
Eron JoshF

1 year ago

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

0
None
Eron JoshF

1 year ago

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

0
None
HeatBl

1 year ago

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

0
None
ManishP82

1 year ago

what power supply is needed

0
None
ManishP82

1 year ago

where is the circuit diagram