Note: I recently redesigned and improved the stepper driver, as this has no microstepping, current limiting, and is prone to change direction erratically.  The improved version is here:  https://www.instructables.com/id/45-better-stepper-driver/

I have wanted to make a 3D printer or a CNC for quite a while, but as I don't have a lot of money, nor can I frequently order components online, I always ran into one obstacle.  Almost all projects required stepper drivers with step-direction control.  Those sorts of parts aren't avaliabe at stores, and the cheapest and most popular are around $15 a piece.  I don't want to spend nearly that much on a single component that could fry in a second, so I decided to make something a little cheaper and more expendable.  I ended up deciding on making my driver with an attiny and separate H-bridge chip.  It uses an attiny85, and the ever-common L293 motor driver.  together, they cost less than $5, and need almost no support circuitry. 

Step 1: other parts

All parts except the attiny and L293 are optional, but highly recommended.  In quantity, most cost as little as a few cents. 
1x >47uf capacitor-the bigger the better
8x ~1k ohm resistor-doesn't have to be 1K, any value 330-2K2 will probably work
1x 1N4001 diode-or any diode that can take >=1 amp, again, the bigger the better
protoboard-you could free-form it, but it's best to use protoboard/perfboard. 
header pins-if you want to breadboard with the driver or make it easy to replace.  I didn't use them, but its generally a good idea to do so. 
IC sockets-for the two chips, one 8 pin, one 16 pin.  Again, I didn't use them, but highly recommended. 
Finially, you will need an arduino.  Any flavor, homemade or whatever, as long as it has serial and an atmega it will work. 
<p>Very interesting. I have a suggestion though. Currently your code takes up some 1600 bytes so it would fit in an attiny85 with room to spare.<br>However, if you want to put it in an attiny 25 or 45 or maybe even a 13, it pays to do direct portmanipulation, each of your step routines like void &quot;two()&quot; takes 38 bytes. With direct portmanipulation that takes only 8 bytes. As you have 8 such routines, that would save 240 bytes to start with. That is already 1/6th of yr current program.<br>Setting of yr pinMode's takes up 166 bytes. If you would replace that by 1 write to the port direction register DDRB that would take only 4 bytes, so there is already a saving of 402 bytes. That is slightly over a quarter of your program.<br>Dont get me wrong, not critisizing you at all and in an Attiny85 there might be ample space, but just in case there is someone who has an Attiny25 lying around, with just some simple changes he or she would have a lot more space available for some other things.<br>Now you are trying to preserve pin2 so you would probably have to OR your portB with a mask rather than a direct write, but still that saves space over pinMode writes :-)<br>It has the added benefit that the pins change all at the same time which (in theory) should make yr motor run smoother :-)</p>
<p>I made something like this!</p><p>It is in my instructable, here:</p><p><a href="https://www.instructables.com/id/Attiny85-as-a-StepDir-Stepper-Motor-Controller/" rel="nofollow">https://www.instructables.com/id/Attiny85-as-a-Step...</a></p><p>It works better than this, as I figured out a way to get the DIR and STEP signals by different pins... More like your Attiny2313 version but cheaper!</p><p>Thank you for the inspiration I got while reading this...</p>
<p>Do you know if this will work with an Arduino Mega im using it to control 3 motors? </p>
If you mean to build three of these drivers and connect it to a mega, yes, that would work, though I would recommend the &quot;$4.5 better stepper driver&quot; instructable, because, as the name implies, it's much better and slightly cheaper. If you meant replacing the attinies with a mega, you could, but you'd have to modify the code, and I would suggest adding other features like microstepping and current control. <br>
<p>Yeah im just making three of these drivers to connect to one mega :), thanks ill give it a look</p>
I'm unable to understand the schematics. <br>As per your advice I have got a pre boot-loaded Atmega328p chip, but have failed to get better drivers like A4983 . All I have right now is L293D , so Can I use Arduino , Atmega 328 p and then further grbl controller to control my stepper by sending Gcodes ? <br>If so is the case please explain me how Arduino and Atmega will be connected as that is not much clearer with the pictures you have uploaded. <br>I'm pre-assuming the following steps that I need to do to run atleast one motor : <br>-Make sure grbl firmware is already uploaded to arduino <br>-Program i.e. upload the &quot;Real Code&quot; (as per step 5 of your instructable) to ATmega328p <br>-Connect L293d as per data sheet to four wire bipolar stepper wire and ATmega328p (or ATtiny2313, as in your instructable) <br>-Open grbl controller and viola , your motor should be running up. <br> <br> <br>Now it would really be a favor if you could just let me know the proper connection of Atmega328 with Arduino (i.e. the inputs ) <br>
That could work, but as I've had some problems with this driver, I would modify the code significantly. This driver uses an attiny 85, which does not have enough pins to drive the four motor wires plus two inputs, so I made one pin do double-duty. It works most of the time, but occasionally, the direction spontaneously flips. Since the 328 has tons of pins to spare, you could make a better driver. The code for the $4.5 diver with the L2619 is &quot;bettter&quot;, and can be quickly adapted for a different processor and driver. If I have the time, I'll re-write some code, and make a diagram, but I'm occupied for most of the next few months, starting saturday. <br>If I can't get to it, just use the stepper librairy for arduino, and write a program that counts up or down on the interrupts, using another pins input for direction.
Actually, immediately after posting that I noticed that no, the 328 cannot use the same code, even should you want to, as it does not have any analog pins and interrputs on the same pin, which is required for this code.
Hey Hi, the schematics are not very clear , from where you got the schematics , I saw the data sheet of L298 and to me it seems very much similiar to l293D , except for the fact that L293D has 16 pins.Moreover both the pins have 4 inputs . <br>Your both the drivers are awesome , you must include a video running all four motors for the 3d printer with grbl or any other software you use , it would be a great learning experience for noobs like me .
I would not use the l293 or 293d as neither has current regulation, and thus neither can do microstepping, unless complemented with a chip that can (an a4989 should actually be able to do so). <br>If you can get some a4989s, you should definitely use those, as their performance will be much greater than my driver. <br>Also, what is unclear about the schematic? It seems fairly straightforward, it needs an oscillator resistor, connections to current sense resistors, an h bridge and power.
Can i use atmega8 in stead of attiny??? if yes then how?
I would think so, though I haven't tried it. You would want to use different code, as the code for this specific project uses a single pin for step and direction, which makes it prone to read direction incorrectly. I have another instructable which uses an attiny 2313, and more importantly, separate step-dir input pins. <br><br>https://www.instructables.com/id/45-better-stepper-driver/<br><br>Using this instructable: https://www.instructables.com/id/Arduino-on-all-sorts-of-Atmels/step1/A-list-of-that-Atmels-can-be-programmed-with-this-/<br><br>You should be able to use the same code on your atmega without a problem. If you want to use L293 instead of L2619, then just change out the line in the code in &quot;void count&quot; that checks the analogRead pin, and replace it with &quot;if (digitalRead(directionpin)==0){&quot; replacing &quot;directionpin&quot; with the pin number you chose. <br>I would, however, suggest using the same controllers, as though it SHOULD work, I have no idea if it will.
Using numbers to indicate which pins are connected is a bit confusing as they could be pin numbers, which is what I thought at first. Usually we use small letters to do this (a) to (a) (b) to (b) ,etc. Just for future reference. Thanks for the 'able &amp; the clarification ! CHEERS!!
Can't follow your schematic at all &amp; a Google search for L298 doesn't have same DIP package or pinout. Can you please clarify ?
In the schematic, anywhere where a wire goes to a box with a number, just put a jumper between the two boxes. If it's something else thats confusing, then could you please clarify what you're asking about? <br>jumpers 5,6,7, and 8 go to the stepper.
Could it be a L293 IC ?
Yes, it is a 293. For some reason I can never remember which one it is. I'll change it in the instructable presently.
It's changed now. Thanks for pointing that out.
Thanks much!
https://www.instructables.com/id/OA7UYG1H143LO81/?editMode=true <br>take a look

About This Instructable




Bio: Currently a student at Iowa State University in Electrical Engineering. I'm participating in several clubs, helping with research, and working, so I probably won ... More »
More by jduffy54:One Night Battery Monitor For Wireless Headphones Attiny Chronograph $4.5 better stepper driver 
Add instructable to: