Projects / Optical tachometer

Optical tachometer

Beginner1 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO

    Stick on the tape

    One strip on the shaft.

  2. NANO

    Aim the sensor

    5 to 15 mm away.

  3. NANO

    Adjust the pot

    LED flickers once per turn.

  4. NANO

    Count pulses

    Print the gap in microseconds.

  5. NANO

    Convert to RPM

    60 million divided by the gap.

  6. NANO

    Add smoothing

    Blend with the last value.

  7. NANO

    Check with a known motor

    Fan, drill or a 1 Hz test.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
TCRT5000 module VCC and GNDNano 5V and GNDPower
TCRT5000 module D0Nano D2, with 10 k to 5VPulse input (interrupt)
OLED SDA and SCLNano A4 and A5I2C
OLED VCC and GNDNano 5V and GNDPower

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.

CheckExpected
Turn the shaft by handReading follows
Fan on a known speedWithin a few percent
Stop itReads 0 after 1.5 s
Add a second strip and set STRIPS 2Same 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 →

Ask Lark AI

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.