DC motors, which you can find in numerous devices around your home, rotate continuously when a DC voltage is applied across them. Such motors are commonly found as the driving motors in radio control (RC) cars, and as the motors that make the discs spin in your DVD player. DC motors are great because they come in a huge array of sizes and are generally very cheap. By adjusting the voltage you apply to them, you can change their rotation speed. By reversing the direction of the voltage applied to them, you can change their direction of rotation as well. This is generally done using an H-bridge,Brushed DC motors,employ stationary magnets and a spinning coil. Electricity is transferred to the coil using “brushes,” hence the reason they are called brushed DC motors. Unlike
brushless DC motors (such as stepper motors), brushed DC motors are cheap and have easier speed control. However, brushed DC motors do not last as long because the brushes can wear out over time. These motors work through an inductive force. When current passes through the spinning coil, it generates a magnetic field that is either attracted to or repelled by the stationary magnets depending on the polarity. By using the brushes to swap the polarity each half rotation, you can generate angular momentum. The exact same configuration can be used to create a generator if you manually turn the armature. This will generate a fluctuating magnetic field that will, in turn, generate current. This is
how hydroelectric generators work—falling water turns the shaft, and a current is produced. This capability to create current in the opposite direction is why we will use a diode to ensure that the motor cannot send current back into your circuit when it is forcibly turned.
Handling High-Current Inductive Loads
DC motors generally require more current than the Arduino’s built-in power supply can provide, and they can create harmful voltage spikes due to their inductive nature. To address this issue, you first learn how to effectively isolate a DC motor from your Arduino, and then how to power it using a secondary supply. A transistor will allow the Arduino to switch the motor on and off safely, as well
as to control the speed using the pulse-width modulation (PWM).
Before you hook up your DC motor, it’s important to understand what all
these components are doing:
■Q1 is an NPN bipolar-junction transistor (BJT) used for switching the separate 9V supply to the motor. There are two types of BJTs, NPN and PNP, which refer to the different semiconductor “doping” techniques used to create the transistor.You can simplistically think of an NPN transistor as a voltage-controlled switch that allows you to inhibit or allow current flow.
■A 1kΩ resistor is used to separate the transistor’s base pin from the control
pin of the Arduino.
■U1 is the DC motor.
■C1 is for filtering noise caused by the motor.
■D1 is a diode used to protect the power supply from reverse voltage
caused by the motor acting like an inductor.
Controlling Motor Speed with PWM
//Simple Motor Speed Control Program
const int MOTOR=9; //Motor on Digital Pin 9
void setup()
{
pinMode (MOTOR, OUTPUT);
}
void loop()
{
for (int i=0; i<256; i++)
{
analogWrite(MOTOR, i);
delay(10);
}
delay(2000);
for (int i=255; i>=0; i--)
{
analogWrite(MOTOR, i);
delay(10);
}
delay(2000);
}
No comments:
Post a Comment