Advertisement
pleasedontcode

Water Monitor rev_01

Mar 3rd, 2024
93
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: Water Monitor
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2024-03-03 19:18:51
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* using an ili9341 tft lcd to monitor a water tank. */
  21.     /* The code uses input from an ultrasound sensor to */
  22.     /* detect the level of the water surface then */
  23.     /* calculates the volume of water present based on */
  24.     /* the tank parameters set a */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Ultrasonic.h>
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup();
  32. void loop();
  33. void updateOutputs();
  34. float calculateWaterVolume(float distance);
  35. void monitorWaterLevel();
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t Water_Level_Probe_HC_SR04_Echo_PIN_D3 = 3;
  39.  
  40. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  41. const uint8_t Water_Level_Probe_HC_SR04_Trigger_PIN_D2 = 2;
  42.  
  43. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  44. /***** used to store raw data *****/
  45. bool Water_Level_Probe_HC_SR04_Trigger_PIN_D2_rawData = 0;
  46.  
  47. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  48. /***** used to store data after characteristic curve transformation *****/
  49. float Water_Level_Probe_HC_SR04_Trigger_PIN_D2_phyData = 0.0;
  50.  
  51. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  52. Ultrasonic ultrasonic(Water_Level_Probe_HC_SR04_Trigger_PIN_D2, Water_Level_Probe_HC_SR04_Echo_PIN_D3);
  53.  
  54. void setup() {
  55.   // put your setup code here, to run once:
  56.   pinMode(Water_Level_Probe_HC_SR04_Echo_PIN_D3, INPUT);
  57.   pinMode(Water_Level_Probe_HC_SR04_Trigger_PIN_D2, OUTPUT);
  58. }
  59.  
  60. void loop() {
  61.   // put your main code here, to run repeatedly:
  62.   updateOutputs(); // Refresh output data
  63.  
  64.   // Monitor the water level and update the TFT LCD
  65.   monitorWaterLevel();
  66.  
  67.   // Delay for a certain period of time
  68.   delay(1000);
  69. }
  70.  
  71. void updateOutputs() {
  72.   digitalWrite(Water_Level_Probe_HC_SR04_Trigger_PIN_D2, Water_Level_Probe_HC_SR04_Trigger_PIN_D2_rawData);
  73. }
  74.  
  75. /* Calculate volume of water based on tank parameters */
  76. float calculateWaterVolume(float distance) {
  77.   // Replace with your code to calculate the volume based on tank parameters
  78.   float volume = 0.0;
  79.   // Perform necessary calculations
  80.  
  81.   return volume;
  82. }
  83.  
  84. void monitorWaterLevel() {
  85.   // Read the water level from the ultrasonic sensor
  86.   float distance = ultrasonic.read();
  87.  
  88.   // Calculate the water volume based on the distance
  89.   float volume = calculateWaterVolume(distance);
  90.  
  91.   // Display the water level and volume on the TFT LCD
  92.   // Replace with your code to display the data on the TFT LCD
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement