Advertisement
pleasedontcode

Flow Tracker rev_167

Dec 7th, 2023
71
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 Tracker
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-07 12:26:19
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* read flow meter and print on serial monitor. */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <FlowSensor.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t sens_YF_B1_OUT_PIN_D2 = 2;
  33.  
  34. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  35. const uint8_t VERDE_LED_PIN_D11 = 11;
  36. const uint8_t ROSSO_LED_PIN_D12 = 12;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. FlowSensor Sensor(YFS201, sens_YF_B1_OUT_PIN_D2);
  40. unsigned long timebefore = 0;
  41. unsigned long reset = 0;
  42.  
  43. void count()
  44. {
  45.   Sensor.count();
  46. }
  47.  
  48. void setup(void)
  49. {
  50.   // put your setup code here, to run once:
  51.   pinMode(sens_YF_B1_OUT_PIN_D2, INPUT);
  52.   pinMode(VERDE_LED_PIN_D11, OUTPUT);
  53.   pinMode(ROSSO_LED_PIN_D12, OUTPUT);
  54.  
  55.   Serial.begin(115200);
  56.   Sensor.begin(count);
  57. }
  58.  
  59. void loop(void)
  60. {
  61.   // put your main code here, to run repeatedly:
  62.   if (millis() - timebefore >= 1000)
  63.   {
  64.     Sensor.read();
  65.     Serial.print("Flow rate (L/minute) : ");
  66.     Serial.println(Sensor.getFlowRate_m());
  67.     Serial.print("Volume (L) : ");
  68.     Serial.println(Sensor.getVolume());
  69.     timebefore = millis();
  70.   }
  71.  
  72.   if (millis() - reset >= 60000)
  73.   {
  74.     Sensor.resetVolume();
  75.     reset = millis();
  76.   }
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement