I made this Tachometer using IR sensor!
HTML-код
- Опубликовано: 28 июн 2023
- Circuit diagram and code:
www.etechnophiles.com/tachome...
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. - Наука
Circuit diagram and code:
www.etechnophiles.com/tachometer-using-arduino/
Worked great for me. Thank you for your work.
Thank you it worked!
Great work! Thank you for the detailed description. Could you kindly post a code for Serial monitor using H05 BT module. Thank you
Code:
#include
#include
#include
#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.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();
if (currentMillis - previousMillis >= 1000) {
detachInterrupt(digitalPinToInterrupt(IR_PIN));
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();
}
}
how can I change the code to make it a simple counter using this same hardware?
Let make it count the paper sheets please … is it possible????
I cannot see the rpm in display. What should be the problem?? Can se it in serial monitor??
Can we do this for speed ( km/hr)
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
How many volts did the source enter?
Thanks it really works,
but how to convert to KM/H (Kilometers Per Hour)?
wheel circumtanse distance/time.
How meny maximum rpm?
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!🤓🙂
It is working but the rpm values are wayyy off, like it should be 1-2k and it's showing 50k. How to fix
make proper gap between fan@@adityadivine2138
Jumper wire male to female?
How we can send this rpm data to computer program?
If you used ESP32 then using IOT you can send it or using Serial Data
Hi. Works with WEMOS D1 ?
Yes
Hi, is the IR sensor connect to D2, or D5? As the code says D5, but the video says D2. Cheers
Connect it to D5. You can check the blog post for more info :)
@@THEELECTRONICGUY I’m using a nano, and 5 doesn’t work, but 2 does!
Im getting a Pantera Cemetery Gates feel from this video
am i the only one
Hello! Error: Adafruit_GFX.h : No such file or directory. what can I do?
You have to add this library from your Arduino ide.
Goto tool then there is "add library" option
It says programmer not responding what to do??
Is it genuine Arduino Nano or a clone?
Try another bootloader if the comms chip is CH??? and not the genuine FTDI
Common problem with Nano.
IT DIDNT WORK, I CHANGED EVERY COMPONENTS AND IT STILL DIDNT WORK
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.