PWM Control Using Arduino Learn To Control DC Motor Speed and LED Brightness
PWM Control Using Arduino Learn To Control DC Motor Speed and LED Brightness
Control signal is
what we give to the PWM controller as the input. It might be an analog or digital signal according to
the design of the PWM controller. The control signal contains information on how much power has
to be applied to the load. The PWM controller accepts the control signal and adjusts the duty cycle of
the PWM signal according to the requirements. PWM waves with various duty cycle are shown in
the figure below.
In the above wave forms you can see that the frequency is same but ON time and OFF time are
different.Two applications of PWM control using arduino is shown here. Controlling the LED
brightness using arduino and motor speed control using arduino.
LED brightness control using arduino.
This one could be the simplest example of PWM control using arduino. Here the brightness of an
LED can be controlled using a potentiometer. The circuit diagram is shown below.
In the circuit
diagram, slider of the potentiometer is connected to analog input pin A0 of arduino. Resistor R1
limits the base current of the transistor Q1. Motor is connected as collector load to the transistor.
Capacitor C1 by-passes voltage spikes and noises produced by the motor. This filter capacitor is very
essential and if it is not there the circuit may not work properly.
Program.
int pwm = 12; // assigns pin 12 to variable pwm
int pot = A0; // assigns analog input A0 to variable pot
int t1 = 0; // declares variable t1
int t2 = 0; // declares variable t2
void setup() // setup loop
{
pinMode(pwm, OUTPUT); // declares pin 12 as output
pinMode(pot, INPUT); // declares pin A0 as input
}
void loop()
{
t2= analogRead(pot); // reads the voltage at A0 and saves in t2
t1= 1000-t2; // subtracts t2 from 1000 ans saves the result in t1
digitalWrite(pwm, HIGH); // sets pin 12 HIGH
delayMicroseconds(t1); // waits for t1 uS (high time)
digitalWrite(pwm, LOW); // sets pin 12 LOW
delayMicroseconds(t2); // waits for t2 uS (low time)
}
Notes.
In both circuits shown above the arduino is supposed to be powered through the 9V external
power input jack.
+5V supply for the potentiometer can be taken from the 5V regulator output on the arduino
board.
The DC motor I used while testing was rated 9V/100mA.
The LED I used while testing was a general purpose 4mm bright green LED.
The maximum collector current 2N2222 can handle is 800mA. Keep this in mind while selecting
the motor.
Be very careful while handling the arduino board. Any wrong connections might damage the
board
Source : http://www.circuitstoday.com/pwm-generation-and-control-using-
arduino