NodeMCU With Water Sensor

I’m using a NodeMCU Esp8266:
https://www.amazon.com/HiLetgo-Internet-Development-Wireless-Micropython/dp/B010N1SPRK/ref=sr_1_1_sspa?ie=UTF8&qid=1531152843&sr=8-1-spons&keywords=arduino%2Bwifi&th=1
connected to a water sensor:
https://www.amazon.com/gp/product/B01N058HS6/ref=oh_aui_detailpage_o03_s01?ie=UTF8&psc=1

My goal is to set up the NodeMCU with the blynk app so that when the water sensor does not sense water it sends a notification to my phone. I’m new to blynk and I’m not sure how to approach this. The water sensor is currently connected to the A0 pin.

1 Like

Basically, you just need to monitor the Analog pin (A0), and when it falls below a certain value send notification. You can do this with coding, or by loading the BASIC BLYNK sketch and using EVENTOR.

I suggest you do a little reading of the DOCS, and search a little around the forum. I don’t think anyone is going to write the code for you. Although there may be some code floating around here if you take a look.

If after that you get hung up, post what you have tried, and we will see if we can get you pointed back in the right direction.

1 Like

Okay, thanks.

I have looked around and I am trying to follow this tutorial: https://www.youtube.com/watch?v=egGs_jSIKbc
How do I find out what type of sensor I have? In the tutorial she has a DHT11. How do I replace the code that has the defined pin?

Example Code: https://examples.blynk.cc/?board=NodeMCU&shield=ESP8266%20WiFi&example=More%2FDHT11

Note: I did not expect anyone to write the code for me, and I did try finding the answers to my questions.

The moisture sensor that you linked to outputs an analog value (0-1023) based on the amount of moisture it detects.

I would use THIS example.

And just change

Blynk.virtualWrite(V5, millis() / 1000);

to

Blynk.virtualWrite(V5, analogRead(A0) );

this will send the value of the sensor to Virtual pin 5.

You could then use Eventor to send a notification when the value passes a certain valve. Although this may lead to repeated notifications if the value bounces above/below this value.

If you send the notification using code, then you will want to have a “notification flag” as to not send repeated notifications when the value drops below the setpoint.

1 Like

Thanks so much! I got it to read the value and send the notification. One more question, can you see the notification when your not in the Blynk app?

Yes. But feel free to give it a try for yourself.

Okay I wrote some code according to some info I found.
Code 1:

Serial.printLn(w);
Blynk.virtualWrite(v5, w);

if(w < 600)(
  Blynk.notify("PAWB Alert - Your water bowl is empty!")
  )

In the code the w stands for water. I don’t know if the virtual write is necessary or not. I want to some how incorporate it into this code so I can send a notification to my phone.
Code 2:

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, analogRead(A0) );
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

Please help me combine code 1 and code 2.

As mentioned in my earlier post, we are not going to write the code for you (at least I am not). Search around this forum, and there are a lot of example/code for what you are trying to do (although some are using temp or other things instead of moisture, but basically the same idea). Once you get something put together I will be happy to take a look, and assist if possible.

HERE is a starting point (I am sure there are other things to search that will also lead to results).

If the coding aspect is too much, try using EVENTOR. For example, When V5 is less than 600, send notification.

I would also change the timer interval to like 5 minutes or something as checking every second is probably not necessary.

If you have been solved the issue, may i ask your code for other people like me?