Water Level Monitoring With NB-IOT & Email Alarts
by Lan_Makerfabs in Workshop > Home Improvement
184 Views, 2 Favorites, 0 Comments
Water Level Monitoring With NB-IOT & Email Alarts
Recently, I have to take business trip and for a long period of time, which makes me a bit worried about not being able to keep an eye on my fish tank, my fish have been with me through a lot of product development time, and they're like family members who can't talk.
So I used Maduino Zero LTE NBIOT SIM7080G and a non-contact liquid level sensor created a small device that can check the water level every day and send me the data by email, so that I can know the changes in the water level of my fish tank and accordingly decide whether it needs to be added to or change the water in the fish tank.
Supplies
- 1 x Maduino Zero LTE NBIOT SIM7080G
- 1 x Non-contact liquid level sensor
- 1 x IOT SIM Card that support NB-IOT
Hardware
1.Connect the non-contact level sensor to the Maduino.
Please note:
- Red wire : Power ,connects to Maduino 3.3V
- Black wire: GND to Maduino GND
- White wire: Data, connects to Maduino D9.
2.Insert the IOT sim card
3.Attach the sensor to the outer layer of the fish tank, this sensor detects precisely the water level, with any tank material(except metal), max thickness 5mm;
4.Connecting the power supply and antenna
Software
Code :
1.Email setting:
Open water_dect_demo.ino .Modify the macro definition as follow:
EMAIL_SERVER SMTP : server address
EMAIL_ID : LOGIN_ID
EMAIL_POP_PWD : EMAIL POP3 Password
FROM_NAME : Sender's name
FROM_ADD : Sender's e-mail address
TO_NAME : Recipient's name
TO_ADD : Recipient’s e-mail address
2.initialize the NB-IOT SIM7080:
// AT init
sendData("AT", 1000, DEBUG);
sendData("AT+CPIN?", 1000, DEBUG);
sendData("AT+CCID", 1000, DEBUG);
sendData("AT+CSQ", 1000, DEBUG);
sendData("AT+COPS?", 1000, DEBUG);
sendData("AT+CGATT?", 1000, DEBUG);
sendData("AT+CNACT=0,1", 1000, DEBUG);
sendData("AT+CNACT?", 1000, DEBUG);
sendData("AT+CPSI?", 1000, DEBUG);
}
3.Sensor monitor
When there no water detected, it output voltage high:
void sensor_read()
{
if (digitalRead(SENSOR_PIN) == LOW)
{
sensor_flag = 1;
SerialUSB.println("Low, have water");
}
else
{
sensor_flag = 0;
SerialUSB.println("High, no water");
}
}
4. If no-water detected, it send email:
void email_task()
{
String temp = "";
sendData("AT+EMAILCID=0", 1000, DEBUG);
sendData("AT+EMAILTO=30", 1000, DEBUG);
// Your mail server port
temp = temp + "AT+SMTPSRV=\"" + EMAIL_SERVER + "\",25";
sendData(temp, 1000, DEBUG);
// Your email id and smtp password not email password
temp = "";
temp = temp + "AT+SMTPAUTH=1,\"" + EMAIL_ID + "\",\"" + EMAIL_POP_PWD + "\"";
sendData(temp, 1000, DEBUG);
// Sender Address
temp = "";
temp = temp + "AT+SMTPFROM=\"" + FROM_ADD + "\",\"" + FROM_NAME + "\"";
sendData(temp, 1000, DEBUG);
// Recipient Address
temp = "";
temp = temp + "AT+SMTPRCPT=0,0,\"" + TO_ADD + "\",\"" + TO_NAME + "\"";
sendData(temp, 1000, DEBUG);
if (sensor_flag == 1)
{
// Subject
sendData("AT+SMTPSUB=\"Water full\"", 1000, DEBUG);
// Set body length
sendData("AT+SMTPBODY=12", 1000, DEBUG);
// Set body
sendData("Water full.\n\r", 1000, DEBUG);
}
else
{
// Subject
sendData("AT+SMTPSUB=\"Water empty\"", 1000, DEBUG);
// Set body length
sendData("AT+SMTPBODY=13", 1000, DEBUG);
// Set body
sendData("Water empty.\n\r", 1000, DEBUG);
}
// Send
sendData("AT+SMTPSEND", 1000, DEBUG);
}
The source can be download at : our github
Program Maduino board ;
Result
As you can see in the picture above, this device works great. I can detect changes in the water level of my fish tank everyday by email while I'm in business trip,in this way I'll know when it's time to refill the tank.As you can see, it's time for me to refill it.
If you are intersted in it, you can try doing it yourself.