Advertisement
pleasedontcode

Flow Monitoring rev_01

Jan 23rd, 2025
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Flow Monitoring
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-01-23 09:07:58
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a flow measurement system using the */
  21.     /* FlowSensor library to monitor water flow through */
  22.     /* the YF-B1 sensor, ensuring accurate readings and */
  23.     /* data logging for efficient water management. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <FlowSensor.h> // https://github.com/hafidhh/FlowSensor-Arduino
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void count(void); // Function prototype for counting pulses
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t Contador_de_agua_YF_B1_OUT_PIN = 4; // Updated pin definition to avoid hyphen
  38.  
  39. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  40. #define type YFS201 // Define the type of flow sensor
  41. FlowSensor Sensor(type, Contador_de_agua_YF_B1_OUT_PIN); // Create an instance of FlowSensor
  42.  
  43. unsigned long timebefore = 0; // Variable to store the last time measurement
  44. unsigned long reset = 0; // Variable to store the last reset time
  45.  
  46. // Interrupt service routine for counting pulses
  47. void count()
  48. {
  49.     Sensor.count(); // Call the count method of the FlowSensor
  50. }
  51.  
  52. void setup(void)
  53. {
  54.     Serial.begin(115200); // Initialize serial communication at 115200 baud rate
  55.     pinMode(Contador_de_agua_YF_B1_OUT_PIN, INPUT); // Set the flow sensor pin as input
  56.     Sensor.begin(count); // Initialize the flow sensor with the count function
  57. }
  58.  
  59. void loop(void)
  60. {
  61.     if (millis() - timebefore >= 1000) // Check if 1 second has passed
  62.     {
  63.         Sensor.read(); // Read the flow sensor data
  64.         Serial.print("Flow rate (L/minute) : "); // Print flow rate
  65.         Serial.println(Sensor.getFlowRate_m()); // Print flow rate in liters per minute
  66.         Serial.print("Volume (L) : "); // Print volume
  67.         Serial.println(Sensor.getVolume()); // Print total volume in liters
  68.         timebefore = millis(); // Update the timebefore variable
  69.     }
  70.  
  71.     // Reset Volume every minute
  72.     if (millis() - reset >= 60000) // Check if 60 seconds have passed
  73.     {
  74.         Sensor.resetVolume(); // Reset the volume counter
  75.         reset = millis(); // Update the reset variable
  76.     }
  77. }
  78.  
  79. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement