Created
June 18, 2018 10:48
-
-
Save elktros/a1caed1f2a4c29756735678bfefa2eca to your computer and use it in GitHub Desktop.
Code for interfacing YF-S201 Water Flow Sensor with Arduino UNO.
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
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