The given project demonstrates above example. It applies PWM to DC motor to vary its speed from min to max and max to min continuously and also measures following parameters.
1) PWM width in %
2) Applied voltage to motor
It uses arduino UNO board to generate PWM and measure/calculate above 3 parameters. These parameters are displayed on 16×4 LCD. It is very easy to vary the speed of DC motor using arduino. Arduino can generate PWM on its analog output pin and when it is applied to DC motor, its speed varies. So it is very simple and easy task. To measure RPM, opto-interrupt sensor MOC7811 is used. When motor completes 1 revolution, the sensor generates 1 pulse and such pulses are calculated by arduino to calculate RPM. So let us see how this is done. Let’s start with circuit diagram first, followed by its descriptions and operation.
CIRCUIT DESCRIPTION
As shown in the figure, the circuit is built using arduino UNO development board, 16×4 LCD, NPN Darlington transistor TIP122 and opto interrupt sensor MOC7811.
• The analog output pin 9 of arduino drives 12V@2000 RPM DC motor through TIP122. This pin is given to the base input of TIP122 through current limiting resistor R2 and DC motor is connected to the collector of TIP122.
• The internal IR LED of MOC7811 is given forward bias using 5V supply from the arduino board through current limiting resistor R1. Internal photo transistor is pulled up by resistor R4. The collector output of the transistor is connected to digital pin 7 or arduino.
• LCD data pins D4 to D7 are connected to digital pins 5, 4, 3 and 2 of arduino while control pins Rs and En are connected to 12 and 11. RW pin is connected to ground. Vcc pin and LED+ pin are connected to 5 V supply from arduino board and Vss pin and LED- pins are connected to arduino board ground.
• One pot is connected to Vee pin to vary contras of LCD.
Here is the snap of arrangement.
Fig. 1: Prototype of Arduino based DC Motor Speed Controller
CIRCUIT OPERATION
• First, the motor is given 12 V supply through an external power supply. Next, the arduino board, LCD, and the sensor are given supply through USB from PC / laptop.
• Initially, the LCD shows different parameters as “PWM ip: PWM Duty: PWM volt: speed:”
• Then arduino starts applying PWM to motor with maximum pulse width.
• So motor will start rotating at maximum speed. Sometimes a delay is provided to allow the motor to attain full speed.
• As the motor starts rotating, the slotted wheel attached to its shaft will also rotate.
• The MOC7811 sensor is placed such a way that the slot of wheel passes through sensor air gap. Thus when the motor rotates one full revolution, the slot passes through sensor gap. Due to the slot in the wheel, the IR light falls on phototransistor. So transistor conducts and generates a negative pulse in collector output. Thus each rotation of motor produces a pulse.
• The frequency of these pulses is actually RPS (- revolution per second) of the motor. To measure the frequency of this pulse first the ON time is measured then OFF time is measured and from this frequency is calculated as -:
Time period = Ton + Toff (in us)
Frequency = 1000000/time period
• This frequency is the speed of the motor in RPS. From this RPS, the speed of the motor is calculated in RPM as -:
RPM = 60×RPS
• The PWM input is varied from 250 to 100 in step of 15. That is directly displayed on LCD.
• The ON time and OFF time of PWM output are also measured to calculate the PWM duty cycle as -:
PWM duty = [PWM_Ton / (PWM_Ton + PWM_Toff)] × 100
• Finally, voltage applied to the motor is calculate as -:
Voltage applied to motor = motor voltage × duty
= (12/100) × duty
• First, the PWM input is decreased from 250 to 100 in 10 steps of 15 and then again it is increased from 100 to 250 and this cycle is repeated continuously.
• So motor speed continuously decreases and then continuously increases. We can observe the change in motor speed that is displayed on LCD as speed in RPM.
Thus the given project varies the speed of DC motor and also measures it accurately. It displays % of pulse width applied to motor along with applied voltage. So one can note down motor speed in RPM at different voltage and pulse width in observation table for further needs.
Project Source Code
###
#include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); #define pwm_ip 8 #define rps_ip 7 int ontime,offtime,duty,pw=255,rps,rpm; float volt,period; long int rps_Ton,rps_Toff,rps_time; void setup() { pinMode(pwm_ip,INPUT); pinMode(rps_ip,INPUT); lcd.begin(16, 4); lcd.clear(); lcd.print("PWM_ip:255"); lcd.setCursor(0,1); lcd.print("PWM_duty:100%"); lcd.setCursor(0,2); lcd.print("PWM_volt:12.00"); lcd.setCursor(0,3); lcd.print("speed:"); } void loop() { for(pw=250;pw>100;pw-=15) // decrease the pulse width by 2% { analogWrite(9,pw); // generate PWM delay(7000); // apply delay for motor to attain full speed ontime = pulseIn(pwm_ip,HIGH); // measure ON time of PWM offtime = pulseIn(pwm_ip,LOW); // measure OFF time of PWM period = ontime+offtime; // calculate total PWM time duty = (ontime/period)*100; // calculate % pulse width volt = 0.12*duty; // calculate applied motor voltage rps_Ton = pulseIn(rps_ip,HIGH); // calculate ON time of RPS pulse input rps_Toff = pulseIn(rps_ip,LOW); // calculate OFF time or RPS pulse rps_time = rps_Ton+rps_Toff; // calculate total time rps = 1000000/rps_time; // calculate frequency that is RPS rpm = 60*rps; // calculate RPM from RPS lcd.setCursor(7,0); // display all the values lcd.print(pw); lcd.setCursor(9,1); lcd.print(duty); lcd.print('%'); lcd.setCursor(9,2); lcd.print(volt); lcd.print('v'); lcd.setCursor(6,3); lcd.print(rpm); lcd.print(" RPM"); } for(pw=100;pw<250;pw+=15) // increase the pulse width and { analogWrite(9,pw); // do same as above delay(7000); ontime = pulseIn(pulse_ip,HIGH); offtime = pulseIn(pulse_ip,LOW); period = ontime+offtime; duty = (ontime/period)*100; volt = 0.12*duty; rps_Ton = pulseIn(rps_ip,HIGH); rps_Toff = pulseIn(rps_ip,LOW); rps_time = rps_Ton+rps_Toff; rps = 1000000/rps_time; rpm = 60*rps; lcd.setCursor(7,0); lcd.print(pw); lcd.setCursor(9,1); lcd.print(duty); lcd.print('%'); lcd.setCursor(9,2); lcd.print(volt); lcd.print('v'); lcd.setCursor(6,3); lcd.print(rpm); lcd.print(" RPM"); } }###
Circuit Diagrams
Project Video
Filed Under: Electronic Projects
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.