Introduction

In this project, we will build a tachometer using a WeMos board (d1 mini pro), an OLED shield (64x48), and an IR sensor (CNY70) to measure the revolutions per seconds (RPS) of a BLDC motor sourced from an old hard disk drive (separate article).

Schematics

Tachometer schematics

Sensor board

IR sensor board

Sketch

The Sketch is compiled with Arduino IDE 2.3.2.

The OLED display libraries are pretty old and you must use them. The new ones won't work with this sketch.

OLED shield

WeMos OLED shield 64x48

Stack the OLED shield onto the WeMos D1 Mini, ensuring the pins are properly aligned and connected.

Explanation

Setup and Initialization: The WeMos board initializes the OLED display and sets up an interrupt service routine to count the revolutions detected by the IR sensor.

Measuring RPS: The loop function uses the millis() function to calculate the time interval and update the RPS every 10 seconds. The RPS is then displayed on the OLED screen.

Interrupt Service Routine: The countRevolution function increments the revolution count each time the IR sensor detects a falling edge (indicating a reflective mark has passed).

Accuracy tachometer

I connected a square wave generator to input D5 and measured the RPS on the OLED display. I got a consistent 0.5% error between 50 and 10'000 Hz and 1.5% at 100 kHz. Good enough for future uses.

Happy Counting!