Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Flow Monitoring
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-01-23 09:07:58
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Implement a flow measurement system using the */
- /* FlowSensor library to monitor water flow through */
- /* the YF-B1 sensor, ensuring accurate readings and */
- /* data logging for efficient water management. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <FlowSensor.h> // https://github.com/hafidhh/FlowSensor-Arduino
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void count(void); // Function prototype for counting pulses
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Contador_de_agua_YF_B1_OUT_PIN = 4; // Updated pin definition to avoid hyphen
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- #define type YFS201 // Define the type of flow sensor
- FlowSensor Sensor(type, Contador_de_agua_YF_B1_OUT_PIN); // Create an instance of FlowSensor
- unsigned long timebefore = 0; // Variable to store the last time measurement
- unsigned long reset = 0; // Variable to store the last reset time
- // Interrupt service routine for counting pulses
- void count()
- {
- Sensor.count(); // Call the count method of the FlowSensor
- }
- void setup(void)
- {
- Serial.begin(115200); // Initialize serial communication at 115200 baud rate
- pinMode(Contador_de_agua_YF_B1_OUT_PIN, INPUT); // Set the flow sensor pin as input
- Sensor.begin(count); // Initialize the flow sensor with the count function
- }
- void loop(void)
- {
- if (millis() - timebefore >= 1000) // Check if 1 second has passed
- {
- Sensor.read(); // Read the flow sensor data
- Serial.print("Flow rate (L/minute) : "); // Print flow rate
- Serial.println(Sensor.getFlowRate_m()); // Print flow rate in liters per minute
- Serial.print("Volume (L) : "); // Print volume
- Serial.println(Sensor.getVolume()); // Print total volume in liters
- timebefore = millis(); // Update the timebefore variable
- }
- // Reset Volume every minute
- if (millis() - reset >= 60000) // Check if 60 seconds have passed
- {
- Sensor.resetVolume(); // Reset the volume counter
- reset = millis(); // Update the reset variable
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement