Advertisement
pleasedontcode

**Sensor Data** rev_02

Nov 8th, 2024
69
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: **Sensor Data**
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-11-08 07:16:01
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The FISH_POND_MONITORING project aims to automate */
  21.     /* fish pond monitoring by integrating sensors for */
  22.     /* water quality, temperature, and fish activity, */
  23.     /* ensuring optimal conditions for aquatic life. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <FlowSensor.h>    //https://github.com/hafidhh/FlowSensor-Arduino
  30. #include <DHT.h>           //https://github.com/adafruit/DHT-sensor-library
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t Water_flow_YF_S201_OUT_PIN_D4        = 4;
  38. const uint8_t Temp_humidity_DHT11_DOUT_PIN_D13      = 13;
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. // Flow sensor instance
  42. FlowSensor flowSensor(1, Water_flow_YF_S201_OUT_PIN_D4); // Assuming type 1 for the flow sensor
  43. // DHT sensor instance
  44. DHT dht(Temp_humidity_DHT11_DOUT_PIN_D13, DHT11); // Using DHT11 for temperature and humidity
  45.  
  46. void setup(void)
  47. {
  48.     // Initialize serial communication for debugging
  49.     Serial.begin(9600);
  50.    
  51.     // Initialize sensors
  52.     flowSensor.begin(flowSensor.count);
  53.     dht.begin();
  54.    
  55.     // Set pin modes
  56.     pinMode(Water_flow_YF_S201_OUT_PIN_D4, INPUT);
  57.     pinMode(Temp_humidity_DHT11_DOUT_PIN_D13, INPUT_PULLUP);
  58. }
  59.  
  60. void loop(void)
  61. {
  62.     // Read flow rate and volume from the flow sensor
  63.     flowSensor.read();
  64.     float flowRate = flowSensor.getFlowRate_m(); // Get flow rate in liters/minute
  65.     float volume = flowSensor.getVolume(); // Get total volume in liters
  66.  
  67.     // Read temperature and humidity from the DHT sensor
  68.     float temperature = dht.readTemperature(); // Read temperature in Celsius
  69.     float humidity = dht.readHumidity(); // Read humidity in percentage
  70.  
  71.     // Print sensor data to the Serial Monitor
  72.     Serial.print("Flow Rate: ");
  73.     Serial.print(flowRate);
  74.     Serial.println(" L/min");
  75.    
  76.     Serial.print("Total Volume: ");
  77.     Serial.print(volume);
  78.     Serial.println(" L");
  79.    
  80.     Serial.print("Temperature: ");
  81.     Serial.print(temperature);
  82.     Serial.println(" °C");
  83.    
  84.     Serial.print("Humidity: ");
  85.     Serial.print(humidity);
  86.     Serial.println(" %");
  87.    
  88.     // Add a delay before the next reading
  89.     delay(2000); // Delay for 2 seconds
  90. }
  91.  
  92. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement