members
Advanced: Project 027b L293D H-bridge motor control shield, two stepper motors DC 5V 28BYJ-48 or W-2
of Acoptex.com in UNO
Advanced: Project 027b
Project name: L293D H-bridge motor control shield, two DC 5V stepper motors 28BYJ-48 or W-24BYJ
Attachments: sketch1, sketch2, libraries
Tags: Arduino, 28BYJ-48, W-24BYJ, DC 5V stepper motor, L293D H-bridge motor control shield, Adafruit motor shield
In this project, you needed these parts :
1.Aruduino Uno R3 (you can also use the other version of Arduino)
2.Arduino IDE ( you can download it from here )
3.Jumper cables
4. Breadboard
5. L293D H-bridge motor control shield (Adafruit motor shield) 1 pc
6. DC 5V Stepper Motor (28BYJ - 48 or W-24BYJ) 2 pcs
or
General
We will learn how to connect L293D H-bridge motor control shield and 2 DC 5V stepper motors (for example 28BYJ-48 or W-24BYJ model) to Arduino board.
Understanding the L293D H-bridge motor control shield for Arduino (old Adafruit Motor Shield)
"Adafruit Motor Shield" was designed by Adafruit but Adafruit stopped to make it in 2014 due to a new and much better motor shield production. We will get explaned the old motor shield here as it is still activelly used around the world and there are clone boards produced in China. This shield contains two L293D motor drivers and one 74HC595 shift register. The shift register expands 3 pins of the Arduino to 8 pins to control the direction for the motor drivers. The output enable of the L293D is directly connected to PWM outputs of the Arduino.
It appears that SN754410 pin-compatible motor driver chip (it has output diodes and can provide 1A per motor, 2A peak) output diodes are designed for ESD protection only and that the use of them as kickback-protection is a hack and not guaranteed for performance. For that reason the motor shield did not come with the SN754410 and instead uses the L293D with integrated kickback-protection diodes. If you're willing to risk it, and need the extra currrent, feel free to buy SN754410's and replace the provided chips.
To increase the maximum current, the L293D allows extra chips with "piggyback". Piggyback is soldering one or two or three extra L293D drivers on top of the L293D drivers on the board to increase the maximum current. The L293D allows parallel operation. Figure out is how much current your motor will need.The motor driver chips that come with the kit are designed to provide up to 600 mA per motor, with 1.2A peak current. Note that once you head towards 1A you'll probably want to put a heatsink onthe motor driver, otherwise you will get thermal failure, possibly burning out the chip.
You can use 2 DC 5V servos and up to 4 DC motors or 2 stepper motors (or 1 stepper and up to 2 DC motors).
Motors take a lot of power, and can cause 'brownouts' that reset the Arduino. For that reason the shield is designed for seperate (split) supplies - one for the electronics and one for the motor. Doing this will prevent brownouts. It does not work for 3V motors as its meant for larger 6V+ motors. Unless you overdrive them at 6V and then they will burn out faster.The first important thing to figure out what voltage the motor is going to use. If you're lucky your motor came with some sort of specifications. Some small hobby motors are only intended to run at 1.5V, but its just as common to have 6-12V motors. The motor controllers on this shield are designed to run from 4.5V to 25V. MOST 1.5-3V MOTORS WILL NOT WORK.
All 6 analog input pins are available as they are not used on the motor shield. They can also be used as digital pins (pins #14 thru 19). Digital pin 2, and 13 are not used.

- 4 H-Bridges: L293D chipset provides 0.6A per bridge (1.2A peak) with thermal shutdown protection, 4.5V to 25V
- Pull down resistors keep motors disabled during power-up
- Big terminal block connectors to easily hook up wires (10-22AWG) and power
- Arduino reset button brought up top
- 2-pin terminal block to connect external power, for seperate logic/motor supplies
- Tested compatible with Mega, Diecimila, & Duemilanove
- 2 connections for 5V 'hobby' servos connected to the Arduino's high-resolution dedicated timer - no jitter. The servo motors use the +5V of the Arduino board. The voltage regulator on the Arduino board could get hot. To avoid this, the newer Motor Shields have connection points for a separate +5V for the servo motors. Hobby servos are the easiest way to get going with motor control. They have a 3-pin 0.1" female header connection with +5V, ground and signal inputs. The motor shield simply brings out the 16bit PWM output lines to two 3-pin headers so that its easy to plug in and go. They can take a lot of power so a 9V battery wont last more than a few minutes! 5V 'Hobby' servos are the easiest way to get going with motor control. They have a 3-pin 0.1" female header connection with +5V, ground and signal inputs. The motor shield simply brings out the 16bit PWM output lines to two 3-pin headers so that its easy to plug in and go. They can take a lot of power so a 9V battery wont last more than a few minutes.
- Up to 4 bi-directional DC motors with individual 8-bit speed selection (so, about 0.5%resolution)
- Up to 2 stepper motors (unipolar or bipolar)with single coil, double coil, interleaved or micro-stepping.
L293D is a typical Motor driver or Motor Driver IC which allows DC motor to drive on either direction. L293D is a 16-pin IC which can control a set of two DC motors simultaneously in any direction. It means that you can control two DC motor with a single L293D IC. In a single L293D chip there are two H-Bridge circuit inside the IC which can rotate two dc motor independently. H-bridge is a circuit which allows the voltage to be flown in either direction. H-bridge IC are ideal for driving a DC motor.Due its size it is very much used in robotic application for controlling DC motors.
See more information about L293D here.
You can find L293D datasheet here.
Understanding the stepper motors
Three basic types of stepper motors include the permanent magnet motor, the variable re-luctance motor, and the hybrid motor, which is a combination of the previous two.
You can read more about them here and here.
DC 5V stepper motors :
See 28BYJ - 48 datasheet here.
See W-24BYJ specification here.
Signals and connections of the stepper motors 600 mA
The 28BYJ-48 step motor runs on 5V power and has a 1/64 reduction. This reduction causes the number of steps required for a full turn to be 4096, or in the 4-step activation mode, that number drops by half to 2048. The stepper motor can operate in 2 activation modes: 8 steps (half-mode) or 4 steps (full step). In the 8-step activation mode, the drive sequence of the coils follows the table below. First a coil is activated, then two, then one, then two again, and so on until the 8 steps are completed:
In 4-step mode, 2 coils are driven at a time, which reduces the number of drives required to move the motor:
Signals and connections of the L293D H-bridge motor control shield for Arduino
- Supply the power either through the Arduino Board or the power header of the Motor Shield.
- Power jumper - only if the Arduino Board and the Shield use a separate power supply, it must be removed.
- 2 5V servo motors can be connected to Servo 1 andServo2. Pins - (GND or Ground), + (VCC), s (Signal);
- Power LED + indicates that the DC/Stepper motor power supply is working. If it is not lit, then the DC/Stepper motors will not run. The servo ports are 5V powered and does not use the DC motor supply;
- Reset button - Arduino board reset button;
- 4 DC bi-directional motors can be connected to terminal blocks M1 (A,B), M2 (A,B), M3 (A,B), M4 (A,B). That means they can be driven forwards and backwards. The speed can also be varied at 0.5% increments using the high-quality built in PWM. This means the speed is very smooth and won't vary! Note that the H-bridge chip is not meant for driving loads over 0.6A or that peak over 1.2A so this is for small motors. Check the datasheet for information about the motor to verify its GOOD to use.
The DC motors are powered off of a 'high voltage supply' and NOT the regulated 5V. Don'tconnect the motor power supply to the 5V line. This is a very very very bad idea unless you aresure you know what you're doing!The DC motors are powered off of a 'high voltage supply' and NOT the regulated 5V. Don't connect the motor power supply to the 5V line. This is a very bad idea unless you are sure you know what you're doing!
- 2 stepper motors: one can be connected to terminal blocks M1 (A,B), GND, M2(A,B), another to terminal blocks M4 (A,B), GND, M3 (A,B);
- Power for the Servos comes from the Arduino's on-board 5V regulator, powered directly from the USB or DC power jack on the Arduino. If you need an external supply, cut the trace right below the servo pins (on v1.2 boards) and connect a 5V or 6V DC supply directly. Using an external supply is for advanced users as you can accidentally destroy the servos by connecting a power supply incorrectly! When using the external supply header for servos, take care that the bottom of the header pins do not contact the metal USB port housing on the Arduino. A piece of electrical tape on the housing will protect against shorts;
- There are two places you can get your DC motor 'high voltage supply' from. One is the DC jack on the Arduino board and the other is the 2-terminal block on the shield that is labeled EXT_PWR. The DC Jack on the Arduino has a protection diode so you won't be able to mess things up too bad if you plug in the wrong kind of power. However the EXT_PWR terminals on the shield do not have a protection diode (for a fairly good reason). Be careful not to plug it in backwards or you will destroy the motor shield and/or your Arduino!
If you would like to have a single DC power supply for the Arduino and motors, simply plug it into the DC jack on the Arduino or the 2-pin PWR_EXT block on the shield. Place the power jumper on the motor shield.
If you have a Diecimila Arduino, set the Arduino power source jumper to EXT. Note that you may have problems with Arduino resets if the battery supply is not able to provide constant power, and it is not a suggested way of powering your motor project.
If you would like to have the Arduino powered off of USB and the motors powered off of a DC power supply, plug in the USB cable. Then connect the motor supply to the PWR_EXT block on the shield. Do not place the jumper on the shield. This is a suggested method of powering your motor project. (If you have a Diecimila Arduino, don't forget to set the Arduino power jumper to USB. If you have a Diecimila, you can alternately do the following: plug the DC power supply into the Arduino, and place the jumper on the motor shield.)
If you would like to have 2 separate DC power supplies for the Arduino and motors. Plug in the supply for the Arduino into the DC jack, and connect the motor supply to the PWR_EXT block. Make sure the jumper is removed from the motor shield. If you have a Diecimila Arduino, set the Arduino jumper to EXT. This is a suggested method of powering your motor project
Either way, if you want to use the DC motor/Stepper system the motor shield LED should be lit indicating good motor power.
Shields are boards that can be plugged on top of the Arduino PCB extending its capabilities. The different shields follow the same philosophy as the original toolkit: they are easy to mount, and cheap to produce.Every Arduino shield must have the same form-factor as the standard Arduino. Power and ground pins on one eight (previously six) pin header, and analog pins on a six-pin header next to that. Digital pins cover the other edge on the other side, an eight-pin header separated from a 10-pin by that weird 0.5" spacing. Some shields also require a connection to the Arduino’s ICSP header (the 2x3 programming header on the end).Some shields use every pin on the Arduino, while others only use a couple. When stacking shields, it’s important to make sure they don’t use overlapping pins. Some shields communicate with the Arduino via SPI, I2C, or Serial, and others use the Arduino’s interrupts or analog inputs.
Build the circuit
The 4-step activation (drive) mode is used by the standard Arduino library, and theoretically gives more power to the engine, since we will always have two coils being driven at the same time.
To control stepper motors, we use the side connectors, the same ones used to control DC motors. Let's connect two 28BYJ-48 stepper motors on this board (can be used for robotex). Pay attention to the wiring order of the wires of this motor, which must be the same as that of the circuit below. The power will be made through the 5V of the Arduino Uno itself, which we will use in the tests, so we will keep the PWR jumper on the board.
Note that 28BYJ-48 is a unipolar stepper, so it has 5 wires, not 4. Red wires of both steppers need to be connected to GND (located between - M1 and M2, M4 and M3 connectors).
You can use 28BYJ-48 stepper motors without connecting the red wires to anything and drive them as bipolar stepper motors.
The following picture shows the needed connections with the Arduino Uno.
L293D motor driver shield installed on top of Arduino Uno board
Code
- Make sure you #include
- Create the stepper motor object with AF_Stepper(steps, stepper#) to setup the motor Hbridge and latches.
- Steps indicates how many steps per revolution the motor has. A 7.5 degree stepper motor has 360/7.5 = 48 steps. Stepper# is which port stepper motor connected to. If you're using M1 and M2, its port 1. If you're using M3 and M4 it's port 2.
- Set the speed of the motor using setSpeed(rpm) where rpm is how many revolutions per minute you want the stepper to turn.
- Then every time you want the motor to move, call the step(#steps, direction, steptype) procedure. #steps is how many steps you'd like it to take. direction is either FORWARD or BACKWARD and the step type is SINGLE, DOUBLE. INTERLEAVE or MICROSTEP. "Single" means single-coil activation, "double" means 2 coils are activated at once (for higher torque) and "interleave" means that it alternates between single and double to get twice the resolution (but of course its half the speed). "Microstepping" is a method where the coils are PWM'd to create smooth motion between steps. You can use whichever stepping method you want, changing it "on the fly" to as you may want minimum power, more torque, or more precision.
- By default, the motor will 'hold' the position after its done stepping. If you want to release all the coils, so that it can spin freely, call release().
- The stepping commands are 'blocking' and will return once the steps have finished.
- Because the stepping commands 'block' - you have to instruct the stepper motors each time you want them to move. If you want to have more of a 'background task' stepper control, check out AccelStepper library (install similarly to how you did with AFMotor) which has some examples for controlling two steppers simultaneously with varying accelleration.
Step by Step instruction
- Install the AFMotor library. See notes below in Library section.
- Open Arduino IDE.
- Plug your Adruino Uno board into your PC and select the correct board and com port
- Open up serial monitor and set your baud to 9600 baud
- Verify and upload the the sketch to your Adruino Uno board
- The sketch rotates the two stepper motors alternately one in each direction. At each cycle, the motor moves in the amount of degrees defined in the angle variable at the beginning of the sketch.
Summary
We have learnt how to connect L293D motor control shield and 2 DC 5V stepper motors to Arduino board.
Library:
- Before you can use the Adafruit Motor shield, you must install the AFMotor library. We have attached it on the begining of this project.So download, unzip and add to libraries in your PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC.
Sketch:
- See attachments on the begining of this project description.
Other projects of Acoptex.com










jobs.viewed