Arduino RPM Counter & DC Motor Constant Speed Controller- In this tutorial, you will learn how to make an RPM counter and how to automatically adjust the speed of a DC motor. In this project, the IR Sensor will be used with the Arduino Uno for the RPM measurement and a Potentiometer/Variable resistor will be used to set the RPM value. The real-time RPM value will be compared with the preset RPM value and then the Arduino will increase or decrease the speed of the DC motor automatically.
In this tutorial, we will cover,
- The components and tools you will need for this project.
- What is an RPM Counter?
- Why we need DC Motor Constant Speed Controller?
- Complete Circuit Diagram Explanation.
- Proteus Simulation of the RPM Counter & DC Motor Constant Speed Controller.
- Program explanation and finally
- Practical Demonstration of the RPM counter and DC Motor Constant Speed Controller.
Without any further delay, let’s get started!!!
The components and tools used in this project can be purchased from Amazon, the components Purchase links are given below:
Computer CPU DC Fan: https://amzn.to/2pqiqgG
IR infrared Sensor best package: https://amzn.to/2KI2z8G
TIP122 NPN Transistor best package: https://amzn.to/2KZKD8n
Arduino Uno: https://amzn.to/2tVz1vu
Mega 2560: https://amzn.to/2ze1kdu
LM7805 Voltage Regulator: https://amzn.to/2IZEl5x
330 ohm resistors pack: https://amzn.to/2NtlAeh
5v 2A adaptor: https://amzn.to/2GsNfcw
2n2222 npn transistors: https://amzn.to/2EmXsIb
10k Resistor: https://amzn.to/2KTd6OW
lm7805 Voltage Regulator: https://amzn.to/2IZEl5x
330-ohm resistors pack: https://amzn.to/2NtlAeh
LDR pack: https://amzn.to/2m2khGR
female DC power jack socket: https://amzn.to/2KEo1gt
470 uf capacitors: https://amzn.to/2xDCOzf
5×7 cm vero board: https://amzn.to/2OHGbvn
female headers: https://amzn.to/2zqmtiJ
connection wires: https://amzn.to/2DpBuW7
Super Starter kit for Beginners: https://amzn.to/2KJvmKG
Jumper Wires: https://amzn.to/2KMoVXs
Bread Board: https://amzn.to/2MS4q8X
12v Adaptor: https://amzn.to/2Ntr6h1
PCB plate: https://amzn.to/2IUwpCt
Variable Supply: https://amzn.to/2MT4Qfj
Digital Multimeter: https://amzn.to/2Nvft9i
Vero Board / strip board: https://amzn.to/2MTf9jD
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2zfoNuJ
Solder wire: https://amzn.to/2ufUMWf
Wire Stripper: https://amzn.to/2KOqxfU
wire cutter: https://amzn.to/2ucIq14
PCB small portable drill machine: https://amzn.to/2Nu62XF
What is an RPM Counter or Tachometer?
RPM stands for “Revolutions per Minute”. The RPM counter is also known as the Tachometer, revolution-counter, tach, rev-counter, and RPM gauge. The RPM counter or Tachometer is an instrument or a device which is used for measuring the rotation speed of a shaft or disk of a motor or any rotating object.
There are two types of Tachometers
- A tachometer which has contact with the rotating object, like for example an Encoder.
- Contact-less tachometer or Optical Tachometers, these types of the tachometer or RPM counters use a laser or Infrared technology for measuring the RPM of a rotating object from a certain distance. The Optical Tachometers are becoming very famous and commonly used in vehicles and machines. The optical tachometers are now commonly used in industries for monitoring the RPM or speed of different AC or DC motors.
In this project, I have used the optical tachometer technology using an IR infrared Sensor.
This is an Infrared Sensor. It has two LEDs. The white one is the Transmitter LED while the Black one is the Receiver LED. The range can be adjusted using the variable resistor. The range of detection is also affected by the color of the object, if you place a Black color object the range of detection will decrease and for a White object, the range is increased. To get a nice reflection, use a white color sticky tap on the object surface.
The Transmitted IR rays are reflected by the object and are received by the IR Receiver LED.
Why we need a DC Motor Constant Speed Controller?
DC Motors are used in industrial machines, Electric bikes, Wheelchairs, etc. There are situations when we need to run a DC motor at a constant speed, but sometimes when the load on the DC motor increases the RPM starts to reduce which can really affect the production. In a situation like this, we will need an automatic control system which can automatically adjust the RPM of the DC motor using the Pulse Width Module “PWM” Technique.
To achieve the constant speed or RPM we will need to make an optical tachometer or RPM monitor. The RPM counter or Tachometer will measure the RPM of the DC Motor in Real-Time, this RPM is then compared with the pre-set value defined in the programming and then Arduino decides whether to increase the speed of the dc motor or to decrease the speed. The adjustment value is added or subtracted as per the requirement; this is done automatically by the Arduino Uno.
Arduino RPM counter & Constant Speed Controller Circuit Diagram:
Let’s first of all, start with the Power Supply which is based on the LM7812 and LM7805 Voltage Regulators. The 12 volts from the LM7812 are used to power up the DC Motor, while the LM7805 voltage regulator is used to power up the 16×2 LCD. In the circuit diagram, you can clearly see all the connections where the 5 volts are connected.
The connections of the 16×2 LCD with the Arduino Uno can be clearly seen. Pin number1 and Pin number16 are connected with the ground. Pin number2 and Pin number 15 are connected with the 5 volts. Pin number3 of the 16×2 LCD is connected with the middle Pin of the variable resistor, this variable resistor is used to control the LCD contrast. While the other two pins of the variable resistor are connected with the 5 volts and GND. The RS Pin of the 16×2 LCD is connected with the Arduino’s Pin number7. Pin number5 which is the R/W pin of the LCD is connected with the ground. The Enable pin of the LCD is connected with Pin number8 of the Arduino Uno. The data pins D4 to D7 of the LCD are connected with the Arduino’s Pins 9, 10, 11, and 12.
There is another variable resistor given at the bottom, its middle Pin is connected with the Arduino’s Analog Pin A0. This variable resistor is used to set the Pre-set value. This variable is used to tell the controller that at which RPM we want to keep the motor speed constant. The real-time RPM is compared with this value.
On the right side, as you can see, the IR Sensor VCC and GND are connected with the Arduino’s 5 volts and ground. While the OUT Pin of the IR Sensor Module is connected with the Arduino’s External Interrupt Pin 2.
The Motor driver circuit is build using TIP122. This transistor is selected due to its ability to handle currents more than 2Amps. A motor is then connected between the +v supply wire and collector of the TIP122 and a 10k ohm resistor is connected at the base of the TIP122 as its BJT a current-controlled device, and another end of the 10k ohm resistor is connected to the PWM pin of the Arduino as per the programming. So that’s all about the Circuit diagram.
Arduino RPM Counter & DC Motor Constant Speed Controller Programming:
* Optical Tachometer
* Uses an IR LED and IR phototransistor to implement an optical tachometer.
* The IR LED is connected to pin 13 and ran continually.
* Pin 2 (interrupt 0) is connected across the IR detector.
int sensePin = 0; // this pin will be used to set the frequency by changing the varible resistor.
int motorPin = 5; // Motor is connected here
int ledPin = 13; // IR TRANSMITTER LED connected to digital pin 13
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
int incmspeed = 25; // default motor speed
int rs = 7;
int en = 8;
int d4 = 9;
int d5 = 10;
int d6 = 11;
int d7 = 12;
// include the library code:
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//Each rotation, this interrupt function is run twice, so take that into consideration for
lcd.begin(16, 2); // intialise the LCD
//Interrupt 0 is digital pin 2, so that is where the IR detector is connected
//Triggers on FALLING (change from HIGH to LOW)
attachInterrupt(0, rpm_fun, FALLING);
//Turn on IR LED
rpmcount = 0;
rpm = 0;
timeold = 0;
int val = analogRead(sensePin); //val stores the frequency value this value will be compared with the rpmcount which is the frequency of the motor.
val = map(val, 0, 1023, 0 , 8000);
//Update RPM every second
//Don't process interrupts during calculations
//Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt
//happened once per revolution instead of twice. Other multiples could be used
//for multi-bladed propellers or fans
rpm = 30*1000/(millis() - timeold)*rpmcount; // thirty means that the motor blade cuts the sensor two times. so its gonna be half. if the motor blade
// while 20 means that three propellers are used
// cuts it one time then mulitiplied by 60.
// rpmcount is all the frequency in Hz.
timeold = millis();
rpmcount = 0;
//Print out result to lcd
lcd.print("RPM PSRPM adj"); // PS PRES SET RPM, and adjusting rpm
lcd.setCursor(0,1); // second row
lcd.setCursor(6,1); // 10 shows the location
//Restart the interrupt processing
attachInterrupt(0, rpm_fun, FALLING);
// once the val value set then it will remain constant.
// the val value will be compared with the rpmcount. if the rpmcount is less than the val value.
// the voltage to the motor will be inceased to acheive the desired rpmcount.
if( rpm < val )
incmspeed = incmspeed + 10;
if( rpm > val )
incmspeed = incmspeed - 10;
// new addition
if ( incmspeed < 1)
incmspeed = 0;
if( incmspeed > 254)
incmspeed = 255;
// new addition end
// int motorspeed = map(val, 0, 1024,0,255);
Optical Tachometer or RPM Counter & DC Motor Constant Speed Controller Simulation:
Before I start the soldering I always check my connections in simulation software like Proteus, and once I am satisfied with the results then I start the practical connections.
Download Simulation of Arduino RPM counter & DC Motor Constant Speed Controller: simulation
For the practical demonstration watch video given below. This is an old video which I recorded a long time ago, sorry for the video quality. The same project is also known as the frequency locked loop DC Motor Speed Controller.