Skip to content

Instantly share code, notes, and snippets.

@khusamov
Created March 11, 2021 06:24
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 khusamov/b0cf698704f306310cd794b5ae93ca6e to your computer and use it in GitHub Desktop.
Save khusamov/b0cf698704f306310cd794b5ae93ca6e to your computer and use it in GitHub Desktop.
Датчик потока воды Sea YF-S201
// 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