Tachometer Using Arduino and IR Sensor
Tachometer Using Arduino and IR Sensor
This is a simple yet effective RPM tachometer using Arduino UNO and an IR sensor.
It counts the revolutions of a rotating object using interrupts and displays the RPM
on an OLED screen. This adaptable tool is useful for controlling and monitoring
machines, making it an excellent addition to a variety of projects and industries.
Table of Contents
Given below are the series of steps this tachometer goes through to display the
motor speed.
1. Sensor setup: First, place an infrared sensor near a rotating product with a
reflecting marking or gaps. The IR sensor recognizes the marker as it passes in front
of it.
3. RPM calculation: To obtain the RPM (Revolutions Per Minute), this formula is
applied:
RPM = (Counter / 2) * 60
4. Display update: The calculated RPM value is displayed on the OLED screen. The
display updates every second, giving real-time RPM readings.
Components required
An infrared sensor is an electronic device that emits light to detect an object in its
surroundings. An IR sensor can detect motion as well as measure the heat of an
object.
Typically, all objects in the infrared range emit some type of thermal radiation. These
radiations are undetectable to human eyes, but an infrared sensor can detect them.
The emitter is a simple infrared LED (Light Emitting Diode), while the detector is a
simple infrared photodiode. The photodiode is sensitive to infrared light of the same
wavelength as the IR LED.
When infrared light strikes a photodiode, the resistances and output voltages change
in response to the magnitude of the IR light.
Circuit diagram
VCC 5V Pin
SDA A4
SCL A5
VCC 5V Pin
GND GND of Arduino Nano
OUT D5
Physical connections
Program/Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
void IRinterrupt() {
counter++;
}
void setup() {
pinMode(IR_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(IR_PIN), IRinterrupt, FALLING);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("TEG");
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Tachometer");
display.display();
delay(2000);
}
void loop() {
unsigned long currentMillis = millis();
display.clearDisplay();
display.setCursor(0, 0);
display.print("RPM: ");
display.println(rpm);
display.display();
}
}
Program explanation
Include Libraries:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
These lines contain the libraries required for communication (Wire) and working with
the Adafruit SSD1306 OLED display.
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
Here, a constant OLED_RESET is defined to specify the reset pin for the OLED
display. The Adafruit_SSD1306 object called display is created to interact with the
OLED screen.
IR_PIN is a variable that stores the pin number to which the IR sensor is
connected.
Counter is a volatile variable that counts the number of revolutions detected
by the infrared sensor. It’s declared as volatile because it’s modified within an
interrupt service routine.
previousMillis is used to store the previous time for timing purposes.
The variable rpm is used to store the determined RPM value.
void IRinterrupt() {
counter++;
}
This is an interrupt service routine (ISR) that gets called whenever a falling edge is
detected on the IR sensor. It increments the counter variable, which keeps track of
the number of revolutions.
Setup Function:
void setup() {
pinMode(IR_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(IR_PIN), IRinterrupt, FALLING);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("TEG");
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Tachometer");
display.display();
delay(2000);
}
The setup function uses a pull-up resistor to initialise the IR sensor pin as an
input. It also attaches the IRinterrupt ISR to the falling edge of the IR sensor
input pin.
It then initializes and configures the OLED display, briefly displaying “TEG” and
“Tachometer” messages.
Loop Function:
void loop() {
unsigned long currentMillis = millis();
In the loop function, the code checks if at least 1 second has passed since
the last RPM calculation using currentMillis – previousMillis >= 1000.
If a second has passed, it detaches the interrupt temporarily to prevent further
counts, calculates the RPM (assuming two counts per revolution), then
reattaches the interrupt.
The calculated RPM value is then displayed on the OLED display.
Conclusion
This project is made using an infrared (IR) sensor and an OLED display with Arduino
nano board. It counts the revolutions of a rotating object with an infrared (IR) sensor,
calculates the RPM (revolutions per minute), and displays the RPM value on an OLED
screen.
This project shows how to use Arduino microcontrollers to monitor and display
rotational speed, which can be used in a variety of fields such as automotive,
robotics, and industrial machinery maintenance.
Tejas Chavan
ARDUINO, Electronics
Kaiweets KM601 Smart Multimeter Review in 2025
Jeff Monegal
April 3, 2024 at 12:13 pm
Hi.
Well done mate but to enhance your project. Look at the model aircraft
sector. Measuring the speed of model glo plug engines is very important
especially with multi engine aircraft. An accurate taco is not only important
but very expensive. Glo engines can turn propellers at 40,000 rpm and more.
Petrol engines at 9000 and sometimes more. Drive shaft speeds on model
cars is also important.
If these speeds are within your taco’s limits then produce a neat looking unit
in a neat case. This would be a desirable item as long as your price is
reasonable.
Best of luck
Jeff.
Reply
Ankit Negi
April 5, 2024 at 11:13 am
Hi Jeff,
Thanks for your valuable insights! We’ll definitely consider your suggestions
for enhancing our project. But this is just a prototype project for learning.
Reply
Adrian
April 3, 2024 at 4:28 pm
Reply
Ankit Negi
April 5, 2024 at 11:09 am
I’m glad you like this project. That’s great! Please give us an update when
you start working on it, and if you encounter any problems, we’re here to
help you out.
Reply
Segwabe Lekgatlhanye
August 24, 2024 at 3:05 am
Hello, where(supplier) can I buy this parts i will like to try the same project of
Tachometer Using Arduino And IR Sensor
Thanks
Reply
Ankit Negi
September 2, 2024 at 12:02 pm
Hi,
You are from which part of the world?
Reply
CB
December 7, 2024 at 8:12 am
Hello
I built the little project, the sketch uploaded nicely, the IR is responsive but
cannot get anything on OLED. I replaced and double checked the easy wiring,
I even exchanged breadboard to no avail. The Oled is good as I plugged it
into another project and it worked. It must be in the coding. Any suggestion?
Reply
Ankit Negi
December 8, 2024 at 12:37 pm
That’s odd. Are you using the same OLED display? If yes, to which pins your
OLED is connected to? Can you double check.
Reply
Leave a Comment
Name *
Email *
Website
Post Comment
Categories
Select Category
Disclaimer
This page might contain some affiliate Links as we are participant in the Amazon
Services LLC Associates Program. We may get compensation for each successful
purchase through our link.
Recent Posts
Recent Comments