Arduino RPM Counter Using an Optical Sensor
Building an RPM (revolutions per minute) counter is a classic and useful Arduino project. This guide walks you through creating an optical tachometer using an IR LED, an IR phototransistor, and a 16×2 LCD display. The result is a simple, accurate RPM counter suitable for motors, fans, or propellers.
Project Overview
This Arduino RPM counter works by interrupting an infrared beam with a rotating object (such as a propeller). Each interruption is detected by the Arduino, counted, and converted into an RPM value that is displayed on an LCD screen.
Key features:
-
Real-time RPM measurement
-
Optical (non-contact) sensing
-
LCD output for easy reading
-
Simple and low-cost components
Parts List
You will need the following components:
-
1 × Arduino board
-
1 × 16×2 LCD display (HD44780 compatible)
-
1 × 10kΩ potentiometer (LCD contrast control)
-
1 × 10kΩ resistor
-
1 × IR LED
-
1 × IR phototransistor
-
Jumper wires
Wiring Instructions
Follow these steps carefully to assemble the circuit. Each subsection explains exactly where every wire should go to avoid confusion.
-
Power Distribution
-
Connect the Arduino 5V pin to the breadboard positive rail.
-
Connect the Arduino GND pin to the breadboard ground rail.
-
Make sure all components (LCD, potentiometer, IR LED, and phototransistor) share this common ground.
-
-
LCD and Potentiometer Connections (16×2 Parallel LCD)
-
LCD Pin 1 (VSS) → Ground
-
LCD Pin 2 (VDD) → 5V
-
LCD Pin 3 (VO) → Middle pin of the 10kΩ potentiometer
-
Potentiometer side pins → 5V and Ground (used to adjust LCD contrast)
-
-
LCD Pin 4 (RS) → Arduino digital pin 7
-
LCD Pin 5 (RW) → Ground (LCD set to write mode)
-
LCD Pin 6 (E) → Arduino digital pin 8
-
LCD Pin 11 (D4) → Arduino digital pin 9
-
LCD Pin 12 (D5) → Arduino digital pin 10
-
LCD Pin 13 (D6) → Arduino digital pin 11
-
LCD Pin 14 (D7) → Arduino digital pin 12
-
LCD Backlight
-
Pin 15 (A) → 5V through a resistor
-
Pin 16 (K) → Ground
-
-
-
IR LED (Transmitter)
-
Anode (longer lead) → Arduino digital pin 13
-
Cathode (shorter lead) → Ground
-
The IR LED remains ON continuously to emit an infrared beam toward the phototransistor.
-
-
IR Phototransistor (Receiver)
-
Collector (shorter lead) → Arduino digital pin 2
-
Emitter (longer lead) → Ground
-
Position the phototransistor directly facing the IR LED so the beam is interrupted by the rotating object.
-
-
Final Checks
-
Ensure all ground connections are common.
-
Double-check pin numbers before powering the circuit.
-
Adjust the potentiometer until text is clearly visible on the LCD.
-
Tip: Digital pin 2 is used because it supports hardware interrupts, allowing the Arduino to count beam interruptions accurately and calculate RPM reliably.
Arduino Code
Upload the following sketch to your Arduino board:
/*
* Optical Tachometer
*
* Uses an IR LED and IR phototransistor to implement an optical tachometer.
* The IR LED is connected to pin 13 and runs continuously.
* Digital pin 2 (interrupt 0) is connected to the IR detector.
*/
#include <LiquidCrystal.h>
int ledPin = 13; // IR LED connected to digital pin 13
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
// Initialize the LCD with the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void rpm_fun() {
// This interrupt runs every time the IR beam is cut
rpmcount++;
}
void setup() {
lcd.begin(16, 2); // Initialize the LCD
// Attach interrupt to digital pin 2 (interrupt 0)
attachInterrupt(0, rpm_fun, FALLING);
// Turn on IR LED
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
rpmcount = 0;
rpm = 0;
timeold = 0;
}
void loop() {
// Update RPM every second
delay(1000);
// Temporarily stop interrupts during calculation
detachInterrupt(0);
rpm = 30 * 1000 / (millis() - timeold) * rpmcount;
timeold = millis();
rpmcount = 0;
// Display RPM on LCD
lcd.clear();
lcd.print("RPM=");
lcd.print(rpm);
// Re-enable interrupt
attachInterrupt(0, rpm_fun, FALLING);
}
Understanding the RPM Calculation
This project assumes two interruptions per revolution, such as when using a motor with a two-blade propeller.
That’s why the RPM calculation uses this formula:
rpm = 30 * 1000 / (millis() - timeold) * rpmcount;
Adjusting for Your Setup
-
One interruption per revolution:
Replace30with60 -
More blades or markings:
Divide60by the number of interruptions per full rotation and update the formula accordingly.
This flexibility allows you to adapt the project to different motors and rotating objects.
Final Notes
-
Ensure the IR LED and phototransistor are properly aligned for reliable readings.
-
Use reflective tape or a slotted disk for more consistent beam interruption.
-
This project can be extended by logging RPM data or adding serial output.
Ready to Build?
This Arduino RPM counter is a great foundation for motor control projects, robotics, and mechanical diagnostics. Assemble the components, upload the code, and start measuring RPM with confidence.