Advertisement
pleasedontcode

**Flow Data** rev_01

Feb 12th, 2025
89
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 Data**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-02-12 15:00:52
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Utilize the YF-S201 flow sensor to measure liquid */
  21.     /* flow, with real-time readings */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /* START CODE */
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <FlowSensor.h>    // https://github.com/hafidhh/FlowSensor-Arduino
  28. #include <SoftwareSerial.h> // Include the necessary libraries
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t Caudalimetro_YF_S201_OUT_PIN_D2 = 2; // Corrected pin name to use underscores
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. // Create an instance of the FlowSensor class
  39. FlowSensor flowSensor(1, Caudalimetro_YF_S201_OUT_PIN_D2); // Assuming type 1 for YF-S201
  40.  
  41. void setup(void)
  42. {
  43.     // put your setup code here, to run once:
  44.     pinMode(Caudalimetro_YF_S201_OUT_PIN_D2, INPUT);
  45.    
  46.     // Initialize the serial monitor
  47.     Serial.begin(9600); // This line should be inside the setup function
  48.  
  49.     // Initialize the flow sensor
  50.     flowSensor.begin(countPulses); // Pass the function to count pulses
  51. }
  52.  
  53. // Function to count pulses from the flow sensor
  54. void countPulses()
  55. {
  56.     flowSensor.count(); // Increment pulse count
  57. }
  58.  
  59. void loop(void)
  60. {
  61.     // put your main code here, to run repeatedly:
  62.    
  63.     // Read flow rate and volume
  64.     flowSensor.read(); // Read the sensor data
  65.  
  66.     // Print flow rate and volume to the serial monitor
  67.     Serial.print("Flow Rate (L/min): ");
  68.     Serial.println(flowSensor.getFlowRate_m()); // Get flow rate in liters per minute
  69.     Serial.print("Total Volume (L): ");
  70.     Serial.println(flowSensor.getVolume()); // Get total volume in liters
  71.  
  72.     // Add a delay to prevent spamming the serial monitor
  73.     delay(1000); // This line is compatible
  74. }
  75.  
  76. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement