Hardware Reference
In-Depth Information
Solution
Use an H-bridge to switch the terminals on the motor so that it will run both backward and
forward. We'll use the L293D : a common, single-chip H-bridge.
Here's what you will need:
▪ 3 V to 5 V motor (see “Miscellaneous” )
▪ Breadboard and jumper wires (see “Prototyping Equipment” )
▪ L293D H-Bridge IC (see “Integrated Circuits” )
▪ Power supply for the motor (optional)
Lay out your breadboard as shown in Figure 4-4 . Ensure that the L293D is positioned cor-
rectly. There is a notch on one end that should be pointed up.
Figure 4-4. Driving a DC motor with an H-bridge
The code in Example 4-3 ( h-bridgeMotor.js ) looks much like the code for driving the DC
motor with a transistor ( Example 4-2 ) . The additional code specifies which direction to
spin the motor.
Example 4-3. Code for driving a DC motor with an H-bridge (h-bridgeMotor.js)
#!/usr/bin/env node
// This example uses an H-bridge to drive a DC motor in two directions
var b = require ( 'bonescript' );
Search WWH ::




Custom Search