Advertisement
pleasedontcode

"Water Monitor" rev_01

Jun 14th, 2024
391
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 NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-06-14 12:06:51
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Design an Arduino project for water level */
  21.     /* detection and control using SoftwareSerial, Relay, */
  22.     /* and Sim800L libraries. The system should read */
  23.     /* float sensor data, manage a relay, and communicate */
  24.     /* water levels via GSM using the Sim800L module. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <SoftwareSerial.h> //https://github.com/plerup/espsoftwareserial
  29. #include <Relay.h> //https://github.com/rafaelnsantos/Relay
  30. #include <Sim800L.h> //https://github.com/vittorioexp/Sim800L-Arduino-Library-revised
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs(void);
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t floatSensorPin = 7; // Pin connected to the float sensor
  39. const uint8_t gsm_SIM800L_RING_PIN_D4 = 4;
  40.  
  41. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  42. const uint8_t gsm_SIM800L_RST_PIN_D3 = 3;
  43. const uint8_t gsm_SIM800L_DTR_PIN_D5 = 5;
  44.  
  45. /***** DEFINITION OF Software Serial *****/
  46. const uint8_t gsm_SIM800L_Serial_PIN_SERIAL_TX_A0 = A0;
  47. const uint8_t gsm_SIM800L_Serial_PIN_SERIAL_RX_A1 = A1;
  48. SoftwareSerial gsm_SIM800L_Serial(gsm_SIM800L_Serial_PIN_SERIAL_RX_A1, gsm_SIM800L_Serial_PIN_SERIAL_TX_A0);
  49.  
  50. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  51. /***** used to store raw data *****/
  52. bool gsm_SIM800L_RST_PIN_D3_rawData = 0;
  53. bool gsm_SIM800L_DTR_PIN_D5_rawData = 0;
  54.  
  55. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  56. /***** used to store data after characteristic curve transformation *****/
  57. float gsm_SIM800L_RST_PIN_D3_phyData = 0.0;
  58. float gsm_SIM800L_DTR_PIN_D5_phyData = 0.0;
  59.  
  60. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  61. Relay relay(2, true); // Initialize relay on pin 2, Normally Open
  62. Sim800L GSM(gsm_SIM800L_Serial); // Initialize Sim800L with SoftwareSerial
  63.  
  64. void setup(void)
  65. {
  66.   // put your setup code here, to run once:
  67.  
  68.   pinMode(floatSensorPin, INPUT); // Set float sensor pin as input
  69.   pinMode(gsm_SIM800L_RING_PIN_D4, INPUT_PULLUP);
  70.  
  71.   pinMode(gsm_SIM800L_RST_PIN_D3, OUTPUT);
  72.   pinMode(gsm_SIM800L_DTR_PIN_D5, OUTPUT);
  73.  
  74.   gsm_SIM800L_Serial.begin(9600); // Initialize SoftwareSerial for GSM module
  75.  
  76.   relay.begin(); // Initialize the relay
  77.  
  78.   GSM.begin(9600); // Initialize the GSM module with a baud rate of 9600
  79.   char* text = "System Initialized";
  80.   char* number = "2926451386";
  81.   bool error = GSM.sendSms(number, text); // Send an initialization SMS
  82. }
  83.  
  84. void loop(void)
  85. {
  86.   // put your main code here, to run repeatedly:
  87.  
  88.   updateOutputs(); // Refresh output data
  89.   relay.loop(); // Update relay state
  90.  
  91.   // Read float sensor data
  92.   bool waterLevelHigh = digitalRead(floatSensorPin);
  93.  
  94.   if (waterLevelHigh) {
  95.     relay.turnOn(); // Turn relay on if water level is high
  96.     GSM.sendSms("2926451386", "Water level is high!"); // Send SMS alert
  97.   } else {
  98.     relay.turnOff(); // Turn relay off if water level is low
  99.   }
  100.  
  101.   delay(1000); // Delay for a second before next loop iteration
  102. }
  103.  
  104. void updateOutputs()
  105. {
  106.   digitalWrite(gsm_SIM800L_RST_PIN_D3, gsm_SIM800L_RST_PIN_D3_rawData);
  107.   digitalWrite(gsm_SIM800L_DTR_PIN_D5, gsm_SIM800L_DTR_PIN_D5_rawData);
  108. }
  109.  
  110. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement