(edit sidebar)
Intro to Physical Computing Syllabus

Research & Learning

Other Class pages

Shop Admin

ITP Help Pages
Tom's pcomp site
DanO's pcomp site


DC Motor Control Using an H-Bridge

Labs.DCMotorControl History

Hide minor edits - Show changes to output

Changed lines 180-181 from:
''This is a suggestion for a possible project.  You can do any project you wish as long as it demonstrates your mastery of the lab exercises and good physical interaction. ''
to:
''This is a suggestion for a possible project.  It's not a requirement for the class homework''
Changed lines 44-45 from:
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:arduino_and_breadboard.zip | download]])--]
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]])--]
Changed lines 51-52 from:
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:dc_motor_control_with_h-bridge_switch.zip | download]])--]
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]] )--]
Changed lines 104-108 from:
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:dcmotor_bb2.zip | download]])--]


If you need an external power supply, y ou
can use any DC power supply or battery from 9 - 15V as long as your motor can run at that voltage, and as long as the supply can supply as much current as your motor needs.
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]] )--]


If you need an external power supply, you
can use any DC power supply or battery from 9 - 15V as long as your motor can run at that voltage, and as long as the supply can supply as much current as your motor needs.
Changed lines 111-113 from:
%thumb width=400px%[[Attach:decoupling_cap_bb.png | Attach:decoupling_cap_bb.png]]
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:dcmotor_bb2.zip | download]])--]
to:
%thumb width=200px%[[Attach:decoupling_cap_bb.png | Attach:decoupling_cap_bb.png]]
[--(Diagram made with [[http://fritzing.org | Fritzing]] )--]
Changed lines 118-145 from:
Program the microcontroller to run the motor through the H-bridge:

(:div class=code :)
 
  const %color=#cc6600%int%% switchPin = 2;    %color=#7e7e7e%// switch input
  const %color=#cc6600%int%% motor1Pin = 3; 
  %color=#7e7e7e%// H-bridge leg 1 (pin 2, 1A)
  const %color
=#cc6600%int%% motor2Pin = 4;    %color=#7e7e7e%// H-bridge leg 2 (pin 7, 2A)
  const %color=#cc6600%int%% enablePin = 9;    %color=#7e7e7e%// H-bridge enable pin
  const %color=#cc6600%int%% ledPin = 13;      %color=#7e7e7e%// LED
 
  %color=#cc6600%void%% %color
=#cc6600%'''setup'''%%() {
    %color=#7e7e7e%// set the switch as an input:
    %color=#cc6600%pinMode%%(switchPin, %color=#006699%INPUT%%);
 
    %color=#7e7e7e%// set all the other pins you're using as outputs:
    %color=#cc6600%pinMode%%(motor1Pin, %color=#006699%OUTPUT%%);
    %color=#cc6600%pinMode%%(motor2Pin, %color=#006699%OUTPUT%%);
    %color=#cc6600%pinMode%%(enablePin, %color=#006699%OUTPUT%%);
    %color=#cc6600%pinMode%%(ledPin, %color
=#006699%OUTPUT%%);
 
    %color=#7e7e7e%// set enablePin high so
that motor can turn on:
    %color=
#cc6600%digitalWrite%%(enablePin, %color=#006699%HIGH%%);
  
   %color=#7e7e7e%// blink the LED 3 times. This should happen only once.
 
  %color=#7e7e7e%// if you see the LED blink three times, it means that the module
    %color=#7e7e7e%// reset itself,. probably because the motor caused a brownout
 
  %color=#7e7e7e%// or a short.
    %color=#cc6600%blink%%(ledPin, 3, 100);
to:
Program the microcontroller to run the motor through the H-bridge. First set up constants for the switch pin, the two H-bridge pins, and the enable pin of the H-bridge. Use one of the analogWrite pins (3,5,6,9,10, or 11) for the enable pin.

(:toggle question1 init=hide show
='I give up, how do I do that?' hide='Let me figure it out':)
>>id=question1 border='1px solid #999' padding=5px bgcolor=#e1e7f1<<
(:source lang=arduino tabwidth=4 :)

  const int switchPin
= 2;    // switch input
  const int motor1Pin = 3;   // H-bridge leg 1 (pin 2, 1A)
  const int motor2Pin
= 4;    // H-bridge leg 2 (pin 7, 2A)
  const int enablePin = 9;    // H-bridge enable pin
(:sourceend:)
>><<

In the setup(), set all the
pins for the H-bridge as outputs, and the pin for the switch as an input. The set the enable pin high so the H-bridge can turn the motor on

(:toggle question2 init
=hide show='I give up, how do I do that?' hide='Let me figure it out':)
>>id=question2 border='1px solid
#999' padding=5px bgcolor=#e1e7f1<<
(:source lang=arduino tabwidth=4 :)
  void setup() {
    // set the switch as an input:
    pinMode(switchPin, INPUT);

    // set all the other pins you're using as outputs:
    pinMode(motor1Pin, OUTPUT);
    pinMode(motor2Pin, OUTPUT);

   pinMode(enablePin, OUTPUT);
    pinMode(ledPin, OUTPUT);

    // set enablePin high so that motor can turn on:
    digitalWrite(enablePin, HIGH);
Changed lines 149-154 from:
  
  %color=#cc6600%void%% %color=#cc6600%
'''loop'''%%() {
    %color=#7e7e7e%// if the switch is
high, motor will turn on one direction:
    %color=#cc6600%if%% (%color=#cc6600%digitalRead%%(switchPin) == %color=#006699%HIGH%%) {
      %color=#cc6600%digitalWrite%%(motor1Pin, %color=#006699%LOW%%);  %color
=#7e7e7e%// set leg 1 of the H-bridge low
      %color
=#cc6600%digitalWrite%%(motor2Pin, %color=#006699%HIGH%%);  %color=#7e7e7e%// set leg 2 of the H-bridge high
to:
(:sourceend:)
>><<

In the main loop(). read the switch. If it
's high, turn the motor one way by taking one H-bridge pin high and the other low.  If the switch is low, reverse the direction by reversing the states of the two H-bridge pins.

(:toggle question3 init
=hide show='I give up, how do I do that?' hide='Let me figure it out':)
>>id
=question3 border='1px solid #999' padding=5px bgcolor=#e1e7f1<<
(:source lang=arduino tabwidth=4 :)

  void loop() {
    // if the switch is high, motor will turn on one direction:
    if (digitalRead(switchPin) == HIGH) {
      digitalWrite(motor1Pin, LOW);  // set leg 1 of the H-bridge low
      digitalWrite(motor2Pin, HIGH); 
// set leg 2 of the H-bridge high
Changed lines 164-167 from:
   %color=#7e7e7e%// if the switch is low, motor will turn in the other direction:
    %color=#cc6600%else%% {
      %color=#cc6600%digitalWrite%%(motor1Pin, %color=#006699%HIGH%%);  %color=#7e7e7e%// set leg 1 of the H-bridge high
      %color=#cc6600%digitalWrite%%(motor2Pin, %color=#006699%LOW%%);  %color=#7e7e7e%// set leg 2 of the H-bridge low
to:
   // if the switch is low, motor will turn in the other direction:
    else {
      digitalWrite(motor1Pin, HIGH);  // set leg 1 of the H-bridge high
      digitalWrite(motor2Pin, LOW);  // set leg 2 of the H-bridge low
Changed lines 170-187 from:
 
  %color=#7e7e7e%/*
  %color=#7e7e7e%  blinks an LED
  %color=#7e7e7e% */
  %color=#cc6600%void%% %color=#cc6600%blink%%
(%color=#cc6600%int%% whatPin, %color=#cc6600%int%% howManyTimes, %color=#cc6600%int%% milliSecs) {
 
   %color=#cc6600%int%% i = 0;
    %color=#cc6600%for%% ( i = 0; i < howManyTimes; i++) {
      %color=#cc6600%digitalWrite%%(whatPin, %color=#006699%HIGH%%);
      %color=#cc6600%delay%%(milliSecs/2);
      %color=#cc6600%digitalWrite%%(whatPin, %color=#006699%LOW%%);
      %color=#cc6600%delay%%(milliSecs/2);
    }
  }
 
(:divend:)

Once you've seen this code working, try modifying the speed of the motor using the analogWrite() function, as explained in the [[Labs/AnalogIn|Analog Lab]].  Use analogWrite() on pin 9,
the enable pin of the motor, and see what happens as you change the value of the analogWrite().
to:
(:sourceend:)
>><<



Once you've seen this code working, try modifying the speed of the motor using the analogWrite
() function, as explained in the [[Labs/AnalogIn|Analog Lab]].  Use analogWrite() on  the enable pin of the motor, and see what happens as you change the value of the analogWrite().
Changed lines 55-56 from:
Find yourself a DC motor that runs on low DC voltage within the range of 5 - 15V. [[http://www.radioshack.com/search/index.jsp?kwCatId=&kw=dc%20motor&origkw=dc%20motor&sr=1|RadioShack]] often sells several small DC motors, the NYU Computer Store on occasion has small a few, the junk shelf is almost always a goldmine for discarded motors and fans.Asking classmates and second years is another good approach.
to:
Find yourself a DC motor that runs on low DC voltage within the range of 5 - 15V. [[http://www.radioshack.com/search/index.jsp?kwCatId=&kw=dc%20motor&origkw=dc%20motor&sr=1|RadioShack]] often sells several small DC motors, the NYU Computer Store on occasion has small a few, the junk shelf is almost always a goldmine for discarded motors and fans. Asking classmates and second years is another good approach.
Changed lines 99-100 from:
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:dcmotor_bb.zip | download]])--]
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]]--]
Changed lines 111-112 from:
If you find that your microcontroller is resetting whenever the motor turns on, add a capacitor across power and ground close to the motor. The capacitor will smooth out the voltage dips that occur when the motor turns on.  This use of a capacitor is called a decoupling capacitor. Usually a 10 - 100uF capacitor will work.  The larger the cap, the more charge it can hold, but the longer it will take to release its charge.
to:
%thumb width=400px%[[Attach:decoupling_cap_bb.png | Attach:decoupling_cap_bb.png]]
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:dcmotor_bb2.zip | download]])--]

If you find that your microcontroller is resetting whenever
the motor turns on, add a capacitor across power and ground close to the motor. The capacitor will smooth out the voltage dips that occur when the motor turns on.  This use of a capacitor is called a '''decoupling capacitor'''. Usually a 10 - 100uF capacitor will work.  The larger the cap, the more charge it can hold, but the longer it will take to release its charge.
Changed lines 101-102 from:
Or, if you are using an external power for Arduino, you can use Vin (+9V) pin.
to:
Or, if you are using an external power for Arduino, you can use Vin pin.
Changed lines 55-62 from:
Find yourself a DC motor that runs on low DC voltage within the range of 5 - 15V. [[http://www.radioshack.com/search/index.jsp?kwCatId=&kw=dc%20motor&origkw=dc%20motor&sr=1|RadioShack]] often sells several small DC motors, the NYU Computer Store on occasion has small a few, the junk shelf is almost always a goldmine for discarded motors and fans, or simply asking classmates and second years is a good approach to borrowing a motor.

Solder leads to the motor's terminals. With most motors, there is no polarity regarding the motor terminals so
you may hook it up any way you'd like.

Now, consider testing your motor with a bench power supply from the ER. Ask a teacher or resident if you need help setting one up. Begin by adjusting the voltage on the bench power supply and observe its effects. Take note of its speed at different voltages without dipping to low or too high. Running a motor at a voltage much lower or much higher than what it's rated for could potentially damage or permanently destroy your motor.

!!! Acquire an
H-bridge
to:
Find yourself a DC motor that runs on low DC voltage within the range of 5 - 15V. [[http://www.radioshack.com/search/index.jsp?kwCatId=&kw=dc%20motor&origkw=dc%20motor&sr=1|RadioShack]] often sells several small DC motors, the NYU Computer Store on occasion has small a few, the junk shelf is almost always a goldmine for discarded motors and fans.Asking classmates and second years is another good approach.

Solder leads
to the motor's terminals. With DC motors, there is no polarity regarding the motor terminals so you can connect it any way you'd like.


'''Optional:''' Consider
testing your motor with a bench power supply from the equipment room. Ask a teacher or resident if you need help setting one up. Begin by adjusting the voltage on the bench power supply and observe its effects. Take note of its speed at different voltages without dipping to low or too high. Running a motor at a voltage much lower or much higher than what it's rated for could potentially damage or permanently destroy your motor. When the motor doesn't spin, the voltage is too low.  When the motor runs hot, or sounds like it's straining, the voltage is too high.

!!! Set up the
H-bridge
Changed lines 66-67 from:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293NE|Texas Instruments L293NE]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. If an H-bridge is not available in your Physical Computing Kit, they should have them for purchase at the NYU Computer Store and online at many distributors such as: [[http://www.digikey.com|Digikey]], [[http://www.sparkfun.com/commerce/product_info.php?products_id=315|SparkFun]], [[http://www.mouser.com|Mouser]] and [[http://www.jameco.com|Jameco]].
to:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293NE|Texas Instruments L293NE]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. There is one  in your Physical Computing Kit, and the NYU Computer Store and many distributors such as [[http://www.digikey.com|Digikey]], [[http://www.sparkfun.com/commerce/product_info.php?products_id=315|SparkFun]], [[http://www.mouser.com|Mouser]] and [[http://www.jameco.com|Jameco]] sell them as well.
Changed lines 70-73 from:
The L293NE and SN754410 H-Bridge you are using has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and operate between 4.5V and 36V. The small DC motor you are using in this lab can run safely off 5V so this H-bridge will work just fine.

The L293NE and SN754410 is a very basic
H-bridge. This one in particular has two bridges, one on the left side of the chip and one on the right.  The H-bridge you are using has the following pins and features:
to:

The L293NE/SN754410 is a very basic H-bridge. It has two bridges, one on the left side of the chip and one on the right,  and can control 2 motors. It can drive up to 1 amp of current, and operate between 4.5V and 36V. The small DC motor you are using in this lab can run safely off a low voltage so this H-bridge will work just fine.

The H-bridge
has the following pins and features:
Changed lines 87-88 from:
Below is a diagram of the H-bridge you are using and which pins do what in our example. Included with the diagram is a truth table indicating how the motor will function according to the state of the logic pins (which are set by our Arduino).
to:
Below is a diagram of the H-bridge and which pins do what in our example. Included with the diagram is a truth table indicating how the motor will function according to the state of the logic pins (which are set by our Arduino).
Changed line 91 from:
For this lab, the enable pin connects to a digital pin on your Arduino so you can send it either HIGH or LOW and turn the motor ON or OFF. The motor logic pins also connected to designated digital pins on your Arduino so you can send it HIGH and LOW to have the motor turn in one direction, or LOW and HIGH to have it turn in the other direction. The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply. For this lab you will be using the 5V from our Arduino but with aid of our 12V power supply. Most motors require a higher voltage and higher current draw than a microcontroller so the use of an external power supply is often needed.
to:
For this lab, the enable pin connects to a digital pin on your Arduino so you can send it either HIGH or LOW and turn the motor ON or OFF. The motor logic pins also connected to designated digital pins on your Arduino so you can send it HIGH and LOW to have the motor turn in one direction, or LOW and HIGH to have it turn in the other direction. The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply. If your motor can run on 5V and less than 500mA, you can use the Arduino's 5V output. Most motors require a higher voltage and higher current draw than this, so you might need an external power supply.
Changed lines 107-114 from:
Power Jumper -]

Most motors consume more current than a microprocessor, and need their own
supply. So for this lab you will be using a 12V power supply to provide the current you need. You can use any DC power supply from 9 - 15V as long as your motor can run at that voltage, and as long as the supply can supply as much current as your motor needs.

Plug
in an external  DC power source so that your Arduino runs off the 12V power supply. You may still leave your USB cable plugged in for quick and easy reprogramming. Whichever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!). The external voltage input is available at the Vin pin, so you can use it both to power the Arduino, and to power the motor.

Note the capacitor connecting
the motor supply to ground. It smooths out the voltage spikes and dips that occur as the motor turns on and off.
to:
If you need an external power supply, y ou can use any DC power supply or battery from 9 - 15V as long as your motor can run at that voltage, and as long as the supply can supply as much current as your motor needs.

Plug an external  DC power source into the Arduino's external power input. You may still leave your USB cable plugged
in for quick and easy reprogramming. Whichever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!). The external voltage input is available at the Vin pin, so you can use it both to power the Arduino, and to power the motor.

If you find that your microcontroller is resetting whenever the motor turns on, add a capacitor across
power and ground close to the motor. The capacitor will smooth out the voltage dips that occur when the motor turns on.  This use of a capacitor is called a decoupling capacitor. Usually a 10 - 100uF capacitor will work.  The larger the cap, the more charge it can hold, but the longer it will take to release its charge.
Added line 98:
Added line 100:
Changed lines 97-98 from:
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:dc_motor_control_with_h-bridge.zip | download]])--]
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:dcmotor_bb.zip | download]])--]
Or, if you are using an external power for Arduino, you can use Vin (+9V) pin.
Changed lines 100-102 from:
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:dcmotor_bb2.zip | download]])--]

Changed lines 98-99 from:
to:
%thumb width=600px%[[Attach:http://itp.nyu.edu/physcomp/uploads/dcmotor_bb2.png | Attach:http://itp.nyu.edu/physcomp/uploads/dcmotor_bb2.png]]
Changed line 177 from:
%alt='the innards of a cymbal monkey, showing the motors and gears'%http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_innards.JPG
to:
%alt='the innards of a cymbal monkey, showing the motors and gears'%http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_innards.JPG
Changed line 96 from:
%thumb width=600px%[[Attach:dc_motor_control_with_h-bridge_bb.png | Attach:dc_motor_control_with_h-bridge_bb.png]]
to:
%thumb width=600px%[[Attach:http://itp.nyu.edu/physcomp/uploads/dcmotor_bb.png | Attach:http://itp.nyu.edu/physcomp/uploads/dcmotor_bb.png]]
Changed lines 99-105 from:

%rframe width=200px%[[http://itp
.nyu.edu/physcomp/images/labs/arduino_jumper.jpg|http://itp.nyu.edu/physcomp/images/labs/arduino_jumper.jpg]] [[<<]] [- Arduino Power Jumper -]

Most motors consume more current than a microprocessor, and need their own supply. So for this lab you will be using our 12V power
supply to provide the current you need.

Change
your Arduino's power jumper from USB to EXT so that your Arduino runs off 12V power supply. You may still leave your USB cable plugged in for quick and easy reprogramming. Whichever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!). If you choose a motor that requires MORE than the 5V, use the external voltage input to input 9 - 15V. The external voltage input is available at the Vin pin, so you can use it both to power the Arduino, and to power the motor.
to:
Power Jumper -]

Most motors consume more current than a microprocessor, and need their own supply
. So for this lab you will be using a 12V power supply to provide the current you need. You can use any DC power supply from 9 - 15V as long as your motor can run at that voltage, and as long as the supply can supply as much current as your motor needs.

Plug in an external  DC power source so that your Arduino runs off the 12V power supply. You may still leave your USB cable plugged in for quick and easy reprogramming. Whichever motor you use, make sure the power source is compatible (i.e. don't use
a 9V battery for a 3V motor!). The external voltage input is available at the Vin pin, so you can use it both to power the Arduino, and to power the motor.
Changed lines 104-105 from:
Change your Arduino's power jumper from USB to EXT so that your Arduino runs off 12V power supply. You may still leave your USB cable plugged in for quick and easy reprogramming. Whichever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!). If you choose a motor that requires MORE than the 5V your Arduino consider using the 9V power pin or bypassing the Arduino for power all together.
to:
Change your Arduino's power jumper from USB to EXT so that your Arduino runs off 12V power supply. You may still leave your USB cable plugged in for quick and easy reprogramming. Whichever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!). If you choose a motor that requires MORE than the 5V, use the external voltage input to input 9 - 15V. The external voltage input is available at the Vin pin, so you can use it both to power the Arduino, and to power the motor.
Changed lines 44-45 from:
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:arduino_and_breadboard.zip | download]])--]
Changed lines 51-52 from:
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:dc_motor_control_with_h-bridge_switch.zip | download]])--]
Changed lines 97-99 from:
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:dc_motor_control_with_h-bridge.zip | download]])--]

Changed lines 43-44 from:
%alt='Arduino connected to a breadboard' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/arduino_bboard_power.jpg
to:
%width=600 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_and_breadboard_bb.png|Attach:arduino_and_breadboard_bb.png]]
Changed lines 49-50 from:
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch.jpg\\
to:
%alt='Arduino with switch on digital pin 2' width=600%[[Attach:dc_motor_control_with_h-bridge_switch_bb.png | Attach: dc_motor_control_with_h-bridge_switch_bb.png]]
Changed lines 94-95 from:
%thumb width=800px%[[http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg"Arduino module connected to an H-bridge"]]
to:
%thumb width=600px%[[Attach:dc_motor_control_with_h-bridge_bb.png | Attach:dc_motor_control_with_h-bridge_bb.png]]
Changed lines 169-170 from:
''This is a suggestion for the Stupid Pet Trick assignment.  You can do any project you wish as long as it demonstrates your mastery of the lab exercises and good physical interaction. This is just one suggestion.''
to:
''This is a suggestion for a possible project.  You can do any project you wish as long as it demonstrates your mastery of the lab exercises and good physical interaction. ''
Added lines 168-170:

''This is a suggestion for the Stupid Pet Trick assignment.  You can do any project you wish as long as it demonstrates your mastery of the lab exercises and good physical interaction. This is just one suggestion.''

Changed lines 162-163 from:
 (:divend:)
to:
(:divend:)
Changed lines 108-145 from:
[@

int switchPin
= 2;    // switch input
int motor1Pin = 3;    // H-bridge leg 1 (pin 2, 1A)
int motor2Pin
= 4;    // H-bridge leg 2 (pin 7, 2A)
int enablePin = 9;
   // H-bridge enable pin
int ledPin
= 13;      // LED

void setup() {
  // set the switch as an input:
  pinMode(switchPin, INPUT);

  // set all the other pins you're using as outputs:
  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
  pinMode(enablePin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  // set enablePin high so that motor can turn on:
  digitalWrite(enablePin, HIGH);

  // blink the LED 3 times. This should happen only once.
  // if you see the LED blink three times, it means that the module
  // reset itself,. probably because the motor caused a brownout
  // or a short.
  blink(ledPin, 3, 100);
}

void loop
() {
  // if the switch is high, motor will turn on one direction:
  if (digitalRead(switchPin) == HIGH) {
   digitalWrite(motor1Pin, LOW);  // set leg 1 of the H-bridge low
    digitalWrite(motor2Pin, HIGH);  // set leg 2 of the H-bridge high
  }
  // if the switch is low
, motor will turn in the other direction:
  else {
    digitalWrite(motor1Pin, HIGH
);  // set leg 1 of the H-bridge high
    digitalWrite(motor2Pin, LOW);  // set leg 2 of the H-bridge low
to:
(:div class=code :)
 
  const %color=#cc6600%int%% switchPin = 2;    %color=#7e7e7e%// switch input
  const %color
=#cc6600%int%% motor1Pin = 3;   %color=#7e7e7e%// H-bridge leg 1 (pin 2, 1A)
  const %color=#cc6600%int%% motor2Pin = 4;    %color
=#7e7e7e%// H-bridge leg 2 (pin 7, 2A)
  const %color=#cc6600%int%% enablePin = 9;    %color=#7e7e7e%// H-bridge enable pin
  const %color=#cc6600%int%% ledPin = 13;      %color=#7e7e7e%// LED
 

  %color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
 
  %color=#7e7e7e%// set the switch as an input:
    %color=#cc6600%pinMode%%(switchPin, %color=#006699%INPUT%%);
 
 
  %color=#7e7e7e%// set all the other pins you're using as outputs:
    %color=#cc6600%pinMode%%(motor1Pin, %color=#006699%OUTPUT%%);

    %color=#cc6600%pinMode%%(motor2Pin, %color=#006699%OUTPUT%%);
    %color=#cc6600%pinMode%%(enablePin, %color=#006699%OUTPUT%%);
    %color=#cc6600%pinMode%%(ledPin, %color=#006699%OUTPUT%%);
 
    %color=#7e7e7e%// set enablePin high so that motor can turn on:
    %color=#cc6600%digitalWrite%%
(enablePin, %color=#006699%HIGH%%);
 
    %color=#7e7e7e%// blink the LED 3 times. This should happen only once.
 
  %color=#7e7e7e%// if you see the LED blink three times, it means that the module
 
  %color=#7e7e7e%// reset itself,. probably because the motor caused a brownout
 
  %color=#7e7e7e%// or a short.
    %color=#cc6600%blink%%(ledPin, 3
, 100);
Changed lines 135-146 from:
}

/*
  blinks an LED
 */
void blink
(int whatPin, int howManyTimes, int milliSecs) {
  int i = 0;
  for ( i = 0; i < howManyTimes; i++) {
    digitalWrite
(whatPin, HIGH);
    delay(milliSecs/2);
    digitalWrite(whatPin, LOW);
    delay(milliSecs/2);
to:
 
  %color=#cc6600%void%% %color=#cc6600%'''loop'''%%
() {
    %color=#7e7e7e%// if the switch is high, motor will turn on one direction:
 
  %color=#cc6600%if%% (%color=#cc6600%digitalRead%%(switchPin) == %color=#006699%HIGH%%) {
      %color=#cc6600%digitalWrite%%(motor1Pin, %color=#006699%LOW%%);  %color=#7e7e7e%// set leg 1 of the H-bridge low
      %color=#cc6600%digitalWrite%%
(motor2Pin, %color=#006699%HIGH%%);  %color=#7e7e7e%// set leg 2 of the H-bridge high
    }
    %color=#7e7e7e%// if the switch is low, motor will turn in the other direction:
    %color=#cc6600%else%% {
      %color=#cc6600%digitalWrite%%(motor1Pin, %color=#006699%HIGH%%);  %color=#7e7e7e%// set leg 1 of the H-bridge high
      %color=#cc6600%digitalWrite%%(motor2Pin, %color=#006699%LOW%%);  %color=#7e7e7e%// set leg 2 of the H-bridge low
    }
Changed lines 148-151 from:
}

@]
to:
 
  %color=#7e7e7e%/*
  %color=#7e7e7e%  blinks an LED
  %color=#7e7e7e% */
  %color=#cc6600%void%% %color=#cc6600%blink%%(%color=#cc6600%int%% whatPin, %color=#cc6600%int%% howManyTimes, %color=#cc6600%int%% milliSecs) {
    %color=#cc6600%int%% i = 0;
    %color=#cc6600%for%% ( i = 0; i < howManyTimes; i++) {
      %color=#cc6600%digitalWrite%%(whatPin, %color=#006699%HIGH%%);
      %color=#cc6600%delay%%(milliSecs/2);
      %color=#cc6600%digitalWrite%%(whatPin, %color=#006699%LOW%%);
      %color=#cc6600%delay%%(milliSecs/2);
   
}
  }
 
 (:divend:)

Added lines 2-3:

!!!Overview
Changed line 1 from:
!! DC Motor Control Using an H-Bridge
to:
(:title DC Motor Control Using an H-Bridge:)
Added lines 9-12:
(:toc Table of Contents:)

!!! Parts

Changed lines 90-91 from:
Most motors consume more current than a microprocessor, and need their own supply. So for this lab you will be using our 12V power supply to provide the current you need. Change your Arduino's power jumper from USB to EXT so that your Arduino runs off 12V power supply. You may still leave your USB cable plugged in for quick and easy reprogramming. Whichever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!). If you choose a motor that requires MORE than the 5V your Arduino consider using the 9V power pin or bypassing the Arduino for power all together.
to:
%rframe width=200px%[[http://itp.nyu.edu/physcomp/images/labs/arduino_jumper.jpg|http://itp.nyu.edu/physcomp/images/labs/arduino_jumper.jpg]] [[<<]] [- Arduino Power Jumper -]

Most motors consume more current than a microprocessor, and need their own supply. So for this lab you will be using our 12V power supply to provide the current you need.

Change your Arduino's power jumper from USB to EXT so that your Arduino runs off 12V power supply. You may still leave your USB cable plugged in for quick and easy reprogramming. Whichever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!). If you choose a motor that requires MORE than the 5V your Arduino consider using the 9V power pin or bypassing the Arduino for power all together.
Changed lines 61-64 from:
The L293NE and SN754410 H-Bridge we are using has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and operate between 4.5V and 36V. The small DC motor we are using in this lab can run safely off 5V so this H-bridge will work just fine.

The L293NE and SN754410 is a very basic H-bridge. This one in particular has two bridges, one on the left side of the chip and one on the right.  The H-bridge we are using has the following pins and features:
to:
The L293NE and SN754410 H-Bridge you are using has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and operate between 4.5V and 36V. The small DC motor you are using in this lab can run safely off 5V so this H-bridge will work just fine.

The L293NE and SN754410 is a very basic H-bridge. This one in particular has two bridges, one on the left side of the chip and one on the right.  The H-bridge you are using has the following pins and features:
Changed line 72 from:
* Pin 9-11 are unconnected as we are only using one motor in this lab
to:
* Pin 9-11 are unconnected as you are only using one motor in this lab
Changed lines 77-78 from:
Below is a diagram of the H-bridge we are using and which pins do what in our example. Included with the diagram is a truth table indicating how the motor will function according to the state of the logic pins (which are set by our Arduino).
to:
Below is a diagram of the H-bridge you are using and which pins do what in our example. Included with the diagram is a truth table indicating how the motor will function according to the state of the logic pins (which are set by our Arduino).
Changed line 81 from:
For this lab, the enable pin connects to a digital pin on your Arduino so we can send it either HIGH or LOW and turn the motor ON or OFF. The motor logic pins also connected to designated digital pins on your Arduino so we can send it HIGH and LOW to have the motor turn in one direction, or LOW and HIGH to have it turn in the other direction. The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply. For this lab we will be using the 5V from our Arduino but with aid of our 12V power supply. Most motors require a higher voltage and higher current draw than a microcontroller so the use of an external power supply is often needed.
to:
For this lab, the enable pin connects to a digital pin on your Arduino so you can send it either HIGH or LOW and turn the motor ON or OFF. The motor logic pins also connected to designated digital pins on your Arduino so you can send it HIGH and LOW to have the motor turn in one direction, or LOW and HIGH to have it turn in the other direction. The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply. For this lab you will be using the 5V from our Arduino but with aid of our 12V power supply. Most motors require a higher voltage and higher current draw than a microcontroller so the use of an external power supply is often needed.
Changed lines 90-91 from:
Most motors consume more current than a microprocessor, and need their own supply. So for this lab we will be using our 12V power supply to provide the current we need. Change your Arduino's power jumper from USB to EXT so that your Arduino runs off 12V power supply. You may still leave your USB cable plugged in for quick and easy reprogramming. Whichever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!). If you choose a motor that requires MORE than the 5V your Arduino consider using the 9V power pin or bypassing the Arduino for power all together.
to:
Most motors consume more current than a microprocessor, and need their own supply. So for this lab you will be using our 12V power supply to provide the current you need. Change your Arduino's power jumper from USB to EXT so that your Arduino runs off 12V power supply. You may still leave your USB cable plugged in for quick and easy reprogramming. Whichever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!). If you choose a motor that requires MORE than the 5V your Arduino consider using the 9V power pin or bypassing the Arduino for power all together.
Deleted lines 38-41:
If you're using an Arduino breadboard shield, there is a row of sockets connected to 5V on the analog in side of the breadboard, and a row connected to ground on the digital in side of the board:

%alt='Arduino breadboard shield' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/breadboard_shield.jpg

Deleted lines 42-45:
(:table:)
(:cellnr colspan=2:)
%alt='Arduino digital in schematic' height=300%http://itp.nyu.edu/physcomp/images/labs/arduino_dig_input_schem.png
(:cellnr:)
Changed lines 44-49 from:
Breadboard version
(:cell:)
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_shield_switch.jpg\\
Shield version
(:tableend:)

to:
Deleted lines 1-2:

[= !!! UNDER CONSTRUCTION !!! =]
Changed lines 64-65 from:
First, connect leads to the motor's terminals, and power it using a bench power supply (available from the ER). With most motors, there is no polarity regarding the motor terminals so you may hook it up any way you'd like. Adjust the voltage on the bench power supply and observe its effects. Take note of its speed at different voltages without dipping to low or too high. Running a motor at a voltage much lower or much higher than what it's rated for could potentially damage or permanently destroy your motor.
to:
Solder leads to the motor's terminals. With most motors, there is no polarity regarding the motor terminals so you may hook it up any way you'd like.

Now, consider testing your motor with a bench power supply from the ER
. Ask a teacher or resident if you need help setting one up. Begin by adjusting the voltage on the bench power supply and observe its effects. Take note of its speed at different voltages without dipping to low or too high. Running a motor at a voltage much lower or much higher than what it's rated for could potentially damage or permanently destroy your motor.
Changed line 94 from:
For this lab, the enable pin connects to a digital pin on your Arduino so we can send it either HIGH or LOW and turn the motor ON or OFF. The motor logic pins also connected to designated digital pins on your Arduino so we can send it HIGH and LOW to have the motor turn in one direction, or LOW and HIGH to have it turn in the other direction. The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply. For this lab we will be using the 5V from our Arduino but with aid of our 12V power supply. Most motors require a higher voltage and higher current draw than a microcontroller so the use of an external power supply is often needed. If you're using a motor that draws less than 750 milliamps at 15 volts or less, you could use the 9V power pin on your Arduino.
to:
For this lab, the enable pin connects to a digital pin on your Arduino so we can send it either HIGH or LOW and turn the motor ON or OFF. The motor logic pins also connected to designated digital pins on your Arduino so we can send it HIGH and LOW to have the motor turn in one direction, or LOW and HIGH to have it turn in the other direction. The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply. For this lab we will be using the 5V from our Arduino but with aid of our 12V power supply. Most motors require a higher voltage and higher current draw than a microcontroller so the use of an external power supply is often needed.
Changed lines 114-118 from:
int motor1Pin = 3;    // H-bridge leg 1
int motor2Pin = 4;    // H-bridge leg 2
int enablePin = 9; 
   // H-bridge enable pin
int ledPin = 13;
      //LED
to:
int motor1Pin = 3;    // H-bridge leg 1 (pin 2, 1A)
int motor2Pin = 4;
   // H-bridge leg 2 (pin 7, 2A)
int enablePin = 9;
    // H-bridge enable pin
int ledPin = 13;
      // LED
Changed line 116 from:
int speedPin = 9;    // H-bridge enable pin
to:
int enablePin = 9;    // H-bridge enable pin
Changed line 126 from:
  pinMode(speedPin, OUTPUT);
to:
  pinMode(enablePin, OUTPUT);
Changed lines 129-131 from:
  // set speedPin high so that motor can turn on:
  digitalWrite(speedPin, HIGH);
to:
  // set enablePin high so that motor can turn on:
  digitalWrite(enablePin, HIGH);
Changed line 94 from:
For this lab, the enable pin connects to a digital pin on your Arduino so we can send it either HIGH or LOW and turn the motor ON or OFF. The motor logic pins also connected to designated digital pins on your Arduino so we can send it HIGH and LOW to have the motor turn in one direction, or LOW and HIGH to have it turn in the other direction.. The The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply, but for this lab we will use the 5V from your Arduino since the motor is fairly low power. Most motors require a higher voltage and higher current draw than a microcontroller so the use of an external power supply is often needed. If you're using a motor that draws less than 750 milliamps at 15 volts or less, you could use the 9-15V power jack on the Arduino module. Just be sure to switch the jumper on your Arduino to use the external power supply as well instead of USB.
to:
For this lab, the enable pin connects to a digital pin on your Arduino so we can send it either HIGH or LOW and turn the motor ON or OFF. The motor logic pins also connected to designated digital pins on your Arduino so we can send it HIGH and LOW to have the motor turn in one direction, or LOW and HIGH to have it turn in the other direction. The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply. For this lab we will be using the 5V from our Arduino but with aid of our 12V power supply. Most motors require a higher voltage and higher current draw than a microcontroller so the use of an external power supply is often needed. If you're using a motor that draws less than 750 milliamps at 15 volts or less, you could use the 9V power pin on your Arduino.
Changed lines 103-104 from:
Most motors consume more current than a microprocessor, and need their own supply. The motor and the microcontroller need a common ground, however.  The example above uses 12V, run in parallel with the 5V voltage regulator that supplies the Arduino board. Whatever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!).
to:
Most motors consume more current than a microprocessor, and need their own supply. So for this lab we will be using our 12V power supply to provide the current we need. Change your Arduino's power jumper from USB to EXT so that your Arduino runs off 12V power supply. You may still leave your USB cable plugged in for quick and easy reprogramming. Whichever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!). If you choose a motor that requires MORE than the 5V your Arduino consider using the 9V power pin or bypassing the Arduino for power all together.
Added lines 2-3:

[= !!! UNDER CONSTRUCTION !!! =]
Changed lines 66-67 from:
%lframe width=200px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293NE H-bridge-]
to:
%thumb width=200px valign=left% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293NE H-bridge-]
Added lines 66-67:
%lframe width=200px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293NE H-bridge-]
Deleted lines 94-99:
%lframe width=200px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293NE H-bridge-]

