Hardware Reference
In-Depth Information
Using Arduino code to control the direction of the
DC motor
Open the Arduino IDE and type in the following code:
This code sets up the three pins 3, 4, and 9 to enable the chip and control the direction of
the motor. As you did earlier, you can navigate to Tools | Serial Monitor to send data to
the program. Sending a value of 0 sets pin 3 to HIGH and pin 4 to LOW, causing the motor
to spin in one direction. Sending a value of 1 sets pin 3 to LOW and pin 4 to HIGH, caus-
ing the motor to spin in the other direction.
Now, you know how to build circuits to control both the speed and the direction of DC mo-
tors. However, instead of procuring all the parts and building the circuits yourself, you can
buy a DC motor control shield.
Search WWH ::




Custom Search