Digital Tachometer using IR Sensor with Arduino for measuring RPM
In this project, we have designed Digital Tachometer using IR Sensor with Arduino for measuring the number of rotations of rotating Motor in RPM. Simply we have interfaced IR sensor module with Arduino and SSD 1306 LCD module for display. The IR sensor module consists of IR Transmitter & Receiver in a single pair that can work a Digital Tachometer for speed measurement of any rotating object.
Components:
1) Arduino Nano: https://roboman.in/59h4
2) Arduino Nano Type C : https://roboman.in/xkfu
3) TP-4056 Module : https://roboman.in/oa0m
4) DC-DC Boost Converter LM2587 or XL6019 : https://roboman.in/kkuj
5) MAX7219 Dot Matrix 4 in 1 Display Module: https://roboman.in/jekd
6) Sound Sensor : Sound Sensor :https://roboman.in/vs1e
7) 18650 Lithium Battery 2500mah 3C :https://roboman.in/utwc
7) 18650 Lithium Battery 2600mah 3C :https://roboman.in/mmab
7) 18650 Lithium Battery 2200mah 1C :https://roboman.in/70b5
7) 18650 Lithium Battery 2000mah 1C :https://roboman.in/7em9
7) 18650 Lithium Battery 1800mah 1C :https://roboman.in/ywss
Diagram :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
// Easy Peasy Tachometer //James Rovere 2020 #include <Wire.h> #include <EEPROM.h> #include <Adafruit_SSD1306.h>// You may have to edit library for 128x64, //default is 128 x 32. #define OLED_WIDTH 128 #define OLED_HEIGHT 64 #define OLED_ADDR 0x3C // A very common address for these displays. Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT); int eeAddress = 0; float value=0; float rev=0; int rpm; int oldtime=0; int time; int pushbutton=5; int laserpin = 4; void isr() //interrupt service routine { rev++; } void setup() { Serial.begin(9600); display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR); display.clearDisplay(); pinMode(pushbutton,INPUT); pinMode(laserpin,OUTPUT); digitalWrite(2 ,HIGH);// Instead of using a pull up resistor attachInterrupt(0,isr,RISING); //attaching the interrupt } void loop() { if(digitalRead(pushbutton)) { delay(500);// 2 second delay digitalWrite(4 ,HIGH); detachInterrupt(0); //detaches the interrupt while calculating time=millis()-oldtime; //finds the time rpm=(rev/time)*60000; //calculates rpm oldtime=millis(); //saves the current time rev=0; display.clearDisplay(); display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(0, 0);// Vertical, Horizontal. display.println("RPM:"); display.setTextSize(5); display.setTextColor(WHITE); display.setCursor(0,25); display.println(rpm); Serial.println(rpm); clearEEPROM(); EEPROM.put(eeAddress, rpm); display.display(); attachInterrupt(0,isr,RISING); } else{ digitalWrite(4 ,LOW); display.clearDisplay(); display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(0, 0);// Vertical, Horizontal. display.println("RPM:"); display.setTextSize(1); display.setCursor(100, 0);// Vertical, Horizontal. display.println("PREV"); display.setTextSize(5); display.setTextColor(WHITE); display.setCursor(0,25); int rpm1= 0; EEPROM.get(eeAddress,rpm1); display.println(rpm1); display.display(); } } void clearEEPROM() { for (int i = 0 ; i < EEPROM.length() ; i++) { if(EEPROM.read(i) != 0) //skip already "empty" addresses { EEPROM.write(i, 0); //write 0 to address i } } Serial.println("EEPROM erased"); eeAddress = 0; //reset address counter } |