[[<<]]

The logic inputs on the H-bridge connect to the digitals pins on your microcontroller that you use to output control signals to the H-bridge. The configuration of these pins might vary slightly on other models of H-bridge. They might also use slightly different names, but the functions are roughly the same.

Changed line 90 from:
For this lab, the enable pin connects to a digital pin on your Arduino. The motor logic pins also connected to designated digital pins on your Arduino. The The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply, but for this lab we will use the 5V from your Arduino since the motor is fairly low power. Most motors require a higher voltage and higher current draw than a microcontroller so the use of an external power supply is often needed. If you're using a motor that draws less than 750 milliamps at 15 volts or less, you could use the 9-15V power jack on the Arduino module. Just be sure to switch the jumper on your Arduino to use the external power supply as well instead of USB.
to:
For this lab, the enable pin connects to a digital pin on your Arduino so we can send it either HIGH or LOW and turn the motor ON or OFF. The motor logic pins also connected to designated digital pins on your Arduino so we can send it HIGH and LOW to have the motor turn in one direction, or LOW and HIGH to have it turn in the other direction.. The The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply, but for this lab we will use the 5V from your Arduino since the motor is fairly low power. Most motors require a higher voltage and higher current draw than a microcontroller so the use of an external power supply is often needed. If you're using a motor that draws less than 750 milliamps at 15 volts or less, you could use the 9-15V power jack on the Arduino module. Just be sure to switch the jumper on your Arduino to use the external power supply as well instead of USB.
Changed lines 103-111 from:
(:table:)
(:cellnr colspan=2:)
%height=300 alt='schematic of Arduino module connected to an
H-bridge'%http://itp.nyu.edu/physcomp/images/labs/arduino_h-bridge_schem.png
(:cellnr:)
%alt='Arduino module with breadboard shield connected to an H-bridge'%http://itp.nyu.edu/physcomp/images/labs/bboard_shield_h-bridge.JPG
(:cell:)
%lframe width=370px% [[http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg
"Arduino module connected to an H-bridge"]] | [-Arduino module connected to an H-bridge-]
(:tableend:)

to:
%thumb width=800px%[[http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg"Arduino module connected to an H-bridge"]]
Changed lines 75-76 from:
* Pin 2 is a logic pin for our motor (input is either HIGH or LOW)
* Pin 3 is for one of the motor terminals
to:
* Pin 2 (1A) is a logic pin for our motor (input is either HIGH or LOW)
* Pin 3 (1Y) is for one of the motor terminals
Changed lines 78-80 from:
* Pin 6 is for the other motor terminal
* Pin 7 is a logic pin for our motor (input is either HIGH or LOW)
* Pin 8 is the power supply for our motor, this should be given the rated voltage of your motor
to:
* Pin 6 (2Y) is for the other motor terminal
* Pin 7 (2A) is a logic pin for our motor (input is either HIGH or LOW)
* Pin 8 (VCC2) is the power supply for our motor, this should be given the rated voltage of your motor
Changed lines 84-85 from:
* Pin 16 is connected to 5V
to:
* Pin 16 (VCC1) is connected to 5V
Changed lines 72-81 from:
The L293NE and SN754410 is a very basic H-bridge. This one in particular has two bridges, one on the left side of the chip and one on the right.  Though they may have some extra features, every H-bridge will have the same basic interface:

* Pins for enabling and disabling the motors
* Pins for Logic Input (controlling the direction of the
motor)
* Pins for Motor Supply Output (power for the motors)
* Pin
for powering the H-Bridge
* Pins for Ground

Below is a diagram of the H-bridge we are using and which pins do what in our example. Included with the diagram
is a truth table indicating how the motor will function according to your Arduino digital pin outputs.
to:
The L293NE and SN754410 is a very basic H-bridge. This one in particular has two bridges, one on the left side of the chip and one on the right.  The H-bridge we are using has the following pins and features:

* Pin 1 (1,2EN) enables and disables our motor whether it is give HIGH or LOW
* Pin 2 is a logic pin for our
motor (input is either HIGH or LOW)
* Pin 3 is
for one of the motor terminals
* Pin 4-5 are for ground
* Pin 6 is for the other motor terminal
* Pin 7 is a logic pin for our motor (input
is either HIGH or LOW)
* Pin 8 is the power supply for our motor, this should be given the rated voltage of your motor
* Pin 9-11 are unconnected as we are only using one motor in this lab
* Pin 12-13 are for ground
* Pin 14-15 are unconnected
* Pin 16 is connected to 5V

Below is a diagram of the H-bridge we are using and which pins do what in our example. Included with the diagram is a truth table indicating how the motor will function according to the state of the logic pins (which are set by our Arduino)
.
Changed line 90 from:
The logic voltage pins connect to the same voltage source as your microcontroller. The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply. Most motors require a higher voltage and higher current draw than a microcontroller so the use of an external power supply is needed. If you're using a motor that draws less than 750 milliamps at 15 volts or less, you could use the 9-15V power jack on the Arduino module. Just be sure to switch the jumper on your Arduino to use the external power supply as well instead of USB.
to:
For this lab, the enable pin connects to a digital pin on your Arduino. The motor logic pins also connected to designated digital pins on your Arduino. The The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply, but for this lab we will use the 5V from your Arduino since the motor is fairly low power. Most motors require a higher voltage and higher current draw than a microcontroller so the use of an external power supply is often needed. If you're using a motor that draws less than 750 milliamps at 15 volts or less, you could use the 9-15V power jack on the Arduino module. Just be sure to switch the jumper on your Arduino to use the external power supply as well instead of USB.
Changed lines 74-77 from:
* Pins for Logic Input
* Pins for Motor Supply Voltage
* Pins for Logic Voltage
* Pins for Motor Supply Output
to:
* Pins for enabling and disabling the motors
* Pins for Logic Input (controlling the direction of the motor)
* Pins for Motor Supply Output (power for the motors)
* Pin for powering the H-Bridge
Changed lines 70-73 from:
This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.

The L293NE is a very basic H-bridge. There are many different models of
H-bridges from other manufacturers.  This one in particular has two bridges, one on the left side of the chip and one on the right.  Though they may have some extra features, every H-bridge will have the same basic interface:
to:
The L293NE and SN754410 H-Bridge we are using has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and operate between 4.5V and 36V. The small DC motor we are using in this lab can run safely off 5V so this H-bridge will work just fine.

The L293NE and SN754410 is a very basic H-bridge.
This one in particular has two bridges, one on the left side of the chip and one on the right.  Though they may have some extra features, every H-bridge will have the same basic interface:
Changed lines 78-79 from:
* Pins for Ground
to:
* Pins for Ground

Below is a diagram of the H-bridge we are using and which pins do what in our example. Included with the diagram is a truth table indicating how the motor will function according to your Arduino digital pin outputs.

