Arduino sprintf()Arduino sprintf

In this article we are explaining how to create a tachometer using Arduino. Although you can use any Arduino board you want, but we are using Arduino Nano in this article. Tachometer is usually used to measure the rpm of some rotational unit. This is one of the most widely used meter in industrial applications. We need to use this very often. There are other methods to create the tachometer with Arduino but in today’s article we are going to make this by using “interrupts”. We previously created frequency counter article and most of the code is relevant to today’s article as well. You may want to check out that post as well.

So let’s started and see which components we may required

Component List for Arduino based Tachometer

  • Arduino board
  • Hall effect sensor
  • Neodymium magnet
  • 16×2 LCD display
  • Jumper wires
  • Breadboard

Wiring Connections: for Arduino based Tachometer

  • Hall sensor: VCC to 5V, GND to GND, and OUT to digital pin 2
  • LCD: VCC to 5V, GND to GND, SDA to A4, and SCL to A5

Key Concepts:

  • How to use Interrupts for RPM measurement
  • Hall effect sensor: what are they and how they help for tachometer making
  • Non-blocking code execution: How to keep the code execution non blocking

Arduino Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const byte hallSensor = 2;
const byte interruptPin = 0;
volatile unsigned long revCount = 0;
unsigned long prevTime = 0;
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  pinMode(hallSensor, INPUT);
  attachInterrupt(interruptPin, countRevs, RISING);
  lcd.setCursor(0, 0);
  lcd.print("RPM: ");

void loop() {
  unsigned long currentTime = millis();
  if (currentTime - prevTime >= 1000) {
    unsigned long rpm = (revCount * 60) / 2;
    lcd.setCursor(4, 0);
    lcd.print("    ");
    prevTime = currentTime;
    revCount = 0;
    attachInterrupt(interruptPin, countRevs, RISING);

void countRevs() {
Code language: PHP (php)

Key Functions:

  • attachInterrupt(): Configures interrupt for rising edge, in this function we configured the interrupt to detect the rising edge on the external input pin. So whenever a rising edge found on the external interrupt pin, this would cause the interrupt to fire.
  • countRevs(): Increments revCount on each interrupt. This function would help to count the every revolution counting veriable whenever one revolution completes or in other words, whenever the interrupt occurs.
  • loop(): Calculates RPM and updates LCD display. Inside this loop function all we have to do is to update the calculated RPMs onto the LCD display which in our case is 12c based Liquid Crystal Display of 16×2 character lcd interfaced with Arduino

Some Tips to troubleshoot if it is not working

You may need to check and tweak few things, if the tachometer is not functioning as expected.

  • Check if hall effect and magnets are having contact at every rotation.
  • Make sure to adjust the distance between the magnet and the Hall effect sensor for the correct reading of the RPM
  • While reading the interrupts, even it is very much De-bounced, but according to your sensory network, you may need additional denouncing to remove the bouncing effect and wrongly revolutions being measured. So make sure that there are proper debouncing happening while reading the measurements.

By Abdul Rehman

My name is Abdul Rehman and I love to do Reasearch in Embedded Systems, Artificial Intelligence, Computer Vision and Engineering related fields. With 10+ years of experience in Research and Development field in Embedded systems I touched lot of technologies including Web development, and Mobile Application development. Now with the help of Social Presence, I like to share my knowledge and to document everything I learned and still learning.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.