(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


Using a transistor to control high current loads with an Arduino

Tutorials.HighCurrentLoads History

Hide minor edits - Show changes to output

Changed line 46 from:
Attach:arduino_and_breadboard_bb2.png
to:
Changed line 46 from:
to:
Attach:arduino_and_breadboard_bb2.png
Changed line 164 from:
A motor controlled like this can only be turned in one direction. To be able to reverse the direction of the motor, an H-bridge circuit is required. For more on controlling DC motors with H-bridges, see the [[Labs/DCMotorControl |DC Motor Control lab]]
to:
A motor controlled like this can only be turned in one direction. To be able to reverse the direction of the motor, an H-bridge circuit is required. For more on controlling DC motors with H-bridges, see the [[Labs/DCMotorControl |DC Motor Control lab]]
Deleted lines 160-180:
Try this code:
(:div class=code :)
 
 const %color=#cc6600%int%% potPin = 0;          %color=#7e7e7e%// Analog in 0 connected to the potentiometer
 const %color=#cc6600%int%% transistorPin = 9;    %color=#7e7e7e%// connected to the base of the transistor
 %color=#cc6600%int%% potValue = 0;              %color=#7e7e7e%// value returned from the potentiometer
 
 %color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
  %color=#7e7e7e%// set  the transistor pin as output:
  %color=#cc6600%pinMode%%(transistorPin, %color=#006699%OUTPUT%%);
 }
 
 %color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
  %color=#7e7e7e%// read the potentiometer, convert it to 0 - 255:
  potValue = %color=#cc6600%analogRead%%(potPin) / 4;
  %color=#7e7e7e%// use that to control the transistor:
  %color=#cc6600%analogWrite%%(9, potValue);
 }
 
(:divend:)

Changed lines 142-143 from:
const int transistorPin = 9;    // connected to the base of the transistor
to:
 const int transistorPin = 9;    // connected to the base of the transistor
 
Changed lines 150-153 from:
   digitalWrite(transistorPin, HIGH);
  delay(1000);
   digitalWrite(transistorPin, LOW);
  delay(1000);
to:
   // read the potentiometer:
 
  int sensorValue = analogRead(A0);
  // map the sensor value to a range from 0 - 255:
  int outputValue = map
(sensorValue, 0, 1023, 0, 255);
  // use that to control the transistor:
  analogWrite(transistorPin, outputValue
);
Changed lines 113-114 from:
Here's a quick program to test the circuit:
to:
Write a quick program to test the circuit. Your program should make the transistor pin an output in the setup method. Then in the loop, it should turn the motor on and off every second, just like the [[http://arduino.cc/en/Tutorial/Blink|blink sketch]] does.
Changed lines 118-130 from:
Boo
to:
const int transistorPin = 9;    // connected to the base of the transistor

 void setup() {
  // set  the transistor pin as output:
  pinMode(transistorPin, OUTPUT);
 }

 void loop() {
  digitalWrite(transistorPin, HIGH);
  delay(1000);
  digitalWrite(transistorPin, LOW);
  delay(1000);
 }
Changed lines 135-142 from:

(:div class=code :)
 
 const %color=#cc6600%int%% transistorPin = 9;    %color=#7e7e7e%// connected to
the base of the transistor

 %color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
  %color=#7e7e7e%// set  the transistor pin as output:
  %color=#cc6600%pinMode%%(transistorPin, %color=#006699%OUTPUT%%
);
to:
Now that you see it working, try changing the speed of the motor or the intensity of the lamp using the potentiometer.

To do that, read the voltage of the potentiometer using @@analogRead()@@.  Then map the result to a range from 0 to 255 and save it in a new variable.  Use that variable to set the speed of the motor or the brightness of the lamp using @@analogWrite()@@.

(: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 :)
const int transistorPin = 9;    // connected to the base of the transistor

 void setup() {
  // set  the transistor pin as output:
  pinMode(transistorPin, OUTPUT
);
Changed lines 148-153 from:
 
 %color=#cc6600%void%% %color=#cc6600%'''loop'''%%()
{
  %color=#cc6600%digitalWrite%%(transistorPin, %color=#006699%HIGH%%);
  %color=#cc6600%delay%%(1000);
  %color=#cc6600%digitalWrite%%(transistorPin, %color=#006699%LOW%%);
  %color=#cc6600%delay%%(1000);
to:

 void loop() {
  digitalWrite(transistorPin, HIGH);
  delay(1000);
  digitalWrite(transistorPin, LOW);
  delay(1000);
Added lines 155-164:
(:sourceend:)
>><<


Try this code:
(:div class=code :)
 
 const %color=#cc6600%int%% potPin = 0;          %color=#7e7e7e%// Analog in 0 connected to the potentiometer
 const %color=#cc6600%int%% transistorPin = 9;    %color=#7e7e7e%// connected to the base of the transistor
 %color=#cc6600%int%% potValue = 0;              %color=#7e7e7e%// value returned from the potentiometer
Added lines 166-169:
 %color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
  %color=#7e7e7e%// set  the transistor pin as output:
  %color=#cc6600%pinMode%%(transistorPin, %color=#006699%OUTPUT%%);
 }
Added lines 171-177:
 %color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
  %color=#7e7e7e%// read the potentiometer, convert it to 0 - 255:
  potValue = %color=#cc6600%analogRead%%(potPin) / 4;
  %color=#7e7e7e%// use that to control the transistor:
  %color=#cc6600%analogWrite%%(9, potValue);
 }
 
Deleted lines 179-199:
Now that you see it working, try changing the speed of the motor or the intensity of the lamp using the potentiometer. Try this code:
(:div class=code :)
 
 const %color=#cc6600%int%% potPin = 0;          %color=#7e7e7e%// Analog in 0 connected to the potentiometer
 const %color=#cc6600%int%% transistorPin = 9;    %color=#7e7e7e%// connected to the base of the transistor
 %color=#cc6600%int%% potValue = 0;              %color=#7e7e7e%// value returned from the potentiometer
 
 %color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
  %color=#7e7e7e%// set  the transistor pin as output:
  %color=#cc6600%pinMode%%(transistorPin, %color=#006699%OUTPUT%%);
 }
 
 %color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
  %color=#7e7e7e%// read the potentiometer, convert it to 0 - 255:
  potValue = %color=#cc6600%analogRead%%(potPin) / 4;
  %color=#7e7e7e%// use that to control the transistor:
  %color=#cc6600%analogWrite%%(9, potValue);
 }
 
(:divend:)

Added lines 114-123:

(: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 :)
Boo
(:sourceend:)
>><<


Added line 94:
Changed lines 94-96 from:
Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so:  %height=60 alt='diode and diode schematic%[[Attach:diode.png|Attach:diode.png]] | [-click the image to enlarge-].

to:
Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so: 

%height=60 alt='diode and diode schematic%[[Attach:diode.png|Attach:diode.png]] | [-click the image to enlarge-]
Changed lines 94-96 from:
Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so:  %height=120 alt='diode and diode schematic%[[Attach:diode.png|Attach:diode.png]] | [-click the image to enlarge-].

to:
Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so:  %height=60 alt='diode and diode schematic%[[Attach:diode.png|Attach:diode.png]] | [-click the image to enlarge-].

