Skip to content

Instantly share code, notes, and snippets.

@martinius96
Created December 7, 2021 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinius96/30ffcf9306ac5b10344d37f5f44cff7d to your computer and use it in GitHub Desktop.
Save martinius96/30ffcf9306ac5b10344d37f5f44cff7d to your computer and use it in GitHub Desktop.
Otáčkomer na platforme Arduino Uno s modulom IR senzora prekážok KY-032
//Martin Chlebovec (martinius96@gmail.com)
//Schéma zapojenia: http://arduino.clanweb.eu/otackomer.php
//Základná implementácia pre otáčkomer na platforme Arduino Uno / Nano (ATmega328P)
//Neobsahuje ošetrenie zákmitov, volatile premenné v interrupt rutine (negarantované obslúženie premennej)
//Verzia zdarma pre orientačné meranie, chybovost meraní do: 30%
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4); //alebo 0x27 (najpouzivanejsie I2C komunikacne adresy)
int rev = 0;
int rpm;
unsigned long oldtime = 0;
unsigned long time;
void isr() {
rev++;
}
void setup() {
lcd.begin(); //100 kHz I2C speed - Standard Mode
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("-----ZETOR 4011-----");
attachInterrupt(digitalPinToInterrupt (2), isr, RISING); //interrupt pin
}
void loop() {
delay(1000);
detachInterrupt(digitalPinToInterrupt(2));
time = millis() - oldtime; //rozdiel casov
rpm = (rev / time) * 60000; //vyrataj otacky/min
oldtime = millis(); //uloz aktualny cas
rev = 0;
lcd.setCursor(0, 1);
lcd.print(rpm);
lcd.print(" ot/min ");
attachInterrupt(digitalPinToInterrupt (2), isr, RISING);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment