I made this Tachometer using IR sensor!

preview_player
Показать описание
Circuit diagram and code:

Steps to make this tachometer:

1. Put the Arduino Nano on the breadboard
2. Connect the SDA and SCL pins of OLED to A4 and A5 respectively.
3. Connect the OUT pin of the IR sensor to digital pin 2 of Arduino Nano and give +5v and GND connections.
4. Upload the code. (The code is pinned in the first comment.)

Explanation:
The current time in milliseconds is stored in the 'currentMillis' variable.
If the time difference between the current time and the previous time stored in previousMillis is equal to or greater than 1000 milliseconds (1 second):
The interrupt is temporarily detached to avoid conflicting with the counter variable.

The RPM value is calculated by dividing the counter value by 2 (assuming each revolution triggers two interrupts) and multiplying it by 60 to convert it to RPM.

The counter is reset to 0.
The interrupt is reattached to the IR sensor pin.
The previousMillis is updated to the current time.
The OLED display is cleared.
The RPM value is displayed on the OLED display.
Рекомендации по теме
Комментарии
Автор

Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

const int IR_PIN = 5; // IR sensor input pin

volatile unsigned int counter = 0; // Counter variable for revolutions
unsigned long previousMillis = 0; // Variable to store previous time
unsigned int rpm = 0; // Variable to store RPM value

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.setCursor(0, 0);
display.println("TEG");
display.display();
delay(2000);
display.clearDisplay();
display.setTextSize(2);

display.setCursor(0, 0);

display.display();
delay(2000);
}

void loop() {
unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= 1000) {

rpm = (counter / 2) * 60; // Calculate RPM
counter = 0;
attachInterrupt(digitalPinToInterrupt(IR_PIN), IRinterrupt, FALLING);
previousMillis = currentMillis;

display.clearDisplay();
display.setCursor(0, 0);
display.print("RPM: ");
display.println(rpm);
display.display();
}
}

THEELECTRONICGUY
Автор

Worked great for me. Thank you for your work.

nicklasmuller
Автор

Great work! Thank you for the detailed description. Could you kindly post a code for Serial monitor using H05 BT module. Thank you

NextGenPhysics
Автор

hi bro, how about use 2 IR sensor to read 2 different rotation obejct?
2 IR sensor
2 object rotation
1 arduino
1 LCD display

samnafri
Автор

Dear doing great job, with this please try to keep code and diagram with video it would help more to dive deeply to beginners. Keep it up.. Good Luck!🤓🙂

devendradandekar
Автор

I cannot see the rpm in display. What should be the problem?? Can se it in serial monitor??

alpeshjadhav
Автор

How do I calculate rpm to km/h and display it on the LCD screen?

riskyvivi
Автор

Let make it count the paper sheets please … is it possible????

singhaseyha
Автор

how can I change the code to make it a simple counter using this same hardware?

lukedavies
Автор

Hi, is the IR sensor connect to D2, or D5? As the code says D5, but the video says D2. Cheers

SophieC
Автор

How we can send this rpm data to computer program?

debarshi
Автор

Thanks it really works,
but how to convert to KM/H (Kilometers Per Hour)?

ahsanamala
Автор

Im getting a Pantera Cemetery Gates feel from this video
am i the only one

martinkuliza
Автор

Hello! Error: Adafruit_GFX.h : No such file or directory. what can I do?

alexandruflondor
Автор

IT DIDNT WORK, I CHANGED EVERY COMPONENTS AND IT STILL DIDNT WORK

dienau
Автор

It says programmer not responding what to do??

sahajyadav
Автор

i have similar project whit promixity sensor 12 volt, to optocoupler 12 volt to 5 volt and arduino nano, but not measure right to speed, i measure laser RPM meter my spindle speed and show 5400 rpm, but arduino show 4200-4300 rpm. what need change code can make accurate rpm, promixity sensor trigged spindle chuck 2 x /rev. pulse go to arduino pin 2, code formula have
print_to_OLED();
if (millis() - millisBefore > 1000) {
rpm = ((objects / 3.0) * 60); //(object / 3.0)*60;) // i testing many different (object / 1 or 2 or 4 or other ) x60) but not working right.
objects = 2; //liipaisujen määrä trigger 2x/rev
millisBefore = millis();
}
delay(100);
void count() {
objects++;
how repair code, working well but not measure right speed. please help, i not understand code lot. I change IR sensor to promixity sensor because IR not sense accurate speed newer, if read speed show display 1200-5600 and not stabile measure whit IR sensor, lot better have promixity sensor my cnc spindle chuck. need measure 0-30 000 rpm. arduino working well but not show right speed, HELP PLEASE.

mattivirta