Changed lines 107-108 from:
to:
[[<<]]
Changed lines 92-93 from:
[-click the image to enlarge-]
to:
Changed lines 103-109 from:
(:table:)
(:cellnr:)
%width=400px%[[Attach:
arduino_transistor_lamp_schem.png|Attach:arduino_transistor_lamp_schem.png]] | [-click the image to enlarge-]
(:cell:)
%width=300px%[[Attach:arduino_transistor_lamp.png|Attach:arduino_transistor_lamp.png]] | [-click the image to enlarge-]
(:tableend:)
to:

%lframe height=300px%[[Attach:arduino_transistor_lamp_schem.png|Attach:arduino_transistor_lamp_schem.png]] | [-click the image to enlarge-]
%lframe height=300px%[[Attach:arduino_transistor_lamp.png|Attach:arduino_transistor_lamp.png]] | [-click the image to enlarge-]

Changed line 88 from:
%lframe height=300px alt='Arduino with TIP-120 Schematic'% [[Attach:motor_lab_schem.png|Attach:motor_lab_schem.png]][-Note: the schematic symbol for the transistor here is actually\\
to:
%lframe height=300px alt='Arduino with TIP-120 Schematic'% [[Attach:transistor_lab_schem.png|Attach:transistor_lab_schem.png]]|[-Note: the schematic symbol for the transistor here is actually\\
Changed lines 88-89 from:
%lframe height=300px alt='Arduino with TIP-120 Schematic'% [[Attach:motor_lab_schem.png|Attach:motor_lab_schem.png]]
[-Note: the schematic symbol for the transistor here is actually\\
to:
%lframe height=300px alt='Arduino with TIP-120 Schematic'% [[Attach:motor_lab_schem.png|Attach:motor_lab_schem.png]][-Note: the schematic symbol for the transistor here is actually\\
Changed line 94 from:
to:
[[<<]]
Changed lines 82-83 from:
%alt='Arduino with potentiometer and transistor' height=200%[[Attach:arduino_bb_pot_transistor_motor2.png|Attach:arduino_bb_pot_transistor_motor2.png]] | [-click the image to enlarge-]
to:
%lframe alt='Arduino with potentiometer and transistor' height=300%[[Attach:arduino_bb_pot_transistor_motor2.png|Attach:arduino_bb_pot_transistor_motor2.png]] | [-click the image to enlarge-]

[[<<]
]
Changed lines 88-90 from:
(:table:)
(:cellnr:)
%height=300px alt='Arduino with TIP-120 Schematic'% [[Attach:motor_lab_schem.png|Attach:motor_lab_schem.png]]
to:
%lframe height=300px alt='Arduino with TIP-120 Schematic'% [[Attach:motor_lab_schem.png|Attach:motor_lab_schem.png]]
Added lines 91-92:

%lframe alt='Arduino with potentiometer and transistor' height=300%[[Attach:arduino_bb_pot_transistor_motor_diode.png|Attach:arduino_bb_pot_transistor_motor_diode.png]] | [-click the image to enlarge-]
Changed lines 94-97 from:
(:cell:)
%alt='Arduino with potentiometer and transistor' height=200%[[Attach:arduino_bb_pot_transistor_motor_diode.png|Attach:arduino_bb_pot_transistor_motor_diode.png]] | [-click the image to enlarge-]
(:tableend:)

to:

Changed lines 75-76 from:
to:
[[<<]]
Changed lines 73-74 from:
%alt='Arduino with potentiometer and transistor' height=200%[[Attach:arduino_bb_pot_transistor.png|Attach:arduino_bb_pot_transistor.png]] | [-click the image to enlarge-]
to:
%lframe alt='Arduino with potentiometer and transistor' hspace=10 height=300%[[Attach:arduino_bb_pot_transistor.png|Attach:arduino_bb_pot_transistor.png]]  [-click the image to enlarge-]

Changed line 52 from:
%lframe alt='Arduino with potentiometer schematic' hspace=10 height=300%[[arduino_pot_schem.png|Attach:arduino_pot_schem.png]]
to:
%lframe alt='Arduino with potentiometer schematic' hspace=10 height=300%[[Attach:arduino_pot_schem.png|Attach:arduino_pot_schem.png]]
Changed lines 51-52 from:
%lframe alt='Arduino with potentiometer' hspace=10 height=300%[[Attach:arduino_pot_bb.png|arduino_pot_bb.png]]
%lframe alt='Arduino with potentiometer schematic' hspace=10 height=300%[[arduino_pot_schem.png|arduino_pot_schem.png]]
to:
%lframe alt='Arduino with potentiometer' hspace=10 height=300%[[Attach:arduino_pot_bb.png|Attach:arduino_pot_bb.png]]
%lframe alt='Arduino with potentiometer schematic' hspace=10 height=300%[[arduino_pot_schem.png|Attach:arduino_pot_schem.png]]
Changed lines 51-52 from:
%lframe alt='Arduino with potentiometer and LED' hspace=10 height=300%[[Attach:arduino_pot_bb.png|arduino_pot_bb.png]]
%lframe alt='Arduino with potentiometer and LED schematic' hspace=10 height=300%[[arduino_pot_schem.png|arduino_pot_schem.png]]
to:
%lframe alt='Arduino with potentiometer' hspace=10 height=300%[[Attach:arduino_pot_bb.png|arduino_pot_bb.png]]
%lframe alt='Arduino with potentiometer schematic' hspace=10 height=300%[[arduino_pot_schem.png|arduino_pot_schem.png]]
Changed lines 47-52 from:
!!! Add a potentiometer and LED

Connect a potentiometer to analog in pin 0 of the
module, and an LED to digital pin 9:

%lframe alt='Arduino with potentiometer and LED' hspace=10 height=300%[[Attach:analog_in_lab_pot_and_led_bb.png|Attach:analog_in_lab_pot_and_led_bb.png]]
%lframe alt='Arduino with potentiometer and LED schematic' hspace=10 height=300%[[Attach:arduino_analog_input_schem.png|Attach:arduino_analog_input
_schem.png]]
to:
!!! Add a potentiometer

Connect a potentiometer to analog in pin 0 of the
module:

%lframe alt='Arduino with potentiometer and LED' hspace=10 height=300
%[[Attach:arduino_pot_bb.png|arduino_pot_bb.png]]
%
lframe alt='Arduino with potentiometer and LED schematic' hspace=10 height=300%[[arduino_pot_schem.png|arduino_pot_schem.png]]
Changed lines 41-71 from:
!!! 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 height=200%[[Attach:arduino_bb.png|Attach:arduino_bb.png]] | [-click the image to enlarge-]

!!! Add a potentiometer

Connect a potentiometer to analog in pin 0 of the module. You'll use this later to control the output, whether it's a motor or a light.
(:table:)
(:cell:)

%alt='Arduino with potentiometer schematic' height=300px%[[Attach:arduino_pot_schem.png|Attach:arduino_pot_schem.png]] | [-click the image to enlarge-]
(:cell:)


%alt='Arduino with potentiometer' height=200px %[[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]] | [-click the image to enlarge-]


(:tableend:)

!!! Connect a transistor to the microcontroller

The transistor allows you to control a circuit that's carrying higher current and voltage from the microcontroller.  It acts as an electronic switch.  The one you're using for this lab is an NPN-type transistor called a TIP120. The datasheet for it can be found [[http://www.onsemi.com/pub/Collateral/TIP120-D.PDF |here]]. It's designed for switching high-current loads. It has three connections, the base, the collector, and the emitter.  The base is connected to the microcontroller's output. The high-current load (i.e. the motor or light) is attached to its power source, and then to the collector of the transistor.  The emitter of the transistor is connected to ground.

http://itp.nyu.edu/physcomp/images/labs/tip120_pinout.png\\
Pinout of a TIP-120 transistor, from left to right: base, collector, emitter.

http://itp.nyu.edu/physcomp/images/labs/npntransistor.gif\\

Note: you can also use an IRF510 or IRF520 MOSFET transistor for this.  They have the same pin configuration as the TIP120, and perform similarly.  They can handle more amperage and voltage, but are more sensitive to static electricity damage.

to:

%lframe height=300 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_and_breadboard_bb.png|Attach:arduino_and_breadboard_bb.png]]
Added lines 44-68:
[--(Diagram made with [[http://fritzing.org | Fritzing]])--]


!!! Add a potentiometer and LED

Connect a potentiometer to analog in pin 0 of the module, and an LED to digital pin 9:

%lframe alt='Arduino with potentiometer and LED' hspace=10 height=300%[[Attach:analog_in_lab_pot_and_led_bb.png|Attach:analog_in_lab_pot_and_led_bb.png]]
%lframe alt='Arduino with potentiometer and LED schematic' hspace=10 height=300%[[Attach:arduino_analog_input_schem.png|Attach:arduino_analog_input_schem.png]]
[[<<]]
[--(Diagram made with [[http://fritzing.org | Fritzing]])--]


!!! Connect a transistor to the microcontroller

The transistor allows you to control a circuit that's carrying higher current and voltage from the microcontroller.  It acts as an electronic switch.  The one you're using for this lab is an NPN-type transistor called a TIP120. The datasheet for it can be found [[http://www.onsemi.com/pub/Collateral/TIP120-D.PDF |here]]. It's designed for switching high-current loads. It has three connections, the base, the collector, and the emitter.  The base is connected to the microcontroller's output. The high-current load (i.e. the motor or light) is attached to its power source, and then to the collector of the transistor.  The emitter of the transistor is connected to ground.

http://itp.nyu.edu/physcomp/images/labs/tip120_pinout.png\\
Pinout of a TIP-120 transistor, from left to right: base, collector, emitter.

http://itp.nyu.edu/physcomp/images/labs/npntransistor.gif\\

Note: you can also use an IRF510 or IRF520 MOSFET transistor for this.  They have the same pin configuration as the TIP120, and perform similarly.  They can handle more amperage and voltage, but are more sensitive to static electricity damage.

[[<<]]
Changed lines 18-20 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/electrolytic_cap.JPG | http://itp.nyu.edu/physcomp/images/labs/electrolytic_cap.JPG"electrolytic capacitor"]] | [-10uF electrolytic capacitor-]

to:
Deleted lines 20-21:
%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-]
Changed lines 48-49 from:
%alt='Arduino connected to a breadboard' align=top valign=center height=200%[[Attach:arduino_bb.png|Attach:arduino_bb.png]]
to:
%alt='Arduino connected to a breadboard' align=top valign=center height=200%[[Attach:arduino_bb.png|Attach:arduino_bb.png]] | [-click the image to enlarge-]
Changed line 97 from:
 [-click the image to enlarge-]
to:
[-click the image to enlarge-]
Changed lines 81-82 from:
%alt='Arduino with potentiometer and transistor' height=200%[[Attach:arduino_bb_pot_transistor.png|Attach:arduino_bb_pot_transistor.png]]
to:
%alt='Arduino with potentiometer and transistor' height=200%[[Attach:arduino_bb_pot_transistor.png|Attach:arduino_bb_pot_transistor.png]] | [-click the image to enlarge-]
Changed lines 88-89 from:
%alt='Arduino with potentiometer and transistor' height=200%[[Attach:arduino_bb_pot_transistor_motor2.png|Attach:arduino_bb_pot_transistor_motor2.png]]
to:
%alt='Arduino with potentiometer and transistor' height=200%[[Attach:arduino_bb_pot_transistor_motor2.png|Attach:arduino_bb_pot_transistor_motor2.png]] | [-click the image to enlarge-]
Added line 97:
 [-click the image to enlarge-]
Changed line 99 from:
%alt='Arduino with potentiometer and transistor' height=200%[[Attach:arduino_bb_pot_transistor_motor_diode.png|Attach:arduino_bb_pot_transistor_motor_diode.png]]
to:
%alt='Arduino with potentiometer and transistor' height=200%[[Attach:arduino_bb_pot_transistor_motor_diode.png|Attach:arduino_bb_pot_transistor_motor_diode.png]] | [-click the image to enlarge-]
Changed lines 102-104 from:
Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so:  %height=120 alt='diode and diode schematic%[[Attach:diode.png|Attach:diode.png]].

to:
Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so:  %height=120 alt='diode and diode schematic%[[Attach:diode.png|Attach:diode.png]] | [-click the image to enlarge-].

Changed lines 107-110 from:
!!!! Connect a lamp

Likewise,
the lamp circuit below assumes a 12V lamp.  Change your power supply accordingly if you're using a different lamp.  In the lamp circuit, the protection diode is not needed, since there's no way for the polarity to get reversed in this circuit:
to:
!!!! Connect a lamp instead

You could also attach a lamp using a transistor.  Like the motor
, the lamp circuit below assumes a 12V lamp.  Change your power supply accordingly if you're using a different lamp.  In the lamp circuit, the protection diode is not needed, since there's no way for the polarity to get reversed in this circuit:
Changed line 113 from:
%width=400px%[[Attach:arduino_transistor_lamp_schem.png|Attach:arduino_transistor_lamp_schem.png]]
to:
%width=400px%[[Attach:arduino_transistor_lamp_schem.png|Attach:arduino_transistor_lamp_schem.png]] | [-click the image to enlarge-]
Changed line 115 from:
%width=300px%[[Attach:arduino_transistor_lamp.png|Attach:arduino_transistor_lamp.png]]
to:
%width=300px%[[Attach:arduino_transistor_lamp.png|Attach:arduino_transistor_lamp.png]] | [-click the image to enlarge-]
Changed lines 59-60 from:
%alt='Arduino with potentiometer' height=200px %[[[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]] | [-click the image to enlarge-]
to:

%alt='Arduino with potentiometer' height=200px %[[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]] | [-click the image to enlarge-]

Changed line 56 from:
%alt='Arduino with potentiometer schematic' height=300px%[[Attach:arduino_pot_schem.png|Attach:arduino_pot_schem.png]]|[-click the image to enlarge-]
to:
%alt='Arduino with potentiometer schematic' height=300px%[[Attach:arduino_pot_schem.png|Attach:arduino_pot_schem.png]] | [-click the image to enlarge-]
Changed lines 59-60 from:
%alt='Arduino with potentiometer' height=200px %[[[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]]|[-click the image to enlarge-]
to:
%alt='Arduino with potentiometer' height=200px %[[[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]] | [-click the image to enlarge-]
Changed lines 58-60 from:
%alt='Arduino with potentiometer' height=200%[[[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]]|[-click the image to enlarge-]
to:

%alt='Arduino with potentiometer' height=200px %[[[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]]|[-click the image to enlarge-]
Changed line 58 from:
%alt='Arduino with potentiometer' height=200%[[[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]]
to:
%alt='Arduino with potentiometer' height=200%[[[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]]|[-click the image to enlarge-]
Changed line 56 from:
%alt='Arduino with potentiometer schematic' height=300px%[[Attach:arduino_pot_schem.png|Attach:arduino_pot_schem.png]]
to:
%alt='Arduino with potentiometer schematic' height=300px%[[Attach:arduino_pot_schem.png|Attach:arduino_pot_schem.png]]|[-click the image to enlarge-]
Changed line 58 from:
%alt='Arduino with potentiometer' height=200%[-click the image to enlarge-][[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]]
to:
%alt='Arduino with potentiometer' height=200%[[[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]]
Changed line 58 from:
%alt='Arduino with potentiometer' height=200%[[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]]
to:
%alt='Arduino with potentiometer' height=200%[-click the image to enlarge-][[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]]
Changed line 108 from:
%width=400px%[[arduino_transistor_lamp_schem.png|arduino_transistor_lamp_schem.png]]
to:
%width=400px%[[Attach:arduino_transistor_lamp_schem.png|Attach:arduino_transistor_lamp_schem.png]]
Changed line 108 from:
%width=400px%[[arduino_transisr_lamp.png]]
to:
%width=400px%[[arduino_transistor_lamp_schem.png|arduino_transistor_lamp_schem.png]]
Changed line 110 from:
%width=300px%[[arduino_transistor_lamp.png|arduino_transistor_lamp.png]]
to:
%width=300px%[[Attach:arduino_transistor_lamp.png|Attach:arduino_transistor_lamp.png]]
Changed line 108 from:
%width=400px%[[http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_lamp_schem.png|http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_lamp_schem.png]]
to:
%width=400px%[[arduino_transisr_lamp.png]]
Changed line 110 from:
%width=300px%[[http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_lamp.JPG|http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_lamp.JPG]]
to:
%width=300px%[[arduino_transistor_lamp.png|arduino_transistor_lamp.png]]
Changed lines 55-59 from:
<<<<<<<
%alt='Arduino with potentiometer schematic' height=300 %[[Attach:arduino_pot_schem.png|Attach:arduino_pot_schem.png]]
=======
%alt='Arduino with potentiometer schematic' height=300 %[[Attach:arduino_por_schem.png|Attach:arduino_por_schem.png]]
>>>>>>>
to:

%alt='Arduino with potentiometer schematic' height=300px%[[Attach:arduino_pot_schem.png|Attach:arduino_pot_schem.png]]
Added lines 55-57:
<<<<<<<
%alt='Arduino with potentiometer schematic' height=300 %[[Attach:arduino_pot_schem.png|Attach:arduino_pot_schem.png]]
=======
Added line 59:
>>>>>>>
Changed line 55 from:
%alt='Arduino with potentiometer schematic' height=200 %[[http://itp.nyu.edu/physcomp/images/labs/arduino_pot_schem.png|http://itp.nyu.edu/physcomp/images/labs/arduino_pot_schem.png]]
to:
%alt='Arduino with potentiometer schematic' height=300 %[[Attach:arduino_por_schem.png|Attach:arduino_por_schem.png]]
Changed line 89 from:
%height=200px alt='Arduino with TIP-120 Schematic'% [[Attach:motor_lab_schem.png|Attach:motor_lab_schem.png]]
to:
%height=300px alt='Arduino with TIP-120 Schematic'% [[Attach:motor_lab_schem.png|Attach:motor_lab_schem.png]]
Changed lines 90-91 from:
[-Note: the schematic symbol for the transistor here is actually for an IRF510 MOSFET.  But it can be replaced with a TIP120-]
to:
[-Note: the schematic symbol for the transistor here is actually\\
for an IRF510 MOSFET.  But it can be replaced with a TIP120-]
Changed line 89 from:
%width=400px alt='Arduino with TIP-120 Schematic'% [[Attach:motor_lab_schem.png|Attach:motor_lab_schem.png]]
to:
%height=200px alt='Arduino with TIP-120 Schematic'% [[Attach:motor_lab_schem.png|Attach:motor_lab_schem.png]]
Changed lines 89-90 from:
%width=400px alt='Arduino with TIP-120 Schematic'% http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_schem.png
to:
%width=400px alt='Arduino with TIP-120 Schematic'% [[Attach:motor_lab_schem.png|Attach:motor_lab_schem.png]]
[-Note: the schematic symbol for the transistor here is actually for an IRF510 MOSFET
.  But it can be replaced with a TIP120-]
Changed lines 94-95 from:
Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so:  %alt='diode and diode schematic height=200%[[Attach:diode.png|Attach:diode.png]].
to:
Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so:  %height=120 alt='diode and diode schematic%[[Attach:diode.png|Attach:diode.png]].

Changed line 156 from:
A motor controlled like this can only be turned in one direction. To be able to reverse the direction of the motor, an H-bridge circuit is required. For more on controlling DC motors with H-bridges, see the [[Labs/DCMotorControl |DC Motor Control lab]]
to:
A motor controlled like this can only be turned in one direction. To be able to reverse the direction of the motor, an H-bridge circuit is required. For more on controlling DC motors with H-bridges, see the [[Labs/DCMotorControl |DC Motor Control lab]]
Changed lines 94-95 from:
Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so:  [[Attach:diode.png|diode.png]].
to:
Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so:  %alt='diode and diode schematic height=200%[[Attach:diode.png|Attach:diode.png]].
Added lines 87-90:
(:table:)
(:cellnr:)
%width=400px alt='Arduino with TIP-120 Schematic'% http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_schem.png
(:cell:)
Deleted lines 91-99:


Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so:  [[http://itp.nyu.edu/physcomp/images/labs/diode.png|diagram]].

(:table:)
(:cellnr:)
%width=400px alt='Arduino with TIP-120 Schematic'% http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_schem.png
(:cell:)
%width=300px%[[http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_motor.JPG|http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_motor.JPG]]
Added lines 94-95:
Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so:  [[Attach:diode.png|diode.png]].
Changed lines 85-86 from:
In the motor circuit below, there is a diode in parallel with the collector and emitter of the transistor, pointing away from ground. This is there to protect the transistor should the polarity of the current reverse (for example, if the motor was turned in reverse, or when it releases back voltage). Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic ([[http://itp.nyu.edu/physcomp/images/labs/diode.png|diagram]]).
to:
FInally, add diode in parallel with the collector and emitter of the transistor, pointing away from ground. The diode to protects the transistor from back voltage generated when the motor shuts off, or if the motor is turned in the reverse direction.

%alt='Arduino with potentiometer and transistor' height=200%[[Attach:arduino_bb_pot_transistor_motor_diode
.png|Attach:arduino_bb_pot_transistor_motor_diode.png]]


Be
sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic, like so:  [[http://itp.nyu.edu/physcomp/images/labs/diode.png|diagram]].
Changed lines 80-82 from:
Attach a DC motor to the collector of the transistor.  Most motors will require more amperage than the microcontroller can supply, so you will need to add a separate power supply as well. If your motor runs on around 9V, you could use a 9V battery. A 5V motor might run on 4 AA batteries. a 12V battery may need a 12V wall wart, or a 12V battery.

to:
Attach a DC motor to the collector of the transistor.  Most motors will require more amperage than the microcontroller can supply, so you will need to add a separate power supply as well. If your motor runs on around 9V, you could use a 9V battery. A 5V motor might run on 4 AA batteries. a 12V battery may need a 12V wall wart, or a 12V battery. The ground of the motor power supply should connect to the ground of the microcontroller, on the breadboard.

Changed lines 78-79 from:
!!!! Connect a motor
to:
!!!! Connect a motor and power supply

Attach a DC motor to the collector of the transistor.  Most motors will require more amperage than the microcontroller can supply, so you will need to add a separate power supply as well. If your motor runs on around 9V, you could use a 9V battery. A 5V motor might run on 4 AA batteries. a 12V battery may need a 12V wall wart, or a 12V battery.


%alt='Arduino with potentiometer and transistor' height=200%[[Attach:arduino_bb_pot_transistor_motor2.png|Attach:arduino_bb_pot_transistor_motor2.png]]

Changed line 60 from:
!!! Connect a TIP120 transistor to the microcontroller
to:
!!! Connect a transistor to the microcontroller
Added lines 68-70:

Note: you can also use an IRF510 or IRF520 MOSFET transistor for this.  They have the same pin configuration as the TIP120, and perform similarly.  They can handle more amperage and voltage, but are more sensitive to static electricity damage.

Added lines 74-77:
Connect the base to an output pin of the microcontroller, and the emitter to ground like so:

%alt='Arduino with potentiometer and transistor' height=200%[[Attach:arduino_bb_pot_transistor.png|Attach:arduino_bb_pot_transistor.png]]

Changed line 57 from:
%alt='Arduino with potentiometer' height=200%[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]]
to:
%alt='Arduino with potentiometer' height=200%[[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]]
Changed lines 48-49 from:
%alt='Arduino connected to a breadboard' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/arduino_bboard_power.jpg
to:
%alt='Arduino connected to a breadboard' align=top valign=center height=200%[[Attach:arduino_bb.png|Attach:arduino_bb.png]]
Changed line 55 from:
%alt='Arduino with potentiometer schematic' height=300 %[[http://itp.nyu.edu/physcomp/images/labs/arduino_pot_schem.png|http://itp.nyu.edu/physcomp/images/labs/arduino_pot_schem.png]]
to:
%alt='Arduino with potentiometer schematic' height=200 %[[http://itp.nyu.edu/physcomp/images/labs/arduino_pot_schem.png|http://itp.nyu.edu/physcomp/images/labs/arduino_pot_schem.png]]
Changed line 57 from:
%alt='Arduino with potentiometer' height=300%http://itp.nyu.edu/physcomp/images/labs/bb_pot.jpg
to:
%alt='Arduino with potentiometer' height=200%[Attach:arduino_bb_pot.png|Attach:arduino_bb_pot.png]]
Changed line 122 from:
 const %color=#cc6600%int%% potValue = 0;        %color=#7e7e7e%// value returned from the potentiometer
to:
 %color=#cc6600%int%% potValue = 0;             %color=#7e7e7e%// value returned from the potentiometer
Changed lines 118-121 from:

int potPin = 0;          // Analog in 0 connected to the potentiometer
 int transistorPin
= 9;    // connected to the base of the transistor
 int potValue = 0;       
// value returned from the potentiometer
to:
(:div class=code :)
 
 const %color=#cc6600%int%% potPin = 0;         %color=#7e7e7e%// Analog in 0 connected to the potentiometer
 const %color=#cc6600%int%% transistorPin = 9; 
  %color=#7e7e7e%// connected to the base of the transistor
 const %color=#cc6600%int%% potValue = 0;        %color=#7e7e7e%
// value returned from the potentiometer
Changed lines 124-126 from:
 void setup() {
  // set  the transistor pin as output:
  pinMode(transistorPin, OUTPUT);
to:
 %color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
  %color=#7e7e7e%// set  the transistor pin as output:
  %color=#cc6600%pinMode%%(transistorPin, %color=#006699%OUTPUT%%);
Changed lines 129-133 from:
 void loop() {
  // read the potentiometer, convert it to 0 - 255:
  potValue = analogRead(potPin) / 4;
  // use that to control the transistor:
  analogWrite(9, potValue);
to:
 %color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
  %color=#7e7e7e%// read the potentiometer, convert it to 0 - 255:
  potValue = %color=#cc6600%analogRead%%(potPin) / 4;
  %color=#7e7e7e%// use that to control the transistor:
  %color=#cc6600%analogWrite%%(9, potValue);
Changed lines 135-137 from:
to:
 
(:divend:)

Changed lines 98-113 from:
[@
int transistorPin
= 9;   // connected to the base of the transistor

void setup() {
  // set 
the transistor pin as output:
  pinMode(transistorPin, OUTPUT);
}

void loop() {
  digitalWrite(transistorPin, HIGH);
  delay(1000);
  digitalWrite(transistorPin, LOW);
  delay
(1000);
}
@]
to:
(:div class=code :)
 
 const %color=#cc6600%int%% transistorPin = 9;    %color=#7e7e7e%// connected to the base of the transistor
 
 %color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
  %color=#7e7e7e%// set
  the transistor pin as output:
  %color=#cc6600%pinMode%%
(transistorPin, %color=#006699%OUTPUT%%);
 }
 
 %color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
  %color=#cc6600%digitalWrite%%(transistorPin, %color=#006699%HIGH%%);
  %color=#cc6600%delay%%(1000);
  %color=#cc6600%digitalWrite%%(transistorPin, %color=#006699%LOW%%);
  %color=#cc6600%delay%%(1000);
 }
 
 
(:divend:)

Deleted line 118:
[@
Changed lines 120-136 from:
int transistorPin = 9;    // connected to the base of the transistor
int potValue = 0;        // value returned from the potentiometer

void setup() {
  // set  the transistor pin as output:
  pinMode(transistorPin, OUTPUT);
}

void loop() {
  // read the potentiometer, convert it to 0 - 255:
  potValue = analogRead(potPin) / 4;
  // use that to control the transistor:
  analogWrite(9, potValue);
}

@]

to:
 int transistorPin = 9;    // connected to the base of the transistor
 int potValue = 0;        // value returned from the potentiometer
 
 void
setup() {
   // set  the transistor pin as output:
   pinMode(transistorPin, OUTPUT);
 }
 
 void
loop() {
   // read the potentiometer, convert it to 0 - 255:
   potValue = analogRead(potPin) / 4;
   // use that to control the transistor:
   analogWrite(9, potValue);
 }
Changed lines 73-74 from:
In the motor circuit below, there is a diode in parallel with the collector and emitter of the transistor, pointing away from ground. This is there to protect the transistor should the polarity of the current reverse (for example, if the motor was turned in reverse, or when it releases back voltage). Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic.
to:
In the motor circuit below, there is a diode in parallel with the collector and emitter of the transistor, pointing away from ground. This is there to protect the transistor should the polarity of the current reverse (for example, if the motor was turned in reverse, or when it releases back voltage). Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic ([[http://itp.nyu.edu/physcomp/images/labs/diode.png|diagram]]).
Changed lines 73-74 from:
In the motor circuit below, there is a diode in parallel with the collector and emitter of the transistor, pointing away from ground.  This is there to protect the transistor should the polarity of the current reverse (for example, if the motor was turned in reverse, or when it releases back voltage).
to:
In the motor circuit below, there is a diode in parallel with the collector and emitter of the transistor, pointing away from ground. This is there to protect the transistor should the polarity of the current reverse (for example, if the motor was turned in reverse, or when it releases back voltage). Be sure to add the diode to your circuit correctly. The silver band on the diode denotes the cathode which is the tip of the arrow in the schematic.
Changed lines 69-70 from:
The schematic symbol of an NPN transistor where B is the base, C is the collector, is the emitter.
to:
The schematic symbol of an NPN transistor where B is the base, C is the collector, and E is the emitter.
Changed lines 69-70 from:
The schematic symbol of an NPN transistor
to:
The schematic symbol of an NPN transistor where B is the base, C is the collector, is the emitter.
Changed lines 42-43 from:
 
to:
Added lines 64-70:
http://itp.nyu.edu/physcomp/images/labs/tip120_pinout.png\\
Pinout of a TIP-120 transistor, from left to right: base, collector, emitter.

http://itp.nyu.edu/physcomp/images/labs/npntransistor.gif\\
[[<<]]
The schematic symbol of an NPN transistor

Changed lines 1-2 from:
(:title Using a TIP-120 to control high current loads with an Arduino:)
to:
(:title Using a transistor to control high current loads with an Arduino:)
Added lines 1-2:
(:title Using a TIP-120 to control high current loads with an Arduino:)
Changed lines 127-129 from:
'''Note for the motor users:'''

A motor controlled like this can only be turned in one direction. To be able to reverse the direction of the motor, an H-bridge circuit is required. For more on controlling DC motors with H-bridges, see the [[Labs/DCMotorControl |DC Motor Control lab]]
to:
!!! Notes

'''For the motor users:'''\\
A motor controlled like this can only be turned in one direction. To be able to reverse the direction of the motor, an H-bridge circuit is required. For more on controlling DC motors with H-bridges, see the [[Labs/DCMotorControl |DC Motor Control lab]]
Added lines 1-2:
In this tutorial, you'll learn how to control a high-current DC load such as a DC motor or an incandescent light from a microcontroller. 
Deleted lines 4-5:
In this tutorial, you'll learn how to control a high-current DC load such as a DC motor or an incandescent light from a microcontroller. 
Added lines 7-8:
You will need the following parts for this tutorial.
Changed lines 1-2 from:
(:toc:)
to:
(:toc Table of Contents:)
Changed lines 5-6 from:
For this tutorial you'll need:
to:
!!! Parts
Added lines 1-2:
(:toc:)
Changed line 4 from:
 
to:
Changed line 78 from:
[[http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_lamp_schem.png|http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_lamp_schem.png]]
to:
%width=400px%[[http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_lamp_schem.png|http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_lamp_schem.png]]
Changed line 80 from:
[[http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_lamp.JPG|http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_lamp.JPG]]
to:
%width=300px%[[http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_lamp.JPG|http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_lamp.JPG]]
Changed line 78 from:
%height=300 alt='Arduino TIP120 schematic'%http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_lamp_schem.png
to:
[[http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_lamp_schem.png|http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_lamp_schem.png]]
Changed line 80 from:
%alt='Arduino TIP120 with lamp'%http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_lamp.JPG
to:
[[http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_lamp.JPG|http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_lamp.JPG]]
Deleted line 75:
Deleted lines 76-77:
(:cellnr colspan=2:)
%height=300 alt='Arduino TIP120 schematic'%http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_lamp_schem.png
Added lines 78-79:
%height=300 alt='Arduino TIP120 schematic'%http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_lamp_schem.png
(:cell:)
Deleted lines 80-81:
(:cell:)
%alt='Arduino TIP120 with lamp'%http://itp.nyu.edu/physcomp/images/labs/bboard_shield_tip120_lamp.JPG
Changed line 52 from:
%alt='Arduino with potentiometer'%http://itp.nyu.edu/physcomp/images/labs/bb_pot.jpg
to:
%alt='Arduino with potentiometer' height=300%http://itp.nyu.edu/physcomp/images/labs/bb_pot.jpg
Changed line 65 from:
%alt='Arduino with TIP-120 Schematic'% http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_schem.png
to:
%width=400px alt='Arduino with TIP-120 Schematic'% http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_schem.png
Changed line 67 from:
http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_motor.JPG
to:
%width=300px%[[http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_motor.JPG|http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_motor.JPG]]
Deleted lines 63-64:
(:cellnr colspan=2:)
%height=300 alt='Arduino TIP120 schematic'%http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_schem.png
Changed line 65 from:
%alt='Arduino TIP120 with motor'%http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_motor.JPG
to:
%alt='Arduino with TIP-120 Schematic'% http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_schem.png
Changed line 67 from:
%alt='Arduino TIP120 with motor'%http://itp.nyu.edu/physcomp/images/labs/bboard_shield_tip120_motor.JPG
to:
http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_motor.JPG
Deleted line 51:
Breadboard version:
Changed line 50 from:
%alt='Arduino with potentiometer schematic' height=300 %http://itp.nyu.edu/physcomp/images/labs/arduino_pot_schem.png
to:
%alt='Arduino with potentiometer schematic' height=300 %[[http://itp.nyu.edu/physcomp/images/labs/arduino_pot_schem.png|http://itp.nyu.edu/physcomp/images/labs/arduino_pot_schem.png]]
Changed line 49 from:
(:cellnr colspan=2:)
to:
(:cell:)
Changed line 51 from:
(:cellnr:)
to:
(:cell:)
Deleted lines 53-55:
(:cell:)
Breadboard shield version:
%alt='Arduino breadboard shield with potentiometer'%http://itp.nyu.edu/physcomp/images/labs/shield_pot.jpg
Deleted lines 44-47:
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

Added lines 86-88:

(:table:)
(:cellnr colspan=2:)
Changed lines 90-95 from:
to:
(:cellnr:)
%alt='Arduino TIP120 with lamp'%http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_lamp.JPG
(:cell:)
%alt='Arduino TIP120 with lamp'%http://itp.nyu.edu/physcomp/images/labs/bboard_shield_tip120_lamp.JPG
(:tableend:)

Changed line 35 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/lamp_socket.JPG | http://itp.nyu.edu/physcomp/images/labs/lamp_socket.JPG"Incandescent lamp and socket"]] | [-Incandescent lamp and socket-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/lamp_holder.JPG | http://itp.nyu.edu/physcomp/images/labs/lamp_holder.JPG"Incandescent lamp and socket"]] | [-Incandescent lamp and socket-]
Changed line 35 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/incandescent_lamp.JPG | http://itp.nyu.edu/physcomp/images/labs/incandescent_lamp.JPG"Incandescent lamp and socket"]] | [-Incandescent lamp and socket-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/lamp_socket.JPG | http://itp.nyu.edu/physcomp/images/labs/lamp_socket.JPG"Incandescent lamp and socket"]] | [-Incandescent lamp and socket-]
Changed lines 75-77 from:
%height=300 alt='Arduino TIP120 with motor'%http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_motor.JPG
(:cellnr:)
%height=300 alt='Arduino TIP120 with motor'%http://itp.nyu.edu/physcomp/images/labs/bboard_shield_tip120_motor.JPG
to:
%alt='Arduino TIP120 with motor'%http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_motor.JPG
(:cell:)
%alt='Arduino TIP120 with motor'%http://itp.nyu.edu/physcomp/images/labs/bboard_shield_tip120_motor.JPG
Added lines 71-72:
(:table:)
(:cellnr colspan=2:)
Changed lines 74-79 from:
to:
(:cellnr:)
%height=300 alt='Arduino TIP120 with motor'%http://itp.nyu.edu/physcomp/images/labs/bboard_tip120_motor.JPG
(:cellnr:)
%height=300 alt='Arduino TIP120 with motor'%http://itp.nyu.edu/physcomp/images/labs/bboard_shield_tip120_motor.JPG
(:tableend:)

Changed lines 124-127 from:

!!! Get creative

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:
Changed lines 85-97 from:
to:
int transistorPin = 9;    // connected to the base of the transistor

void setup() {
  // set  the transistor pin as output:
  pinMode(transistorPin, OUTPUT);
}

void loop() {
  digitalWrite(transistorPin, HIGH);
  delay(1000);
  digitalWrite(transistorPin, LOW);
  delay(1000);
}
Changed lines 103-118 from:
to:
int potPin = 0;          // Analog in 0 connected to the potentiometer
int transistorPin = 9;    // connected to the base of the transistor
int potValue = 0;        // value returned from the potentiometer

void setup() {
  // set  the transistor pin as output:
  pinMode(transistorPin, OUTPUT);
}

void loop() {
  // read the potentiometer, convert it to 0 - 255:
  potValue = analogRead(potPin) / 4;
  // use that to control the transistor:
  analogWrite(9, potValue);
}

Added lines 67-68:
!!!! Connect a motor
Added lines 75-76:
!!!! Connect a lamp
Changed lines 81-94 from:

The simplest program for this would be as follows:

Sub main()
call delay(0.5)  ' start  program with a half-second delay

do
call putPin(13, getPin(14))
loop
end sub

If your power supply for
the BX24 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 BX24 need a common ground (in our case, they get it through the transistor's base; see above schematic).
to:
!!! Program the microcontroller

Here's a quick program to test the circuit:
[@

@]

Now that you see it working, try changing the speed of the motor or the intensity of
the lamp using the potentiometer. Try this code:

[@

@]

'''Note for
the motor users:'''

A motor controlled like this can only be turned in one direction. To be able to reverse the direction of the motor, an H-bridge circuit is required. For more on controlling DC motors with H-bridges, see
the [[Labs/DCMotorControl |DC Motor Control lab]]
Changed lines 98-103 from:
Step 4 (optional step):

A motor controlled like this can only be turned in one direction. To be able to reverse the direction of the motor, an H-bridge circuit is required. For more on controlling DC motors with H-bridges, see the notes on DC motor control. Then get an H-bridge such as the Texas Instruments SN754410, or make your own. Use it to control the direction of a motor.

Step 5:

to:
!!! Get creative
Added lines 27-28:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/tip120_transistor.JPG | http://itp.nyu.edu/physcomp/images/labs/tip120_transistor.JPG"TIP120 transistor"]] | [-TIP120 transistor-]
Changed lines 63-64 from:
The transistor allows you to control a circuit that's carrying higher current and voltage from the microcontroller.  It acts as an electronic switch.  The one you're using for this lab is an NPN-type transistor called a TIP120. It's designed for switching high-current loads. It has three connections, the base, the collector, and the emitter.  The base is connected to the microcontroller's output. The high-current load (i.e. the motor or light) is attached to its power source, and then to the collector of the transistor.  The emitter of the transistor is connected to ground.
to:
The transistor allows you to control a circuit that's carrying higher current and voltage from the microcontroller.  It acts as an electronic switch.  The one you're using for this lab is an NPN-type transistor called a TIP120. The datasheet for it can be found [[http://www.onsemi.com/pub/Collateral/TIP120-D.PDF |here]]. It's designed for switching high-current loads. It has three connections, the base, the collector, and the emitter.  The base is connected to the microcontroller's output. The high-current load (i.e. the motor or light) is attached to its power source, and then to the collector of the transistor.  The emitter of the transistor is connected to ground.
Changed lines 69-75 from:
to:
This circuit assumes you're using a 12V motor.  If your motor requires a different voltage, make sure to use a power supply that's appropriate.  Connect the ground of the motor's supply to the ground of your microcontroller circuit, though, or the circuit won't work properly.

Likewise, the lamp circuit below assumes a 12V lamp.  Change your power supply accordingly if you're using a different lamp.  In the lamp circuit, the protection diode is not needed, since there's no way for the polarity to get reversed in this circuit:

%height=300 alt='Arduino TIP120 schematic'%http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_lamp_schem.png

Changed lines 67-71 from:
%alt='Arduino TIP120 schematic'%http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_schem.png


The simplest program fot this would be as follows:
to:
%height=300 alt='Arduino TIP120 schematic'%http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_schem.png


The simplest program for this would be as follows:
Changed lines 67-69 from:
%alt='Arduino TIP120 schematic'%http://itp.nyu.edu/physcomp/images/labs/arduino_TIP120_schem.jpg

to:
%alt='Arduino TIP120 schematic'%http://itp.nyu.edu/physcomp/images/labs/arduino_tip120_schem.png

Changed line 61 from:
Connect a TIP120 transistor to the microcontroller
to:
!!! Connect a TIP120 transistor to the microcontroller
Changed lines 63-74 from:


Note the second power supply. Most motors take a great deal more
current than a microprocessor, and need their own supply. The example below uses a 9V battery as a separate power source. Whatever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!).

Connect a switch to another pin of the BX-24 and program it to control the
motor, like so:

Detail of the board:

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:
to:
The transistor allows you to control a circuit that's carrying higher current and voltage from the microcontroller.  It acts as an electronic switch.  The one you're using for this lab is an NPN-type transistor called a TIP120. It's designed for switching high-current loads. It has three connections, the base, the collector, and the emitter.  The base is connected to the microcontroller's output. The high-current load (i.e. the motor or light) is attached to its power source, and then to the collector of the transistor.  The emitter of the transistor is connected to ground.

In the motor circuit below, there is a diode in parallel with
the collector and emitter of the transistor, pointing away from ground.  This is there to protect the transistor should the polarity of the current reverse (for example, if the motor was turned in reverse, or when it releases back voltage).

%alt='Arduino TIP120 schematic'%http
://itp.nyu.edu/physcomp/images/labs/arduino_TIP120_schem.jpg

Changed line 52 from:
%alt='Arduino with potentiometer schematic' height=300 %http://itp.nyu.edu/physcomp/images/labs/arduino_analog_pot_schem.png
to:
%alt='Arduino with potentiometer schematic' height=300 %http://itp.nyu.edu/physcomp/images/labs/arduino_pot_schem.png
Changed line 52 from:
%alt='Arduino with potentiometer and LED schematic' height=300 %http://itp.nyu.edu/physcomp/images/labs/arduino_analog_input_schem.png
to:
%alt='Arduino with potentiometer schematic' height=300 %http://itp.nyu.edu/physcomp/images/labs/arduino_analog_pot_schem.png
Changed line 55 from:
%alt='Arduino with potentiometer and LED'%http://itp.nyu.edu/physcomp/images/labs/bb_pot.jpg
to:
%alt='Arduino with potentiometer'%http://itp.nyu.edu/physcomp/images/labs/bb_pot.jpg
Changed line 58 from:
%alt='Arduino breadboard shield with potentiometer and LED'%http://itp.nyu.edu/physcomp/images/labs/shield_pot.jpg
to:
%alt='Arduino breadboard shield with potentiometer'%http://itp.nyu.edu/physcomp/images/labs/shield_pot.jpg
Changed lines 13-14 from:
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/electrolytic_cap.JPG | http://itp.nyu.edu/physcomp/images/labs/electrolytic_cap.JPG"electrolytic capacitor"]] | [-10uF electrolytic capacitor-]
Deleted lines 24-25:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/electrolytic_cap.JPG | http://itp.nyu.edu/physcomp/images/labs/electrolytic_cap.JPG"electrolytic capacitor"]] | [-10uF electrolytic capacitor-]
Changed lines 21-22 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/1N4004_diodes.JPG | http://itp.nyu.edu/physcomp/images/labs/1N4004_diodes.JPG"Power diodes"]] | [-power diodes (for DC Motor version only)-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/1N4004_diodes.JPG | http://itp.nyu.edu/physcomp/images/labs/1N4004_diodes.JPG"Power diodes"]] | [-power diodes \\
(for DC Motor version only)-]
Added lines 28-29:
[[<<]]
Added lines 20-24:
 
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/1N4004_diodes.JPG | http://itp.nyu.edu/physcomp/images/labs/1N4004_diodes.JPG"Power diodes"]] | [-power diodes (for DC Motor version only)-]

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/electrolytic_cap.JPG | http://itp.nyu.edu/physcomp/images/labs/electrolytic_cap.JPG"electrolytic capacitor"]] | [-10uF electrolytic capacitor-]

Deleted lines 31-36:
 
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/1N4004_diodes.JPG | http://itp.nyu.edu/physcomp/images/labs/1N4004_diodes.JPG"Power diodes"]] | [-power diodes-]

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/electrolytic_cap.JPG | http://itp.nyu.edu/physcomp/images/labs/electrolytic_cap.JPG"electrolytic capacitor"]] | [-10uF electrolytic capacitor-]

  * 10Kohm resistors
Added line 33:
Changed line 1 from:
In this tutorial, you'll learn how to control a high-current DC load such as a DC motor or an incandescent light from a microcontroller.
to:
In this tutorial, you'll learn how to control a high-current DC load such as a DC motor or an incandescent light from a microcontroller. 
Changed lines 24-27 from:
   * 1N4004 diodes
    * TIP120 transistor
    * 10uF capacitor
    * 10Kohm resistors
to:
- or -

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/incandescent_lamp.JPG | http://itp.nyu.edu/physcomp/images/labs/incandescent_lamp.JPG"Incandescent lamp and socket"]] | [-Incandescent lamp and socket-]
 
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/1N4004_diodes.JPG | http://itp.nyu.edu/physcomp/images/labs/1N4004_diodes.JPG"Power diodes"]] | [-power diodes-]

%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/electrolytic_cap.JPG | http://itp.nyu.edu/physcomp/images/labs/electrolytic_cap.JPG"electrolytic capacitor"]] | [-10uF electrolytic capacitor-]

  * 10Kohm resistors
Changed lines 45-48 from:
!!! Add a Digital Input (a switch)

Connect a switch to digital input 2 on the Arduino.

to:
!!! Add a potentiometer

Connect a potentiometer to analog in pin 0 of the module. You'll use this later to control the output, whether it's a motor or a light.
Changed line 50 from:
%alt='Arduino digital in schematic' height=300%http://itp.nyu.edu/physcomp/images/labs/arduino_dig_input_schem.png
to:
%alt='Arduino with potentiometer and LED schematic' height=300 %http://itp.nyu.edu/physcomp/images/labs/arduino_analog_input_schem.png
Changed lines 52-53 from:
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch.jpg\\
Breadboard version
to:
Breadboard version:
%alt='Arduino with potentiometer and LED'%http://itp.nyu.edu/physcomp/images/labs/bb_pot.jpg
Changed lines 55-56 from:
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_shield_switch.jpg\\
Shield version
to:
Breadboard shield version:
%alt='Arduino breadboard shield with potentiometer and LED
'%http://itp.nyu.edu/physcomp/images/labs/shield_pot.jpg
Changed lines 59-61 from:
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.
to:
Connect a TIP120 transistor to the microcontroller
Changed lines 61-64 from:
Step 2:

Connect the base of a TIP120 transistor to one pin of your BX-24. Connect the motor to the transistor as follows:

to:

Added lines 18-19:
%lframe width=90px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/potentiometer.jpg | http://itp.nyu.edu/physcomp/images/labs/potentiometer.jpg"potentiometer"]] | [-10Kohm potentiometer-]
Deleted lines 21-22:
%lframe width=90px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/potentiometer.jpg | http://itp.nyu.edu/physcomp/images/labs/potentiometer.jpg"potentiometer"]] | [-10Kohm potentiometer-]
Added lines 20-21:
%lframe width=90px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/potentiometer.jpg | http://itp.nyu.edu/physcomp/images/labs/potentiometer.jpg"potentiometer"]] | [-10Kohm potentiometer-]
Deleted lines 17-20:
%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/L293_h-bridge.JPG | http://itp.nyu.edu/physcomp/images/labs/L293_h-bridge.JPG"L293 H-bridge"]] | [-L293 H-bridge-]

Changed lines 1-14 from:
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
 
  * BX-24
   * Serial cable
   * DB9 female serial connector & headers
    * LED's
 
  * Switch
 
  * 1Kohm resistors
    * 1N4004 diodes
to:
In this tutorial, you'll learn how to control a high-current DC load such as a DC motor or an incandescent light from a microcontroller.
 
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"]] | [-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"switch"]] | [-switch-]

%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_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-]

  * 1N4004 diodes
Changed lines 28-31 from:
   * DC motor
    * power supply for DC motor
    * 10uF capacitor (optional)
    * 1uF capacitor (optional)
to:
   * 10uF capacitor
Changed lines 30-31 from:
   * 220 ohm resistors
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.

(: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:)

Added lines 1-61:
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
    * BX-24
    * Serial cable
    * DB9 female serial connector & headers
    * LED's
    * Switch
    * 1Kohm resistors
    * 1N4004 diodes
    * TIP120 transistor
    * DC motor
    * power supply for DC motor
    * 10uF capacitor (optional)
    * 1uF capacitor (optional)
    * 10Kohm resistors
    * 220 ohm resistors

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 base of a TIP120 transistor to one pin of your BX-24. Connect the motor to the transistor as follows:

Note the second power supply. Most motors take a great deal more current than a microprocessor, and need their own supply. The example below uses a 9V battery as a separate power source. Whatever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!).

Connect a switch to another pin of the BX-24 and program it to control the motor, like so:

Detail of the board:

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:

The simplest program fot this would be as follows:

Sub main()
call delay(0.5)  ' start  program with a half-second delay

do
call putPin(13, getPin(14))
loop
end sub

If your power supply for the BX24 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 BX24 need a common ground (in our case, they get it through the transistor's base; see above schematic).

Step 4 (optional step):

A motor controlled like this can only be turned in one direction. To be able to reverse the direction of the motor, an H-bridge circuit is required. For more on controlling DC motors with H-bridges, see the notes on DC motor control. Then get an H-bridge such as the Texas Instruments SN754410, or make your own. Use it to control the direction of a motor.

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 21, 2013, at 08:45 AM