By Abdul Rehman
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
Key Concepts:
#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.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("RPM: ");
}
void loop() {
unsigned long currentTime = millis();
if (currentTime - prevTime >= 1000) {
detachInterrupt(interruptPin);
unsigned long rpm = (revCount * 60) / 2;
lcd.setCursor(4, 0);
lcd.print(rpm);
lcd.print(" ");
prevTime = currentTime;
revCount = 0;
attachInterrupt(interruptPin, countRevs, RISING);
}
}
void countRevs() {
revCount++;
}
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 You may need to check and tweak few things, if the tachometer is not functioning as expected.
19 April 2023
07 April 2023
07 April 2023
FYP Solutions Powered By Impressive Business WordPress Theme