Created
March 11, 2021 06:24
-
-
Save khusamov/b0cf698704f306310cd794b5ae93ca6e to your computer and use it in GitHub Desktop.
Датчик потока воды Sea YF-S201
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://digitrode.ru/computing-devices/mcu_cpu/1806-arduino-i-datchik-rashoda-vody.html | |
const int watermeterPin = 2; | |
volatile int pulse_frequency; | |
unsigned int literperhour; | |
unsigned long currentTime, loopTime; | |
byte sensorInterrupt = 0; | |
void setup() | |
{ | |
pinMode(watermeterPin, INPUT); | |
Serial.begin(9600); | |
attachInterrupt(sensorInterrupt, getFlow, FALLING); | |
currentTime = millis(); | |
loopTime = currentTime; | |
} | |
void loop () | |
{ | |
currentTime = millis(); | |
if(currentTime >= (loopTime + 1000)) | |
{ | |
loopTime = currentTime; | |
literperhour = (pulse_frequency * 60 / 7.5); | |
pulse_frequency = 0; | |
Serial.print(literperhour, DEC); | |
Serial.println(" Liter/hour"); | |
} | |
} | |
void getFlow () | |
{ | |
pulse_frequency++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment