How to connect water flow sensor using arduino with coading

By Aman kumar
Sat, 23-Nov-2019, 17:01

f


Water Flow Sensor Measure on 16x2 LCD Display

Water Flow Sensor Measure on 16x2 LCD Display © GPL3+

In this project, use the YF-S201 1/2-inch water flow sensor to measure the water flow rate (L/min) and display it on an LCD.

  • 6,054 VIEWS
  • 2 COMMENTS
  • 8 RESPECTS

COMPONENTS AND SUPPLIES

APPS AND ONLINE SERVICES

ABOUT THIS PROJECT

CODE

water flow sensor measuring flow rate on LCD 16 x 2 DisplayC/C++
#include 
const int rs = 4, en = 5, d4 = 6, d5 = 7, d6 = 8, d7 = 9;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
byte statusLed    = 13;

byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 3;


float calibrationFactor = 7.5;

volatile byte pulseCount;  

float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;

unsigned long oldTime;

void setup()
{

   
  // Set up the status LED line as an output
  pinMode(statusLed, OUTPUT);
  digitalWrite(statusLed, HIGH); 
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;

  // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
  // Configured to trigger on a FALLING state change (transition from HIGH
  // state to LOW state)
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}

/**
 * Main program loop
 */
void loop()
{
   
   if((millis() - oldTime) > 1000)    // Only process counters once per second
  { 
    
    detachInterrupt(sensorInterrupt);
        
    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output. We also apply the calibrationFactor to scale the output
    // based on the number of pulses per second per units of measure (litres/minute in
    // this case) coming from the sensor.
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    
    // Note the time this processing pass was executed. Note that because we've
    // disabled interrupts the millis() function won't actually be incrementing right
    // at this point, but it will still return the value it was set to just before
    // interrupts went away.
    oldTime = millis();
    
    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres = (flowRate / 60) * 1000;
    
    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres += flowMilliLitres;
      
    unsigned int frac;
    
  lcd.begin(16, 2);
  lcd.print(" Flow Rate");
  lcd.setCursor(1, 1);
  lcd.print(flowRate);
  lcd.setCursor(6, 1);
  lcd.print("L/Min");
    
    

    // Reset the pulse counter so we can start incrementing again
    pulseCount = 0;
    
    // Enable the interrupt again now that we've finished sending output
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  }
}

/*
I.S.R.
 */
void pulseCounter()
{
  // Increment the pulse counter
  pulseCount++;
}

Related Updates

This site was designed with Websites.co.in - Website Builder

IMPORTANT NOTICE
DISCLAIMER

This website was created by a user of Websites.co.in, a free instant website builder. Websites.co.in does NOT endorse, verify, or guarantee the accuracy, safety, or legality of this site's content, products, or services. Always exercise caution—do not share sensitive data or make payments without independent verification. Report suspicious activity by clicking the report abuse below.

WhatsApp Google Map
×

Caution! Unverified Website!


The identity of this user has not yet been verified. Please make transactions at your own risk!

Safety and Abuse Reporting

Thanks for being awesome!

We appreciate you contacting us. Our support will get back in touch with you soon!

Have a great day!

Are you sure you want to report abuse against this website?

Please note that your query will be processed only if we find it relevant. Rest all requests will be ignored. If you need help with the website, please login to your dashboard and connect to support

;