Hello there,
I am in process of making a remote water tank monitoring system. ( I have just installed frizzing and will update this topic later with the circuit diagram. I am very new to arduino (read 1 week since I have received my first Nano and started tinkering)
Suffice to say, from a hardware perspective all is working and correctly connected. as I get the SMS messages.
Textually, this is the function of the project.
Components Used.
LC1BD04
The water in the tank is monitored by means of a LC1BD04 sensor. This sensor sets a pin to High when the water is detected, and LOW when no water is detected. I have chosen for this sensor above the UltraSonic sensor and Pressure sensors for various reasons. suffice to say, I have thought this through.
SIM800L
This is used to send sms messages to me regarding the water level as measured by LC1BD04. it is connected to a laboratory power supply at the moment, and receiving sms messages, so power is not a problem.
DS1307
This RTC is used to send a message at a specific time. in this case 08:00 in the morning.
This is the idea.
The water is measured constantly. when there is a change in status of the water tank the LC1BD04 will set the pin value accordingly, and a sms is sent to a predefined number with SIM800. In addition to the status change messages, there will be a SMS sent every morning at a predefined time with the status of the tank at that point in time.
Here is the code that I have currently:
#include <SoftwareSerial.h>
#include <Wire.h>
#include <RTClib.h>
SoftwareSerial mySerial(6, 5); // RX D6 closest to earth on GSM Module, TX
int prevPin10 = LOW;
int prevPin11 = LOW;
int prevPin12 = LOW;
int prevPin13 = LOW;
char phone_number[] = "+31615553214"; // Replace with your phone number
char message[150];
RTC_DS1307 rtc;
void setup() {
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
Serial.begin(9600);
mySerial.begin(9600); // Initialize the software serial communication with the GSM module
Wire.begin(); // Initialize the I2C bus
rtc.begin(); // Initialize the RTC module
}
void loop() {//Read the digital pin values. If the PIN=HIGH then there is water.
int pin10 = digitalRead(10);// This is the Quarter Pin. on the Hardware Pin 10
int pin11 = digitalRead(11);// This is the Half Pin. on the Hardware Pin 11
int pin12 = digitalRead(12);// This is the Three Quarter Pin. on the Hardware Pin 12
int pin13 = digitalRead(13);// This is the full Pin. on the Hardware Pin 13
//Debug infomration to get pin status
//Serial.println(pin10);
//Serial.println(pin11);
//Serial.println(pin12);
//Serial.println(pin13);
//Serial.println("");
if (pin13 == HIGH && pin12 == HIGH && pin11 == HIGH && pin10 == HIGH) {
sprintf(message, "[%04d-%02d-%02d %02d:%02d:%02d] Tank is full", rtc.now().year(), rtc.now().month(), rtc.now().day(), rtc.now().hour(), rtc.now().minute(), rtc.now().second());
} else if (pin13 == LOW && pin12 == HIGH && pin11 == HIGH && pin10 == HIGH) {
sprintf(message, "[%04d-%02d-%02d %02d:%02d:%02d] Tank is three quarter", rtc.now().year(), rtc.now().month(), rtc.now().day(), rtc.now().hour(), rtc.now().minute(), rtc.now().second());
} else if (pin13 == LOW && pin12 == LOW && pin11 == HIGH && pin10 == HIGH) {
sprintf(message, "[%04d-%02d-%02d %02d:%02d:%02d] Tank half", rtc.now().year(), rtc.now().month(), rtc.now().day(), rtc.now().hour(), rtc.now().minute(), rtc.now().second());
} else if (pin13 == LOW && pin12 == LOW && pin11 == LOW && pin10 == HIGH) {
sprintf(message, "[%04d-%02d-%02d %02d:%02d:%02d] Tank is quarter", rtc.now().year(), rtc.now().month(), rtc.now().day(), rtc.now().hour(), rtc.now().minute(), rtc.now().second());
} else if (pin13 == LOW && pin12 == LOW && pin11 == LOW && pin10 == LOW) {
sprintf(message, "[%04d-%02d-%02d %02d:%02d:%02d] Tank is empty", rtc.now().year(), rtc.now().month(), rtc.now().day(), rtc.now().hour(), rtc.now().minute(), rtc.now().second());
} else
{
}
//Serial.println(message);
// Check if the status has changed,
if (pin10 != prevPin10 || pin11 != prevPin11 || pin12 != prevPin12 || pin13 != prevPin13) {
//sprintf(message, "[%04d-%02d-%02d %02d:%02d:%02d]", rtc.now().year(), rtc.now().month(), rtc.now().day(), rtc.now().hour(), rtc.now().minute(), rtc.now().second());
Serial.println(message); // Print the message to the serial monitor
// Send an SMS
mySerial.println("AT+CMGF=1"); // Set the SMS mode to text mode
delay(100);
mySerial.print("AT+CMGS=\"");
mySerial.print(phone_number);
mySerial.println("\""); // Set the phone number
delay(100);
mySerial.println(message); // Set the SMS message
delay(100);
mySerial.println((char)26); // Send the SMS message
delay(1000);
//Check if the SMS was sent successfully
if (mySerial.find("OK")) {
Serial.println("Message sent successfully!");
} else {
Serial.println("Error sending message");
}
//Set new Water level Values to default
prevPin10 = pin10;
prevPin11 = pin11;
prevPin12 = pin12;
prevPin13 = pin13;
Serial.println("Delay after SMS being sent for 10 Minutes");
delay(600000); // Wait for 10 minutes before checking again
}
Serial.println("Delay for 20 Minutes on no change");
delay(1200000);
// Check if it's 8 in the morning
DateTime now = rtc.now();
if ((now.hour() == 8 )) {
//sprintf(message, "[%04d-%02d-%02d %02d:%02d:%02d]", rtc.now().year(), rtc.now().month(), rtc.now().day(), rtc.now().hour(), rtc.now().minute(), rtc.now().second());
Serial.println(message);
// Send an SMS
//mySerial.println("AT+CMGF=1"); // Set the SMS mode to text mode
//delay(100);
//mySerial.print("AT+CMGS=\"");
//mySerial.print(phone_number);
//mySerial.println("\""); // Set the phone number
//delay(100);
//mySerial.println(message); // Set the SMS message
//delay(100);
//mySerial.println((char)26); // Send the SMS message
//delay(1000);
//Check if the SMS was sent successfully
if (mySerial.find("OK")) {
Serial.println("Message sent successfully!");
} else {
Serial.println("Error sending message");
Serial.println("Timestamp sms have just been sent");
}
//Set new Water level Values to default
prevPin10 = pin10;
prevPin11 = pin11;
prevPin12 = pin12;
prevPin13 = pin13;
Serial.println("Delay after Daily SMS of 23 hours 58 min before checking Time again");
delay(3540000); // Wait for 59 min minutes before checking again
}
}
Problems I need help with.
This morning I did not get my morning message as expected. My nano was connected to the PC for power, but Arduino IDE was closed. AS soon as I connected the IDE I received a text, which seems to indicate hardware wise it seems to be functioning correctly,
1a. I only get the messages when the nano is connected by USB to the PC. could it be that the code is not stored in the Nano?
1b. it could also be that the Nano needs to have the serial monitor connected in order to process the code?
Notes for point 1. when the nano is connected to the IDE and it get to the specific time (08:00) the message is sent, and received.
- I want to ultimately connect this system to solar and batteries using 2 x 18650 lithium batteries in parallel to power the system. the challenge is that I need 7-12V for the Nano (the LC1BD04 definitely needs 5V to operate. The SIM800 needs 4V to operate. I have a solar panel (6V18W) that can charge the batteries in Parallel, so I need a DC DC boost converter to power the Nano and LC1BD04. can anyone recommend one that can be used?