DC Motors are widely used in embedded systems. This tutorial explains driving a DC motor using ARM-7 Architecture based LPC2148 Microcontroller.
DC motors are available in different ratings. Selection of a motor depends on the application for which the motor is used. In this example we are using a 12-V DC motor. The current required ton drive the motor is provided by a motor driving IC: L293D. This IC is designed to provide up to 600 mA current at 4.5 V- 36 V range.
1 (EN 1,2)
Enable (Active high) channel 1 and 2
2, 7, 10, 15
3, 6, 11, 14
9 (EN 3, 4)
Enable (Active High) channel 3 and 4
4.5 - 36 V
5 v power supply pin for internal logic of the IC
A single L293D IC can drive two DC motors. In this example we are only controlling the motor which is connected to OUT1 and OUT2 pins of L293D.
A switch is also connected to P0.26 to turn on and turn off the motor. The system will turn off the motor when the switch is pressed.
a=IO0PIN & (1<<26);
if(a==0) /* The switch is open */
else /* The switch is pressed */