Page 188 - Making things move_ DIY mechanisms for inventors, hobbyists, and artists
P. 188
166 Making Things Move
FIGURE 6-31 The Arduino setup to drive a motor through a transistor
7. Open the Arduino application on your computer and start a new sketch. Type
in the following code, verify it, and then upload it to the Arduino.
/*
Using Arduino to turn on a motor with input from a switch
Created June 2010
By Stina Marie Hasse Jorgensen, Sam Galison, and Dustyn Roberts
Adapted from code at
http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads
*/
const int transistorPin = 9; // connected to base of transistor
const int switchPin = 2; // connected to switch
void setup()
{
pinMode(switchPin, INPUT); // set the switch pin as input:
pinMode(transistorPin, OUTPUT); // set the transistor pin as output:
}