Build it step by step
0 of 7 doneStick on the tape
One strip on the shaft.
Aim the sensor
5 to 15 mm away.
Adjust the pot
LED flickers once per turn.
Count pulses
Print the gap in microseconds.
Convert to RPM
60 million divided by the gap.
Add smoothing
Blend with the last value.
Check with a known motor
Fan, drill or a 1 Hz test.
How do you build an optical tachometer?
Point an IR sensor at a reflective strip on a spinning shaft to read RPM. You need Arduino Nano, TCRT5000 IR reflective sensor module, SSD1306 OLED Display and Resistor 10 kΩ. It takes 7 steps and about 60 minutes.
- Level
- Beginner
- Time
- About 60 min
- Parts
- 4
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- DisplaysBuy
- PassivesBuyResistor 10 kΩ × 1
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| TCRT5000 module VCC and GND | Nano 5V and GND | Power |
| TCRT5000 module D0 | Nano D2, with 10 k to 5V | Pulse input (interrupt) |
| OLED SDA and SCL | Nano A4 and A5 | I2C |
| OLED VCC and GND | Nano 5V and GND | Power |
Code
A tachometer only needs to know how long a shaft takes for one turn. A strip of reflective tape on the shaft sends a bright flash back to the infrared sensor once per turn, and the time between flashes gives the speed: sixty million microseconds divided by the gap is revolutions per minute. The interrupt records the time of each pulse exactly, even while the screen is being updated, and the sketch ignores any pulse sooner than 2 ms after the last, which removes false triggers. The display smooths the number a little so that it does not flicker. Aim the sensor 5 to 15 mm from the strip, set its potentiometer until the on-board LED flickers once per pass, and shield it from sunlight, which contains infrared. Test it on a motor of known speed first. Never hold the sensor close to a fast spinning part with loose hair, clothing or fingers; fix it on a stand. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Optical tachometer: one reflective strip per turn. Libraries: Adafruit SSD1306, Adafruit GFX. Board: Arduino Nano.
// Adjust the module's blue potentiometer until the on-board LED flickers once per pass of the strip.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const byte SENSOR = 2;
const byte STRIPS = 1; // reflective strips on the shaft
volatile unsigned long lastUs = 0, periodUs = 0;
volatile bool fresh = false;
float rpm = 0;
void isr() {
unsigned long now = micros();
unsigned long dt = now - lastUs;
if (dt > 2000) { periodUs = dt; lastUs = now; fresh = true; } // ignore bounces shorter than 2 ms (30000 rpm limit)
}
void setup() {
pinMode(SENSOR, INPUT);
attachInterrupt(digitalPinToInterrupt(SENSOR), isr, FALLING);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextColor(SSD1306_WHITE);
}
void loop() {
noInterrupts(); unsigned long p = periodUs; bool f = fresh; fresh = false; unsigned long last = lastUs; interrupts();
if (f && p > 0) { float now = 60000000.0 / p / STRIPS; rpm = rpm == 0 ? now : 0.7 * rpm + 0.3 * now; } // smoothing
if (micros() - last > 1500000UL) rpm = 0; // no pulse for 1.5 s means stopped
oled.clearDisplay(); oled.setTextSize(3); oled.setCursor(0, 8); oled.print(rpm, 0);
oled.setTextSize(2); oled.setCursor(0, 44); oled.print("RPM");
oled.display();
delay(200);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Turn the shaft by hand | Reading follows |
| Fan on a known speed | Within a few percent |
| Stop it | Reads 0 after 1.5 s |
| Add a second strip and set STRIPS 2 | Same RPM |
If it does not work
Reads double
The sensor sees two flashes per turn.
Jumpy
Shade it from sunlight and fix the distance.
Zero always
Check the pot and the D0 wire.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the optical tachometer?
Arduino Nano, TCRT5000 IR reflective sensor module, SSD1306 OLED Display and Resistor 10 kΩ.
How long does the optical tachometer take to build?
About 60 minutes for a beginner maker, in 7 steps.
How do I know the optical tachometer works?
Turn the shaft by hand: Reading follows. Fan on a known speed: Within a few percent. Stop it: Reads 0 after 1.5 s.
Reads double: what should I check?
The sensor sees two flashes per turn.
Jumpy: what should I check?
Shade it from sunlight and fix the distance.
Zero always: what should I check?
Check the pot and the D0 wire.
