Build an Arduino digital tachometer that measures RPM with an IR sensor and shows live and max RPM on a 16×2 I2C LCD. Wiring table, diagram and full code.
Need it ready-made? Buy Ready Project
This Arduino digital tachometer measures how fast something spins, in revolutions per minute (RPM), without touching it. An IR reflective sensor looks at a white strip on a motor shaft, fan or wheel, and the Arduino Uno shows the live RPM and the highest RPM on a 16×2 I2C LCD.
It is a useful bench tool for checking DC motors, cooler fans, drill speed, bicycle wheels or robot wheels, and a great way to learn how hardware interrupts work on the ATmega328P.

How It Works
- Sensing: the IR module has an infrared LED and a photodiode. A white or shiny strip reflects the IR light back, so the module’s OUT pin goes LOW every time the strip passes. A fan blade passing in front of the sensor works the same way.
- Interrupt timing: OUT is connected to D2, which is external interrupt INT0. On every falling edge the interrupt routine records the time with
micros()and stores the gap since the previous pulse. Pulses closer than 0.5 ms are ignored as noise. - RPM maths: RPM = 60,000,000 / (period in microseconds x marks per revolution). Measuring the period between pulses gives a fresh reading on every turn, so it is accurate even at low speeds.
- Marks per revolution: if you stick 2 strips on a wheel or count a 3-blade fan, press the MODE button to set 1, 2, 3 or 4 marks. The maximum RPM resets when you change it.
- Zero detection: if no pulse arrives for 2 seconds, the display shows 0 RPM. The screen updates 4 times per second and the reading is also printed on the Serial Monitor at 9600 baud.
Components Required
- Arduino Uno R3 (or Nano, ATmega328P) – 1
- IR obstacle / reflective sensor module (TCRT5000 or FC-51 type, with LM393 comparator) – 1
- 16×2 LCD with I2C backpack (PCF8574) – 1
- Tactile push button – 1
- Small DC motor or fan to test (optional) – 1
- White paper or reflective tape strip – 1
- Breadboard and jumper wires
- USB cable or 9V adapter for power
Wiring Table
| Component pin | Arduino pin | Notes |
|---|---|---|
| IR sensor VCC | 5V | |
| IR sensor GND | GND | |
| IR sensor OUT | D2 | Interrupt pin INT0 (D3 also works) |
| LCD VCC | 5V | |
| LCD GND | GND | |
| LCD SDA | A4 | I2C data |
| LCD SCL | A5 | I2C clock |
| MODE button leg 1 | D4 | Internal pull-up enabled in code |
| MODE button leg 2 | GND | Use diagonal legs on a 4-pin button |
| Status LED | D13 | On-board LED, no wiring needed |
Connection Diagram
The illustration above shows the general layout; its wire routes are only for orientation. The pin-accurate drawing below matches the wiring table exactly, so follow it while building.
Code
Install the LiquidCrystal I2C library (by Frank de Brabander) from the Arduino IDE Library Manager. Select Arduino Uno as the board, choose the right COM port and upload the sketch below. The sketch compiles to about 7 KB of flash.
/*
Arduino Digital Tachometer with IR Sensor & I2C LCD
---------------------------------------------------
Measures the speed (RPM) of a motor, fan or wheel using an IR
obstacle/reflective sensor module and shows it on a 16x2 I2C LCD.
Wiring (Arduino Uno / Nano, ATmega328P):
IR sensor OUT -> D2 (INT0, external interrupt)
IR sensor VCC -> 5V, GND -> GND
LCD SDA -> A4, LCD SCL -> A5
LCD VCC -> 5V, GND -> GND
MODE button -> D4 to GND (internal pull-up)
Status LED -> D13 (on-board LED, blinks with each pulse)
Libraries: LiquidCrystal_I2C (Frank de Brabander), Wire (built-in)
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // change to 0x3F if your LCD stays blank
const byte SENSOR_PIN = 2; // must be D2 or D3 (interrupt pins on Uno)
const byte BUTTON_PIN = 4; // cycles marks per revolution 1..4
const byte LED_PIN = 13;
const unsigned long TIMEOUT_US = 2000000UL; // no pulse for 2 s => show 0 RPM
const unsigned long MIN_GAP_US = 500UL; // ignore glitches shorter than 0.5 ms (max ~120000 pulses/min)
const unsigned long UPDATE_MS = 250; // LCD refresh interval
volatile unsigned long lastPulseUs = 0; // time of the latest valid pulse
volatile unsigned long periodUs = 0; // time between the last two pulses
volatile unsigned long pulseCount = 0; // total pulses (for the counter line)
byte marksPerRev = 1; // reflective strips / blades per revolution
unsigned long maxRpm = 0;
unsigned long lastUpdate = 0;
bool lastButton = HIGH;
// Interrupt service routine: runs on every falling edge from the IR module
void onPulse() {
unsigned long now = micros();
unsigned long gap = now - lastPulseUs;
if (gap < MIN_GAP_US) return; // simple glitch filter
periodUs = gap;
lastPulseUs = now;
pulseCount++;
}
void setup() {
pinMode(SENSOR_PIN, INPUT_PULLUP);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0); lcd.print(" IR Tachometer ");
lcd.setCursor(0, 1); lcd.print(" Ready... ");
delay(1200);
lcd.clear();
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(SENSOR_PIN), onPulse, FALLING);
}
void loop() {
// --- MODE button: change marks per revolution (1..4), resets max ---
bool b = digitalRead(BUTTON_PIN);
if (lastButton == HIGH && b == LOW) {
delay(30); // debounce
if (digitalRead(BUTTON_PIN) == LOW) {
marksPerRev = (marksPerRev % 4) + 1;
maxRpm = 0;
}
}
lastButton = b;
if (millis() - lastUpdate < UPDATE_MS) return;
lastUpdate = millis();
// Copy volatile values safely with interrupts paused
noInterrupts();
unsigned long period = periodUs;
unsigned long lastUs = lastPulseUs;
unsigned long count = pulseCount;
interrupts();
unsigned long rpm = 0;
if (period > 0 && (micros() - lastUs) < TIMEOUT_US) {
// RPM = 60 s * 1,000,000 us / (period between marks * marks per rev)
rpm = 60000000UL / (period * marksPerRev);
}
if (rpm > maxRpm) maxRpm = rpm;
digitalWrite(LED_PIN, (micros() - lastUs) < 50000UL); // LED on right after a pulse
// Line 1: live RPM
lcd.setCursor(0, 0);
lcd.print("RPM:");
char buf[17];
snprintf(buf, sizeof(buf), "%7lu M:%u ", rpm, marksPerRev);
lcd.print(buf);
// Line 2: maximum RPM seen
lcd.setCursor(0, 1);
snprintf(buf, sizeof(buf), "MAX:%7lu ", maxRpm);
lcd.print(buf);
Serial.print("RPM="); Serial.print(rpm);
Serial.print(" MAX="); Serial.print(maxRpm);
Serial.print(" pulses="); Serial.println(count);
}
Calibration and Use
- Stick one small white strip on a dark motor shaft or disc (or a black strip on a shiny one).
- Hold the sensor 3-10 mm from the strip and turn the blue potentiometer on the module until its LED blinks cleanly once per turn.
- Check against a known speed if you can: a standard PC fan label or a phone tachometer app with a strobe.
Troubleshooting
| Problem | Fix |
|---|---|
| LCD shows only blocks or stays blank | Adjust the contrast pot on the I2C backpack and try address 0x3F instead of 0x27. |
| RPM is double the real value | The sensor sees two edges per turn; set MODE to 2 marks or use a smaller, cleaner strip. |
| Reading jumps around | Shield the sensor from sunlight and bright lamps, which contain IR, and keep the distance fixed. |
| Always 0 RPM | Check OUT goes to D2 and that the module LED blinks when the strip passes. |
Ideas to Extend
- Add an SD card to log RPM over time.
- Use an ESP32 to show the RPM on a phone over Wi-Fi.
- Add a PWM motor driver and turn it into a closed-loop speed controller.
- Replace the IR sensor with a hall sensor and a magnet for dusty or wet places.
2 thoughts on “Arduino Digital Tachometer with IR Sensor & I2C LCD”