I made this Tachometer using IR sensor!
Circuit diagram and code:
www.etechnophi...
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.
Пікірлер: 34
Circuit diagram and code: www.etechnophiles.com/tachometer-using-arduino/
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(); } }
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
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
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!🤓🙂
@adityadivine2138
7 ай бұрын
It is working but the rpm values are wayyy off, like it should be 1-2k and it's showing 50k. How to fix
@user-jz7jr5rr1c
7 ай бұрын
make proper gap between fan@@adityadivine2138
Can we do this for speed ( km/hr)
I cannot see the rpm in display. What should be the problem?? Can se it in serial monitor??
Let make it count the paper sheets please … is it possible????
How do I calculate rpm to km/h and display it on the LCD screen?
@riskyvivi2960
10 күн бұрын
please make a code... thanks
how can I change the code to make it a simple counter using this same hardware?
How many volts did the source enter?
Hi, is the IR sensor connect to D2, or D5? As the code says D5, but the video says D2. Cheers
@THEELECTRONICGUY
4 ай бұрын
Connect it to D5. You can check the blog post for more info :)
@Sophie333C
4 ай бұрын
@@THEELECTRONICGUY I’m using a nano, and 5 doesn’t work, but 2 does!
How we can send this rpm data to computer program?
@user-jz7jr5rr1c
7 ай бұрын
If you used ESP32 then using IOT you can send it or using Serial Data
Jumper wire male to female?
Thanks it really works, but how to convert to KM/H (Kilometers Per Hour)?
@mattivirta
9 ай бұрын
wheel circumtanse distance/time.
Im getting a Pantera Cemetery Gates feel from this video am i the only one
Hi. Works with WEMOS D1 ?
@user-jz7jr5rr1c
7 ай бұрын
Yes
How meny maximum rpm?
Hello! Error: Adafruit_GFX.h : No such file or directory. what can I do?
@anonymousanonymous7959
8 ай бұрын
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??
@phils6926
5 ай бұрын
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.