Water Level Monitoring With NB-IOT & Email Alarts

by Lan_Makerfabs in Workshop > Home Improvement

205 Views, 2 Favorites, 0 Comments

Water Level Monitoring With NB-IOT & Email Alarts

QQ图片20240430141742.jpg


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

微信图片_20240429145729.jpg

Hardware

IMG20240429102723.jpg
图片1.png
水位线.jpg
水位线.png
图片2.png

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

图片3.png


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

图片4.png
QQ图片20240430141806.jpg

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.