Changed lines 66-69 from:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293NE|Texas Instruments L293NE]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. If an H-bridge is not available in your Physical Computing Kit, they should have them for purchase at the NYU Computer Store and online at many distributors such as: [[http://www.digikey.com|Digikey]], [[http://www.sparkfun.com/commerce/product_info.php?products_id=315|SparkFun]], [[http://www.mouser.com|Mouser]] and [[http://www.jameco.com|Jameco]]. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.

The L293E is a very basic H-bridge. There are many different models of H-bridges from other manufacturers.  This one in particular has two bridges, one on the left side of the chip and one on the right.  Though they may have some extra features, every H-bridge will have the same basic interface:
to:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293NE|Texas Instruments L293NE]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. If an H-bridge is not available in your Physical Computing Kit, they should have them for purchase at the NYU Computer Store and online at many distributors such as: [[http://www.digikey.com|Digikey]], [[http://www.sparkfun.com/commerce/product_info.php?products_id=315|SparkFun]], [[http://www.mouser.com|Mouser]] and [[http://www.jameco.com|Jameco]].

!!! How your H-bridge works

This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current,
and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.

The L293NE is a very basic H-bridge. There are many different models of H-bridges from other manufacturers.  This one in particular has two bridges, one on the left side of the chip and one on the right.  Though they may have some extra features, every H-bridge will have the same basic interface:
Changed lines 81-82 from:
%lframe width=200px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293 H-bridge-]
to:
%lframe width=200px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293NE H-bridge-]
Changed lines 76-77 from:
%thumb width=800px% [[http://http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg | http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg]]
to:
%thumb width=800px% [[http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg | http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg]]
Changed lines 76-77 from:
%thumb width=500px% [[http://http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg | http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg]]
to:
%thumb width=800px% [[http://http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg | http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg]]
Changed lines 76-77 from:
%lframe valign=left% [[http://http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg | http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg]]
to:
%thumb width=500px% [[http://http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg | http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg]]
Added lines 76-77:
%lframe valign=left% [[http://http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg | http://itp.nyu.edu/physcomp/images/labs/hbridge_labpinout.jpg]]
Deleted lines 78-79:
%lframe width=200px valign=center% [[http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg | http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg"SN754410 H-bridge"]] | [-SN754410 H-bridge-]
Changed lines 26-27 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293NE \\ or SN754410 H-bridge-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293NE [[<<]] or SN754410 H-bridge-]
Changed lines 26-27 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293NE\\or SN754410 H-bridge-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293NE \\ or SN754410 H-bridge-]
Changed lines 26-27 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293NE or SN754410 H-bridge-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293NE\\or SN754410 H-bridge-]
Changed lines 26-29 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293 H-bridge-]

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg | http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg"SN754410 H-bridge"]] | [-
SN754410 H-bridge-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293NE or SN754410 H-bridge-]
Changed line 99 from:
%lframe width=350px% [[http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg"Arduino module connected to an H-bridge"]] | [-Arduino module connected to an H-bridge-]
to:
%lframe width=370px% [[http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg"Arduino module connected to an H-bridge"]] | [-Arduino module connected to an H-bridge-]
Deleted line 78:
Added lines 82-83:
%lframe width=200px valign=center% [[http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg | http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg"SN754410 H-bridge"]] | [-SN754410 H-bridge-]
Deleted lines 85-86:
%lframe width=200px valign=center% [[http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg | http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg"SN754410 H-bridge"]] | [-SN754410 H-bridge-]
Added lines 80-81:
[[<<]]
Added lines 86-87:
[[<<]]
Changed lines 80-81 from:
http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG
to:
%lframe width=200px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293 H-bridge-]

%lframe width=200px valign=center% [[http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg | http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg"SN754410 H-bridge"]] | [-SN754410 H-bridge-]

Changed line 94 from:
%alt='Arduino module connected to an H-bridge'%http://itp.nyu.edu/physcomp/images/labs/bboard_h-bridge.JPG
to:
%lframe width=350px% [[http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg"Arduino module connected to an H-bridge"]] | [-Arduino module connected to an H-bridge-]
Added lines 28-29:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg | http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg"SN754410 H-bridge"]] | [-SN754410 H-bridge-]
Changed line 92 from:
%alt='Arduino module connected to an H-bridge'%http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg
to:
%alt='Arduino module connected to an H-bridge'%http://itp.nyu.edu/physcomp/images/labs/bboard_h-bridge.JPG
Changed lines 26-29 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg
| http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg
"SN754410 H-bridge"]] | [-SN754410 H-bridge-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293 H-bridge-]
Changed lines 26-27 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293 H-bridge-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg
| http://itp.nyu.edu/physcomp/uploads/h_bridge_01.jpg
"SN754410 H-bridge"]] | [-SN754410 H-bridge-]
Changed line 92 from:
%alt='Arduino module connected to an H-bridge'%http://itp.nyu.edu/physcomp/images/labs/bboard_h-bridge.JPG
to:
%alt='Arduino module connected to an H-bridge'%http://itp.nyu.edu/physcomp/images/labs/arduino_hbridge.jpg
Changed lines 66-67 from:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293E|STMicroelectronics L293E]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. If an H-bridge is not available in your Physical Computing Kit, they should have them for purchase at the NYU Computer Store and online at many distributors such as: [[http://www.digikey.com|Digikey]], [[http://www.sparkfun.com/commerce/product_info.php?products_id=315|SparkFun]], [[http://www.mouser.com|Mouser]] and [[http://www.jameco.com|Jameco]]. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.
to:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293NE|Texas Instruments L293NE]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. If an H-bridge is not available in your Physical Computing Kit, they should have them for purchase at the NYU Computer Store and online at many distributors such as: [[http://www.digikey.com|Digikey]], [[http://www.sparkfun.com/commerce/product_info.php?products_id=315|SparkFun]], [[http://www.mouser.com|Mouser]] and [[http://www.jameco.com|Jameco]]. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.
Changed lines 5-6 from:
To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. There are many different models and brands of H-Bridge.  This tutorial uses one of the most basic, a [[http://octopart.com/search?q=L293NE|STMicroelectronics L293NE]] or a [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]].
to:
To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. There are many different models and brands of H-Bridge.  This tutorial uses one of the most basic, a [[http://octopart.com/search?q=L293NE|Texas Instruments L293NE]] or a [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]].
Changed lines 5-6 from:
To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. There are many different models and brands of H-Bridge.  This tutorial uses one of the most basic, a [[http://octopart.com/search?q=L293E|STMicroelectronics L293E]] or a [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]].
to:
To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. There are many different models and brands of H-Bridge.  This tutorial uses one of the most basic, a [[http://octopart.com/search?q=L293NE|STMicroelectronics L293NE]] or a [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]].
Changed lines 64-65 from:
!!!   Get an H-bridge
to:
!!! Acquire an H-bridge
Changed lines 66-67 from:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293E|STMicroelectronics L293E]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. If an H-bridge is not available in your Physical Computing Kit, they should have them for purchase at the NYU Computer Store and online at many distributors such as: [[http://www.digikey.com|Digikey]],[[http://www.sparkfun.com/commerce/product_info.php?products_id=315|SparkFun]], [[http://www.mouser.com|Mouser]] and [[http://www.jameco.com|Jameco]]. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.
to:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293E|STMicroelectronics L293E]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. If an H-bridge is not available in your Physical Computing Kit, they should have them for purchase at the NYU Computer Store and online at many distributors such as: [[http://www.digikey.com|Digikey]], [[http://www.sparkfun.com/commerce/product_info.php?products_id=315|SparkFun]], [[http://www.mouser.com|Mouser]] and [[http://www.jameco.com|Jameco]]. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.
Changed lines 66-67 from:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293E|STMicroelectronics L293E]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. [[http://www.acroname.com |Acroname]] and [[http://www.digikey.com |Digikey]] carry these chips, as do many other manufacturers. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.
to:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293E|STMicroelectronics L293E]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. If an H-bridge is not available in your Physical Computing Kit, they should have them for purchase at the NYU Computer Store and online at many distributors such as: [[http://www.digikey.com|Digikey]],[[http://www.sparkfun.com/commerce/product_info.php?products_id=315|SparkFun]], [[http://www.mouser.com|Mouser]] and [[http://www.jameco.com|Jameco]]. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.
Changed lines 78-81 from:
http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge

The
logic inputs on the H-bridge connect to the pins on your microcontroller that you use to output control signals to the H-bridge and the supply output pins go to your motor. The configuration of these pins might vary slightly on other models of H-bridge. They might also use slightly different names, but the functions are roughly the same.
to:
http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG

The
logic inputs on the H-bridge connect to the digitals pins on your microcontroller that you use to output control signals to the H-bridge. The configuration of these pins might vary slightly on other models of H-bridge. They might also use slightly different names, but the functions are roughly the same.
Changed lines 99-100 from:
!!! program the Microcontroller
to:
!!! Program the Microcontroller
Changed lines 159-160 from:
Once you've seen this code working, try modifying the speed of the motor using the analogWrite() function, as explained in the [[Labs/AnalogIn |analog lab]].  Use analogWrite() on pin 9, the enable pin of the motor, and see what happens as you change the value of the analogWrite().
to:
Once you've seen this code working, try modifying the speed of the motor using the analogWrite() function, as explained in the [[Labs/AnalogIn|Analog Lab]].  Use analogWrite() on pin 9, the enable pin of the motor, and see what happens as you change the value of the analogWrite().
Changed lines 163-166 from:
Use your motor to make something move, vibrate, rise, fall, roll, creep, or whatever you can think of, in response to user input from a digital input device (switch, floor sensor, tripwire, etc). Look inside moving toys, you'll find a number of excellent motors and gears you can re-purpose. See the innards of a cymbal monkey below as an example.  Perhaps you can re-design the user interface to a toy, using the microcontroller to meciate between new sensors on the toy and the motors of the toy. Whatever you build, make sure it reacts in some way to human action.

%alt='the innards of a cymbal monkey, showing the motors and gears'%http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_innards.JPG
to:
Use your motor to make something move, vibrate, rise, fall, roll, creep, or whatever you can think of, in response to user input from a digital input device (switch, floor sensor, tripwire, etc). Look inside moving toys, you'll find a number of excellent motors and gears you can re-purpose. See the innards of a cymbal monkey below as an example.  Perhaps you can re-design the user interface to a toy, using the microcontroller to mediate between new sensors on the toy and the motors of the toy. Whatever you build, make sure it reacts in some way to human action.

%alt='the innards of a cymbal monkey, showing the motors and gears'%http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_innards.JPG
Changed lines 76-77 from:
The logic voltage pins connect to the same voltage source as your microcontroller. The motor supply voltage connects to the voltage source for the motor.  Since the motor may need higher voltage an almost certainly needs higher current, this is often a separate power supply. If you're using a motor that draw less than about 750 milliamps at 15 volts or less, you could use the 9-15V power jack on the Arduino module, and switch the module to draw power from this source as well.
to:
The logic voltage pins connect to the same voltage source as your microcontroller. The motor supply voltage connects to the voltage source for the motor, which is usually an external power supply. Most motors require a higher voltage and higher current draw than a microcontroller so the use of an external power supply is needed. If you're using a motor that draws less than 750 milliamps at 15 volts or less, you could use the 9-15V power jack on the Arduino module. Just be sure to switch the jumper on your Arduino to use the external power supply as well instead of USB.
Changed lines 68-77 from:
The L293 is a very basic H-bridge.  There are many different models of H-bridge from other manufacturers.  This one actually has two bridges, one on the left side of the chip and one on the right.  Though they may have some extra features, every H-bridge will have the same basic interface:

* Pins for Logic input
* Pins for Motor Supply voltage
* Pins for Logic voltage
* Pins for Motor Supply output
* Pins for ground

The logic voltage pins connect to the same voltage source as your microcontroller. The motor supply voltage connect to the voltage source for the motor.  Since the motor may need higher voltage an almost certainly needs higher current, this is often a separate supply. If you're using a motor that draw less than about 750 milliamps at 15 volts or less, you could use the 9-15V power jack on the Arduino module, and switch the module to draw power from this source as well.
to:
The L293E is a very basic H-bridge. There are many different models of H-bridges from other manufacturers.  This one in particular has two bridges, one on the left side of the chip and one on the right.  Though they may have some extra features, every H-bridge will have the same basic interface:

* Pins for Logic Input
* Pins for Motor Supply Voltage
* Pins for Logic Voltage
* Pins for Motor Supply Output
* Pins for Ground

The logic voltage pins connect to the same voltage source as your microcontroller. The motor supply voltage connects to the voltage source for the motor.  Since the motor may need higher voltage an almost certainly needs higher current, this is often a separate power supply. If you're using a motor that draw less than about 750 milliamps at 15 volts or less, you could use the 9-15V power jack on the Arduino module, and switch the module to draw power from this source as well.
Changed lines 66-68 from:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293E|STMicroelectronics L293E]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. [[http://www.acroname.com |Acroname]] and [[http://www.digikey.com |Digikey]] carry these chips, as do many other manufacturers. You can find its datasheet [[
This example uses an H-bridge integrated circuit, the Texas Instruments L293 (also sold as  the SN754410). [[http://www.acroname.com |Acroname]] and [[http://www.digikey.com |Digikey]] carry these chips, as do many other manufacturers. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge. |here]]. This particular chip has 2 H-
bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.
to:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293E|STMicroelectronics L293E]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. [[http://www.acroname.com |Acroname]] and [[http://www.digikey.com |Digikey]] carry these chips, as do many other manufacturers. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.
Changed line 66 from:
This example uses an H-bridge integrated circuit, the Texas Instruments L293 (also sold as  the SN754410). [[http://www.acroname.com |Acroname]] and [[http://www.digikey.com |Digikey]] carry these chips, as do many other manufacturers. You can find its datasheet [[
to:
This example uses an H-bridge integrated circuit, the [[http://octopart.com/search?q=L293E|STMicroelectronics L293E]] or [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]]. [[http://www.acroname.com |Acroname]] and [[http://www.digikey.com |Digikey]] carry these chips, as do many other manufacturers. You can find its datasheet [[
Changed lines 60-61 from:
Find yourself a DC motor that runs on low DC voltage within the range of 5 - 15V. Connect leads to its terminals, and power it using a bench power supply (available from the ER). With most motors, there is no polarity regarding the motor terminals so you may hook it up any way you'd like. Adjust the voltage on the bench power supply and observe its effects. Take note of its speed at different voltages without dipping to low or too high. Running a motor at a voltage much lower or much higher than what it's rated for could potentially damage or permanently destroy your motor.
to:
Find yourself a DC motor that runs on low DC voltage within the range of 5 - 15V. [[http://www.radioshack.com/search/index.jsp?kwCatId=&kw=dc%20motor&origkw=dc%20motor&sr=1|RadioShack]] often sells several small DC motors, the NYU Computer Store on occasion has small a few, the junk shelf is almost always a goldmine for discarded motors and fans, or simply asking classmates and second years is a good approach to borrowing a motor.

First, connect leads to the motor's
terminals, and power it using a bench power supply (available from the ER). With most motors, there is no polarity regarding the motor terminals so you may hook it up any way you'd like. Adjust the voltage on the bench power supply and observe its effects. Take note of its speed at different voltages without dipping to low or too high. Running a motor at a voltage much lower or much higher than what it's rated for could potentially damage or permanently destroy your motor.
Changed lines 35-36 from:
Conect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V and any of the ground connections:
to:
Connect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V and any of the ground connections:
Changed lines 58-61 from:
!!! Get a motor

Get a DC motor that runs on low voltage DC, in the 5-15V range. Connect leads to its terminals, and run if from a benchtop power supply. Try changing the voltage on it, and seeing what effect it has. Don't go over the motor's rated voltage. IF you do, the motor will ruin very hot, and probably stop within a minute and burn out.
to:
!!! Find a motor

Find yourself a DC motor that runs on low DC voltage within the range of 5 - 15V. Connect leads to its terminals, and power it using a bench power supply (available from the ER). With most motors, there is no polarity regarding the motor terminals so you may hook it up any way you'd like. Adjust the voltage on the bench power supply and observe its effects. Take note of its speed at different voltages without dipping to low or too high. Running a motor at a voltage much lower or much higher than what it's rated for could potentially damage or permanently destroy your motor.
Deleted line 63:
Changed lines 24-25 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/switch.jpg | http://itp.nyu.edu/physcomp/images/labs/switch.jpg"switch"]] | [-switch-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/switch.jpg | http://itp.nyu.edu/physcomp/images/labs/switch.jpg"switch"]] | [-Switch-]
Changed lines 28-29 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/dc_power_supply.JPG | http://itp.nyu.edu/physcomp/images/labs/dc_power_supply.JPG"DC power supply"]] | [-DC power supply-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/dc_power_supply.JPG | http://itp.nyu.edu/physcomp/images/labs/dc_power_supply.JPG"DC power supply"]] | [-12V DC power supply-]
Changed lines 7-8 from:
If you simply want to turn a motor on and off, and don't need to reverse it, for example if you're controlling a fan, try the [[Tutorials/Tutorials | tutorial]] on [[Tutorials/HighCurrentLoads |controlling high current loads with transistors]].
to:
If you simply want to turn a motor on and off, and don't need to reverse it, for example if you're controlling a fan, try the tutorial on [[Tutorials/HighCurrentLoads|controlling high current loads with transistors]].
Changed lines 5-6 from:
To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. There are many different models and brands of H-Bridge.  This tutorial uses one of the most basic, an [[http://octopart.com/search?q=L293E|STMicroelectronics L293E]] or a [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]].
to:
To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. There are many different models and brands of H-Bridge.  This tutorial uses one of the most basic, a [[http://octopart.com/search?q=L293E|STMicroelectronics L293E]] or a [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]].
Changed lines 5-6 from:
To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. There are many different models and brands of H-Bridge.  This tutorial uses one of the most basic, an L293E from Texas Instruments (the alternate name for this chip is the SN754410).
to:
To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. There are many different models and brands of H-Bridge.  This tutorial uses one of the most basic, an [[http://octopart.com/search?q=L293E|STMicroelectronics L293E]] or a [[http://octopart.com/search?q=SN754410|Texas Instruments SN754410]].
Changed line 133 from:
  if (digiralRead(switchPin) == HIGH) {
to:
  if (digitalRead(switchPin) == HIGH) {
Changed lines 7-8 from:
If you simply want to turn a motor on and off, and don't need to reverse it, for example if you're controlling a fan, try the transistor tutorial.
to:
If you simply want to turn a motor on and off, and don't need to reverse it, for example if you're controlling a fan, try the [[Tutorials/Tutorials | tutorial]] on [[Tutorials/HighCurrentLoads |controlling high current loads with transistors]].
Changed lines 7-8 from:
If you simply want to turn a motor on and off, and don't need to reverse it, for example if you're controlling a fan, try the TIP120 tutorial.
to:
If you simply want to turn a motor on and off, and don't need to reverse it, for example if you're controlling a fan, try the transistor tutorial.
Changed lines 165-166 from:
%alt='the innards of a cymbal monkey, showing the motors and gears'%http://itp.nyu.edu/physcomp/images/labs/cymbal)_monkey_innards.JPG
to:
%alt='the innards of a cymbal monkey, showing the motors and gears'%http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_innards.JPG
Changed lines 80-82 from:
The logic inputs on the H-bridge connect to the pins on your microcontroller that you use to output control signals to the H-bridge and the supply output pins go to your motor. The configuration of these pins might vary slightly depending on the manufacturer of the H-bridge. They might also use slightly different names, but the functions are roughly the same.

to:
The logic inputs on the H-bridge connect to the pins on your microcontroller that you use to output control signals to the H-bridge and the supply output pins go to your motor. The configuration of these pins might vary slightly on other models of H-bridge. They might also use slightly different names, but the functions are roughly the same.
Deleted lines 85-86:
H-Bridge connected to a PIC. Note the motor supply wire. In this example, it runs to the 12V input from the DC power supply, because the motor runs on 12V. It may be different on your circuit, depending on the voltage your motor needs. Note also the 10Kohm pulldown resistor needed on the enable pin.
Added lines 158-160:

Once you've seen this code working, try modifying the speed of the motor using the analogWrite() function, as explained in the [[Labs/AnalogIn |analog lab]].  Use analogWrite() on pin 9, the enable pin of the motor, and see what happens as you change the value of the analogWrite().

Changed lines 163-166 from:
Use your motor to make something move, vibrate, rise, fall, roll, creep, or whatever you can think of, in response to user input from a digital input device (switch, floor sensor, tripwire, etc).
to:
Use your motor to make something move, vibrate, rise, fall, roll, creep, or whatever you can think of, in response to user input from a digital input device (switch, floor sensor, tripwire, etc). Look inside moving toys, you'll find a number of excellent motors and gears you can re-purpose. See the innards of a cymbal monkey below as an example.  Perhaps you can re-design the user interface to a toy, using the microcontroller to meciate between new sensors on the toy and the motors of the toy. Whatever you build, make sure it reacts in some way to human action.

%alt='the innards of a cymbal monkey, showing the motors and gears'%http://itp.nyu.edu/physcomp/images/labs/cymbal)_monkey_innards.JPG

Changed lines 3-6 from:
In this tutorial, you'll learn how to control a DC motor's direction and speed using an H-bridge. 

To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. There are many different models and brands of H-Bridge.  This tutorial uses one of the most basic, an L293# from Texas Instruments (the alternate name for this chip is the SN754410).
to:
In this tutorial, you'll learn how to control a DC motor's direction using an H-bridge. 

To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. There are many different models and brands of H-Bridge.  This tutorial uses one of the most basic, an L293E from Texas Instruments (the alternate name for this chip is the SN754410).
Changed lines 9-10 from:
For this tutorial you'll need:
to:
For this lab you'll need:
Changed lines 60-61 from:
Get a DC motor that runs on low voltage DC, in the 5-15V range. Connect leads to its terminals, and run if from a benchtop power supply in the lab. Try changing the voltage on it, and seeing what effect it has. Don't go over the motor's rated voltage.
to:
Get a DC motor that runs on low voltage DC, in the 5-15V range. Connect leads to its terminals, and run if from a benchtop power supply. Try changing the voltage on it, and seeing what effect it has. Don't go over the motor's rated voltage. IF you do, the motor will ruin very hot, and probably stop within a minute and burn out.
Changed lines 64-65 from:
Though they may have some extra features, every H-bridge will have the same basic interface:
to:

This example uses an H-bridge integrated circuit, the Texas Instruments L293 (also sold as  the SN754410). [[http://www.acroname.com |Acroname]] and [[http://www.digikey.com |Digikey]] carry these chips, as do many other manufacturers. You can find its datasheet [[
This example uses an H-bridge integrated circuit, the Texas Instruments L293 (also sold as  the SN754410). [[http://www.acroname.com |Acroname]] and [[http://www.digikey.com |Digikey]] carry these chips, as do many other manufacturers. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge. |here]]. This particular chip has 2 H-bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.

The L293 is a very basic H-bridge.  There are many different models of H-bridge from other manufacturers.  This one actually has two bridges, one on the left side of the chip and one on the right. 
Though they may have some extra features, every H-bridge will have the same basic interface:
Changed lines 78-82 from:
ADD PIX HERE

The
logic inputs on the H-bridge connect to the pins on your microcontroller that you use to output control signals to the H-bridge and the supply output pins go to your motor. The configuration of these pins might vary slightly depending on the manufacturer of the H-bridge. They might also use slightly different names, but the functions are the same.

This example uses an H-bridge integrated circuit, the Texas Instruments L293 (also sold as  the SN754410). [[http://www.acroname.com |Acroname]] and [[http://www.digikey.com |Digikey]] carry these chips, as do many other manufacturers. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.
to:
http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge

The
logic inputs on the H-bridge connect to the pins on your microcontroller that you use to output control signals to the H-bridge and the supply output pins go to your motor. The configuration of these pins might vary slightly depending on the manufacturer of the H-bridge. They might also use slightly different names, but the functions are roughly the same.
Deleted lines 25-27:

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/dc_power_supply.JPG | http://itp.nyu.edu/physcomp/images/labs/dc_power_supply.JPG"DC power supply"]] | [-DC power supply-]

Added lines 28-31:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/dc_power_supply.JPG | http://itp.nyu.edu/physcomp/images/labs/dc_power_supply.JPG"DC power supply"]] | [-DC power supply-]

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/dc_motor.JPG | http://itp.nyu.edu/physcomp/images/labs/dc_motor.JPG"DC Motor"]] | [-DC Motor-]

Deleted lines 33-36:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/dc_motor.JPG | http://itp.nyu.edu/physcomp/images/labs/dc_motor.JPG"DC Motor"]] | [-DC Motor-]

[[<<]]

Added lines 17-19:

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/leds.jpg | http://itp.nyu.edu/physcomp/images/labs/leds.jpg"Light Emiting Diodes"]] | [-Light Emiting Diodes, LED -]

Changed lines 22-26 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/leds.jpg | http://itp.nyu.edu/physcomp/images/labs/leds.jpg"Light Emiting Diodes"]] | [-Light Emiting Diodes, LED -]

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm, 1Kohm, and \\

10Kohm resistors-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-10Kohm resistors-]
Deleted lines 26-27:
[[<<]]
Added lines 31-32:
[[<<]]
Deleted line 34:
Added lines 26-28:

[[<<]]

Changed lines 33-35 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/dc_motor.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_dc_motor.JPG"DC Motoe"]] | [-DC Motor-]

to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/dc_motor.JPG | http://itp.nyu.edu/physcomp/images/labs/dc_motor.JPG"DC Motor"]] | [-DC Motor-]

Changed lines 24-29 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/switch.jpg | http://itp.nyu.edu/physcomp/images/labs/switch.jpg"resistors"]] | [-switch-]

* 5-15VDC power supply
* L293E H-bridge
* DC
motor
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/switch.jpg | http://itp.nyu.edu/physcomp/images/labs/switch.jpg"switch"]] | [-switch-]

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/dc_power_supply.JPG | http://itp.nyu.edu/physcomp/images/labs/dc_power_supply.JPG"DC power supply"]] | [-DC power supply-]

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293 H-bridge-]

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/dc_
motor.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_dc_motor.JPG"DC Motoe"]] | [-DC Motor-]

Deleted line 26:
* Switch
Added line 89:
%alt='Arduino module with breadboard shield connected to an H-bridge'%http://itp.nyu.edu/physcomp/images/labs/bboard_shield_h-bridge.JPG
Added line 91:
%alt='Arduino module connected to an H-bridge'%http://itp.nyu.edu/physcomp/images/labs/bboard_h-bridge.JPG
Changed lines 92-101 from:
Most motors take a great deal more current than a microprocessor, and need their own supply. The example above uses 12V, run in paralle with the 7805 regulator. Whatever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!).

Note
the two capacitors on either side of our regulator. They smooth out the power, as the motor will cause spikes and dips when it turns on and off.

Here's
the schematic for the capacitors and the regulator:

If your power supply for the micocontroller is compatible with your motor, you can wire the motor supply in parallel with the 5V regulator. For example, I use a 12V DC 1000 mA power adaptor, so I can use a 12V motor, if the power from the motor is wired in parallel with the 5V regulator's input, like so:

Note that the motor and the microcontroller need a common ground (in our case, they get it through the transistor's base; see above schematic).
to:
Most motors consume more current than a microprocessor, and need their own supply. The motor and the microcontroller need a common ground, however.  The example above uses 12V, run in parallel with the 5V voltage regulator that supplies the Arduino board. Whatever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!).

Note the capacitor connecting the motor supply to ground. It smooths out
the voltage spikes and dips that occur as the motor turns on and off.
Changed line 136 from:
  if (switchPin == HIGH) {
to:
  if (digiralRead(switchPin) == HIGH) {
Changed lines 44-45 from:
Connect a switch to digital input 2 on the Arduino. The switch shown below is a store-bought momentary pushbutton, but you can use any switch.  Try making your own with a couple of pieces of metal.
to:
Connect a switch to digital input 2 on the Arduino.
Changed lines 59-60 from:
Get a DC motor that runs on low voltage DC, in the 5-15V range. Connect leads to its terminals, and run if from a benchtop power supply in the lab. Try changing the voltage on it, and seeing what effect it has. Don't go over the motor's rated voltage. Connect a switch in series with the motor and use it to turn on the motor.
to:
Get a DC motor that runs on low voltage DC, in the 5-15V range. Connect leads to its terminals, and run if from a benchtop power supply in the lab. Try changing the voltage on it, and seeing what effect it has. Don't go over the motor's rated voltage.
Changed lines 65-66 from:
* Pins for logic input
* Pins for Supply voltage
to:
* Pins for Logic input
* Pins for Motor Supply voltage
Changed line 68 from:
* Pins for Supply output
to:
* Pins for Motor Supply output
Changed lines 71-72 from:
The logic voltage pins connect to the same voltage source as your microcontroller. The supply voltage connect to the voltage source for the motor.  Since the motor may need higher voltage an almost certainly needs higher current, this is often a separate supply. If you're using a motor that draw less than about 750 milliamps at 15 volts or less, you could use the 9-15V power jack on the Arduino module, and switch the module to draw power from this source as well.
to:
The logic voltage pins connect to the same voltage source as your microcontroller. The motor supply voltage connect to the voltage source for the motor.  Since the motor may need higher voltage an almost certainly needs higher current, this is often a separate supply. If you're using a motor that draw less than about 750 milliamps at 15 volts or less, you could use the 9-15V power jack on the Arduino module, and switch the module to draw power from this source as well.
Changed lines 83-84 from:
H-Bridge connected to a PIC. Note the motor supply wire. In this example, it runs to the 12V input from the DC power supply, because the motor runs on 12V. It may be different on your circuit, depending on the votlage your motor needs. Note also the 10Kphm pulldown resistor needed on the enable pin.
to:
H-Bridge connected to a PIC. Note the motor supply wire. In this example, it runs to the 12V input from the DC power supply, because the motor runs on 12V. It may be different on your circuit, depending on the voltage your motor needs. Note also the 10Kohm pulldown resistor needed on the enable pin.
Changed lines 94-95 from:
Note that we've added two capacitors on either side of our regulator. They smooth out the power, as the motor will cause spikes and dips when it turns on and off.
to:
Note the two capacitors on either side of our regulator. They smooth out the power, as the motor will cause spikes and dips when it turns on and off.
Changed lines 57-58 from:
With any H-bridge, you will have certain elements:
to:
!!! Get a motor

Get a DC motor that runs on low voltage DC, in the 5-15V range. Connect leads to its terminals, and run if from a benchtop power supply in the lab. Try changing the voltage on it, and seeing what effect it has. Don't go over the motor's rated voltage. Connect a switch in series with the motor and use it to turn on the motor.

!!!  Get an H-bridge

Though they may have some extra features, every H-bridge will have the same basic interface
:
Changed lines 71-77 from:
The logic voltage pins want the same voltage and current as your microcontroller. The supply voltage wants whatever voltage and current you run your motors with. The logic inputs connect to the pins on your microcontroller that you use to output control signals to the H-bridge. And the supply output pins go to your motor. The configuration of these pins might vary slightly depending on the manufacturer of the H-bridge. They might also use slightly different names, but the concepts are the same.

This example uses an H-bridge integrated circuit, the Texas Instruments SN754410 (you can also use the L293, which is identical to ths TI chip). Acroname carries these chips, as do many other manufacturers. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.

!!! Get a motor

Get a DC motor that runs on low voltage DC, in the 5-15V range. Connect leads to its terminals, and run if from a benchtop power supply in the lab. Try changing the voltage on it, and seeing what effect it has. Don't go over the motor's rated voltage. Connect a switch in series with the motor and use it to turn on the motor
.
to:
The logic voltage pins connect to the same voltage source as your microcontroller. The supply voltage connect to the voltage source for the motor.  Since the motor may need higher voltage an almost certainly needs higher current, this is often a separate supply. If you're using a motor that draw less than about 750 milliamps at 15 volts or less, you could use the 9-15V power jack on the Arduino module, and switch the module to draw power from this source as well.

ADD PIX HERE

The logic inputs on
the H-bridge connect to the pins on your microcontroller that you use to output control signals to the H-bridge and the supply output pins go to your motor. The configuration of these pins might vary slightly depending on the manufacturer of the H-bridge. They might also use slightly different names, but the functions are the same.

This example uses an H-bridge integrated circuit, the Texas Instruments L293 (also sold as  the SN754410). [[http://www.acroname.com |Acroname]] and [[http://www.digikey.com |Digikey]] carry these chips, as do many other manufacturers. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge
.
Added line 12:
Added line 14:
Added line 18:
Changed lines 21-23 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm 1Kohm, \\
and and 10Kohm resistors-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm, 1Kohm, and \\
10Kohm resistors-]
Changed lines 18-19 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm 1Kohm, \\and and 10Kohm resistors-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm 1Kohm, \\
and and 10Kohm resistors-]
Changed lines 17-19 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm 1Kohm, and and 10Kohm resistors-]
to:

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm 1Kohm, \\and and 10Kohm resistors-]
Changed line 17 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm and 10Kohm resistors-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm 1Kohm, and and 10Kohm resistors-]
Deleted line 20:
* LED
Changed lines 24-27 from:
* 10Kohm resistor
* 1Kohm resistor
* 220 ohm resistors

to:
Deleted lines 19-21:

* Prototyping board (breadboard)
* Power supply connector (2)
Changed lines 21-26 from:
* Assorted wires
* 5V regulator
* PIC 18F452 or BX-24
* Serial cable
* DB9 female serial connector & headers
* LEDs
to:
* LED
Changed line 23 from:
* SN754410 (or L293) H-bridge
to:
* L293E H-bridge
Changed lines 25-28 from:
* power supply for DC motor
* 10uF capacitor
* 1uF capacitor
* 10Kohm resistors
to:
* 10Kohm resistor
* 1Kohm resistor
Changed line 1 from:
DC Motor Control Using an H-Bridge
to:
!! DC Motor Control Using an H-Bridge
Changed lines 3-5 from:

Minimum parts needed: (new parts in bold. see parts list for details
)
to:
In this tutorial, you'll learn how to control a DC motor's direction and speed using an H-bridge. 

To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. There are many different models and brands of H-Bridge.  This tutorial uses one of the most basic, an L293# from Texas Instruments (the alternate name for this chip is the SN754410
).

If you simply want to turn a motor on and off, and don't need to reverse it, for example if you're controlling a fan, try the TIP120 tutorial.

For this tutorial you'll need:

%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/breadboard.jpg | http://itp.nyu.edu/physcomp/images/labs/breadboard.jpg"Solderless breadboard"]] | [-Solderless breadboard-]
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/hookup_wire.jpg | http://itp.nyu.edu/physcomp/images/labs/hookup_wire.jpg"hookup wire"]] | [-22-AWG hookup wire-]
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/arduino.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino.jpg"Arduino module"]] | [-Arduino Microcontroller \\
module-]
[[<<]]
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/leds.jpg | http://itp.nyu.edu/physcomp/images/labs/leds.jpg"Light Emiting Diodes"]] | [-Light Emiting Diodes, LED -]
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm and 10Kohm resistors-]
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/switch.jpg | http://itp.nyu.edu/physcomp/images/labs/switch.jpg"resistors"]] | [-switch-]


Changed lines 39-42 from:
(Note: if you simply want to turn a motor on and off, and don't need to reverse it, for example if you're controlling a fan, try the TIP120 example).

To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. With any H-bridge, you will have certain elements:

to:
[[<<]]

!!! Prepare the breadboard
Conect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V and any of the ground connections:

%alt='Arduino connected to a breadboard' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/arduino_bboard_power.jpg

If you're using an Arduino breadboard shield, there is a row of sockets connected to 5V on the analog in side of the breadboard, and a row connected to ground on the digital in side of the board:

%alt='Arduino breadboard shield' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/breadboard_shield.jpg

!!! Add a Digital Input (a switch)

Connect a switch to digital input 2 on the Arduino. The switch shown below is a store-bought momentary pushbutton, but you can use any switch.  Try making your own with a couple of pieces of metal.

(:table:)
(:cellnr colspan=2:)
%alt='Arduino digital in schematic' height=300%http://itp.nyu.edu/physcomp/images/labs/arduino_dig_input_schem.png
(:cellnr:)
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch.jpg\\
Breadboard version
(:cell:)
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_shield_switch.jpg\\
Shield version
(:tableend:)

With any H-bridge, you will have certain elements:

Changed line 50 from:
%alt='schematic of Arduino module connected to an H-bridge'%http://itp.nyu.edu/physcomp/images/labs/arduino_h-bridge_schem.png
to:
%height=300 alt='schematic of Arduino module connected to an H-bridge'%http://itp.nyu.edu/physcomp/images/labs/arduino_h-bridge_schem.png
Changed lines 48-49 from:
H-brige connected to a BX-24.
to:
(:table:)
(:cellnr colspan=2:)
%alt='schematic of Arduino module connected to an H
-bridge'%http://itp.nyu.edu/physcomp/images/labs/arduino_h-bridge_schem.png
(:cellnr:)
(:cell:)
(:tableend:)

Changed lines 65-78 from:
/*
  DC Motor Control
 
 This program controls a DC motor through an L293 H-bridge.
 The H-bridge's inputs are on pins D3 and D4. Its enable pin
 is on pin D9.
 
 A switch is attached to D2. An LED is attached to D13, just
 to see that the module is working.
 
 by Tom Igoe
 created 1 June 2006
 */

to:
Changed lines 64-65 from:
MOTOR CODE
to:
[@
/*
  DC Motor Control
 
 This program controls a DC motor through an L293 H-bridge.
 The H-bridge's inputs are on pins D3 and D4. Its enable pin
 is on pin D9.
 
 A switch is attached to D2. An LED is attached to D13, just
 to see that the module is working.
 
 by Tom Igoe
 created 1 June 2006
 */

int switchPin = 2;    // switch input
int motor1Pin = 3;    // H-bridge leg 1
int motor2Pin = 4;    // H-bridge leg 2
int speedPin = 9;    // H-bridge enable pin
int ledPin = 13;      //LED

void setup() {
  // set the switch as an input:
  pinMode(switchPin, INPUT);

  // set all the other pins you're using as outputs:
  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
  pinMode(speedPin, OUTPUT);
  pinMode(ledPin, OUTPUT);

  // set speedPin high so that motor can turn on:
  digitalWrite(speedPin, HIGH);

  // blink the LED 3 times. This should happen only once.
  // if you see the LED blink three times, it means that the module
  // reset itself,. probably because the motor caused a brownout
  // or a short.
  blink(ledPin, 3, 100);
}

void loop() {
  // if the switch is high, motor will turn on one direction:
  if (switchPin == HIGH) {
    digitalWrite(motor1Pin, LOW);  // set leg 1 of the H-bridge low
    digitalWrite(motor2Pin, HIGH);  // set leg 2 of the H-bridge high
  }
  // if the switch is low, motor will turn in the other direction:
  else {
    digitalWrite(motor1Pin, HIGH);  // set leg 1 of the H-bridge high
    digitalWrite(motor2Pin, LOW);  // set leg 2 of the H-bridge low
  }
}

/*
  blinks an LED
 */
void blink(int whatPin, int howManyTimes, int milliSecs) {
  int i = 0;
  for ( i = 0; i < howManyTimes; i++) {
    digitalWrite(whatPin, HIGH);
    delay(milliSecs/2);
    digitalWrite(whatPin, LOW);
    delay(milliSecs/2);
  }
}

@]
Changed lines 38-39 from:
Step 1:
to:
!!! Get a motor
Changed lines 42-43 from:
Step 2:
to:
!!! Connect the motor to the H-bridge
Changed lines 60-61 from:
Step 3:
to:
!!! program the Microcontroller
Changed lines 64-133 from:
PIC:

' switch is on RC4:
switchPin var portc.4
input switchPin

' H-bridge is on RC2 and RC3. Enable is on pin RC1
motor1Pin var portc.2
motor2pin var portc.3
speedPin var portc.1

output motor1Pin
output motor2pin
output speedPin

' start with speed on:
high speedPin

main:

' switch direction:
if (switchPin = 1) then
low motor1Pin
high motor2Pin
else
low motor2Pin
high motor1Pin
endif

' blinking LED to tell that the program is still running:
high portb.0
pause 50
low portb.0
pause 50
goto main



BX-24:

' H-bridge is connected to pins 11 and 12.
' Switch is connected to pin 20
' motor enable pin is connected to pin 8

Const switchPin as byte = 20
Const motor1Pin as byte = 11
Const motor2Pin as byte = 12
Const motorEnablePin as byte = 8
Dim motorDirection as byte

Sub main()
' initialize  variables:
call putPin(motor1Pin,1)
call putPin(motor2Pin,0)
motorDirection =  getPin(motorEnablePin)

do
if motorDirection  = 1 then
call putPin(motor1Pin,0)
call putPin(motor2Pin,1)
else
call putPin(motor1Pin,1)
call putPin(motor2Pin,0)
end if
loop
end sub


Step 5:

to:
MOTOR CODE

!!! Get creative

Added lines 1-134:
DC Motor Control Using an H-Bridge


Minimum parts needed: (new parts in bold. see parts list for details)

* Prototyping board (breadboard)
* Power supply connector (2)
* 5-15VDC power supply
* Assorted wires
* 5V regulator
* PIC 18F452 or BX-24
* Serial cable
* DB9 female serial connector & headers
* LEDs
* Switch
* SN754410 (or L293) H-bridge
* DC motor
* power supply for DC motor
* 10uF capacitor
* 1uF capacitor
* 10Kohm resistors
* 220 ohm resistors

(Note: if you simply want to turn a motor on and off, and don't need to reverse it, for example if you're controlling a fan, try the TIP120 example).

To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. With any H-bridge, you will have certain elements:

* Pins for logic input
* Pins for Supply voltage
* Pins for Logic voltage
* Pins for Supply output
* Pins for ground

The logic voltage pins want the same voltage and current as your microcontroller. The supply voltage wants whatever voltage and current you run your motors with. The logic inputs connect to the pins on your microcontroller that you use to output control signals to the H-bridge. And the supply output pins go to your motor. The configuration of these pins might vary slightly depending on the manufacturer of the H-bridge. They might also use slightly different names, but the concepts are the same.

This example uses an H-bridge integrated circuit, the Texas Instruments SN754410 (you can also use the L293, which is identical to ths TI chip). Acroname carries these chips, as do many other manufacturers. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.

Step 1:

Get a DC motor that runs on low voltage DC, in the 5-15V range. Connect leads to its terminals, and run if from a benchtop power supply in the lab. Try changing the voltage on it, and seeing what effect it has. Don't go over the motor's rated voltage. Connect a switch in series with the motor and use it to turn on the motor.

Step 2:

Connect the motor to the H-bridge as follows:

H-Bridge connected to a PIC. Note the motor supply wire. In this example, it runs to the 12V input from the DC power supply, because the motor runs on 12V. It may be different on your circuit, depending on the votlage your motor needs. Note also the 10Kphm pulldown resistor needed on the enable pin.

H-brige connected to a BX-24.

Most motors take a great deal more current than a microprocessor, and need their own supply. The example above uses 12V, run in paralle with the 7805 regulator. Whatever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!).

Note that we've added two capacitors on either side of our regulator. They smooth out the power, as the motor will cause spikes and dips when it turns on and off.

Here's the schematic for the capacitors and the regulator:

If your power supply for the micocontroller is compatible with your motor, you can wire the motor supply in parallel with the 5V regulator. For example, I use a 12V DC 1000 mA power adaptor, so I can use a 12V motor, if the power from the motor is wired in parallel with the 5V regulator's input, like so:

Note that the motor and the microcontroller need a common ground (in our case, they get it through the transistor's base; see above schematic).

Step 3:

Program the microcontroller to run the motor through the H-bridge:

PIC:

' switch is on RC4:
switchPin var portc.4
input switchPin

' H-bridge is on RC2 and RC3. Enable is on pin RC1
motor1Pin var portc.2
motor2pin var portc.3
speedPin var portc.1

output motor1Pin
output motor2pin
output speedPin

' start with speed on:
high speedPin

main:

' switch direction:
if (switchPin = 1) then
low motor1Pin
high motor2Pin
else
low motor2Pin
high motor1Pin
endif

' blinking LED to tell that the program is still running:
high portb.0
pause 50
low portb.0
pause 50
goto main



BX-24:

' H-bridge is connected to pins 11 and 12.
' Switch is connected to pin 20
' motor enable pin is connected to pin 8

Const switchPin as byte = 20
Const motor1Pin as byte = 11
Const motor2Pin as byte = 12
Const motorEnablePin as byte = 8
Dim motorDirection as byte

Sub main()
' initialize  variables:
call putPin(motor1Pin,1)
call putPin(motor2Pin,0)
motorDirection =  getPin(motorEnablePin)

do
if motorDirection  = 1 then
call putPin(motor1Pin,0)
call putPin(motor2Pin,1)
else
call putPin(motor1Pin,1)
call putPin(motor2Pin,0)
end if
loop
end sub


Step 5:

Use your motor to make something move, vibrate, rise, fall, roll, creep, or whatever you can think of, in response to user input from a digital input device (switch, floor sensor, tripwire, etc).
  Edit | View | History | Print | Recent Changes | Search Page last modified on September 01, 2013, at 03:19 PM