Flowmeter NodeMcu Counting Litres

38,073

50

27

Introduction: Flowmeter NodeMcu Counting Litres

About: Student of the Dep. of Electrical Engineering, University of Algarve, Portugal

This work aims to build an Internet based system that enables the remote monitoring of a water/flow meters.

Motivation: In a house or building it is very important to regularly analyze the consumption of water and thus take action, avoiding unnecessary costs. The possibility of track/control multiple points of water through a single web page is enabled by this project, or even the automatic cut of water supply when detecting a flooding.

In this project, the monitoring can be done locally or remotely, this way you can generate alerts programmatically in order to warn the administrator about an over-consumption in any part of a building. All data generated is sent and registered in both a local "web server" as a remote database (Emoncms or Thingspeak).

The measurements of the water consumption are stored in the EEPROM of the ESP8266. It is then displayed in a Web page and transmitted to IoT platforms.

Step 1: What's Needed?

For this work, it's needed:

1 Flowmeter http://pt.aliexpress.com/item/New-Black-G1-2-Wate...

1 NodeMcu http://pt.aliexpress.com/item/NodeMcu-Lua-WIFI-dev...

or http://pt.aliexpress.com/item/V2-4M-4FLASH-NodeMcu... (I prefer this one)

1 Breadboard (depends on the NodeMcu version, this works for the second one I mentioned above http://pt.aliexpress.com/item/400-Tie-Point-Interl...)

3 breadboard cables, like this ones http://pt.aliexpress.com/item/Free-shipping-Dupon... , you just need 3, so you can keep the rest for other projects.

All the code was developed in the Arduino IDE. (https://www.arduino.cc/en/Main/Software)

In the end I made an example with ESPlorer using the LUA language to try to get the same results (http://esp8266.ru/esplorer/)

The hardware connection is done by attaching 3 cables (jumper cables) between the flowmeter and the nodemcu, in order to get the on/off pulse generated by the flow of water and thus count for the litres *.

Cable connections (use the breadboard cables, male-to-male) :

  • Connect the red cable output from the flowmeter to the 3.3v pin on the nodemcu.
  • Connect the black cable output from the flowmeter to "ground" on the nodemcu.
  • Connect the yellow cable output from the flowmeter to the control pin on the nodemcu (in my case the D2 pin)

And that's it for a start, so the next step is to program the nodemcu (control of the litres passing in the flowmeter).

Note: Before any code, you may need to flash new firmware into the NodeMcu, use ESP8266Flasher (https://github.com/nodemcu/nodemcu-flasher).

I did 3 examples that I will show in the next steps, but I will only show the code for the first one.

*The flowmeter specs indicate that +/- 440 "pulses" is equivalent to 1 litre.

Step 2: Example1

In this first example, we have:

  • Litres counting in the serial monitor of the Arduino IDE;
  • Setup of a webserver in the ESP8266, where the data from the litre consumption is shown in response to an HTTP request. The access to the webserver can be done inside the network or from outside, requiring the corresponding setup of the Wi-Fi router.

  • Through an HTTP GET request, the total number of litres is sent to an external server (ThingSpeak). With that info a plot is shown in the ThingSpeak platform (see https://thingspeak.com/channels/120470), that can be accessed in any Internet terminal and analysed at any time.

  • The possibility to use an "html iframe" in the local webserver to show the graphic from ThingSpeak(illustrated on the image above).

Attached is the full code for this example.

Step 3: Example 2

In this second example, we have:

  • Litres counting in the serial monitor of the Arduino IDE;
  • Through an HTTP GET request, the total number of litres is sent to an external server (Emoncms). With that info a graphic is created in EmonCms, (see http://emoncms.org/a21210&id=32359) that can be access remotely and analysed in real time.

The code for this example can be obtained by replacing the URL in example 1, with the one from the input API of emoncms.

Step 4: Example 3 (ThingSpeak Only)

In this third example, we have:

  • Litres counting in the serial monitor of the Arduino IDE;
  • Through an HTTP GET request, the total number of litres is sent to an external server (ThingSpeak). With that info a plot is shown in the ThingSpeak platform (see https://thingspeak.com/channels/120470), that can be accessed in any Internet terminal and analysed at any time. (Now illustrated by the ThingSpeak website page.)

The code for this example can be achieve by modifying very easily the code from the example 1.

Step 5: Example With ESplorer (LUA Code)

Attached there are some files with the LUA example code.

Some notes about ESplorer and LUA: when using ESplorer (Lua code) to work with NodeMcu, it is possible to send multiples files to its memory. On one hand that makes the software more modular, on the other hand we can have the possibility of storing html pages in NodeMcu memory, that can be called anytime on the code.

Useful links:

Lua Examples: https://learn.adafruit.com/adafruit-huzzah-esp8266...

Software ESPlorer : http://esp8266.ru/esplorer/

Step 6: Last Words...?

As in any other project, something fails...

The NodeMcu sent random stack errors, sometimes by failing to connect to the wifi network, or by using the function attachInterrupt.

When I was starting the code, I was using the library ESP8266WiFiMulti.h, and decided to swap for the library ESP8266WiFi.h, and the error started to appear less often.

Although I'm a bit better at coding than electronics (no knowledge at all :P ), I kept reading about this issues on the web, but no luck. I used 3 units of NodeMcu (2 different models), to check if the errors were coming from a faulty one, but it didn't make any difference.

Well maybe someone can show me where I failed?

Step 7: Useful Links

Be the First to Share

    Recommendations

    • Audio Challenge 2020

      Audio Challenge 2020
    • Maps Challenge

      Maps Challenge
    • Backyard Contest

      Backyard Contest

    27 Discussions

    0
    Abinesh07
    Abinesh07

    2 months ago on Step 4

    this is my error what i'm stuck with_ arduino.h library is missing no such dictionary found

    3
    EdsgerD
    EdsgerD

    8 months ago

    Great content sir. Can you please provide me the modified code for step 4 example 3 (thingspeak only)?

    0
    MangehE
    MangehE

    Question 12 months ago

    Hello. Please how can I create an acount on this webpage. Thanks

    0
    djgille12
    djgille12

    Question 1 year ago on Introduction

    Hello,

    Great project, I am working on an IOT project that would communicate water purity and flow to think speak so we know when our customers need service. I used your example as a starting point with the EsP8266NodeMCU but have not been able to connect to thing speak. My question is would my mobile phone hot spot cause connectivity issues.

    0
    NutthachaiY
    NutthachaiY

    1 year ago on Step 5

    I would like to know the information about connecting the flowsensor and netpie to the graph. Is there enough?
    0
    AbhiB10
    AbhiB10

    3 years ago

    hi,plz help me i am tring to connect my nodemcu and flow meter to thingspeak but it shows a msg of waiting for client.....msg

    i.e. it's not connecting to my thingspeak channel plz help ​

    0
    hcastillo1
    hcastillo1

    Reply 2 years ago

    Hi, did you find an answer for this issue? I have the same problem.

    0
    mseromenho
    mseromenho

    Reply 3 years ago

    Hi sorry for the late reply, is thingspeak well configed?

    0
    sameera.gamage999
    sameera.gamage999

    2 years ago

    please let me know how can i change this into a different thingspeak acount. please someone help me. this is urgent

    0
    hcastillo1
    hcastillo1

    Reply 2 years ago

    Hi, did you find a solution for this issue? I'm having similar problems.

    0
    IkramS2
    IkramS2

    2 years ago

    The detailed description of the code is well written.

    The issue I have is, the count of the litres continues always. How to restart it from Zero?

    0
    Tony_Alvarez
    Tony_Alvarez

    3 years ago

    Hola Compañero, esta muy bueno el proyecto, tengo ciertas dudas con respecto al hardware del Nodemcu, no pierdo nada en consultarte: Como alimentas el Nodemcu? Lo alimentas por el puerto USB con un cargador?? Sabes si se puede alimentar con un cargador de celular que saca 5 Voltios-1 Ampere? O lo quemaría? Quiero tener mi Nodemcu en un lugar fijo y no tengo claro como alimentarlo. No encuentro algún PDF donde me saquen de mis dudas, si supieras sobre documentación que me ayude.

    Te agradecería si pudieras ayudarme.

    Gracias de antemano.

    0
    BasavarajA1
    BasavarajA1

    3 years ago

    Thanks for sharing. I have one question though. I was looking at the specification of this flowmeter on one of the eBay seller. It said the below.

    The lowest rated working voltage: DC4.5 5V-24V

    Looks like you have connected it to 3.3v from NodeMCU. will that work effectively? will it put load on the NodeMCU?

    Thanks,

    Bas

    0
    mseromenho
    mseromenho

    Reply 3 years ago

    Hi Bas,

    Well this goes a bit out of my knowledge, I used the YF-S201 flowmeter that I bought from aliexpress, even if it shows 4.5 - 5v it worked with 3.3v. Sometimes the nodemcu would crash, but I cant be sure if this was the culprit.

    0
    BasavarajA1
    BasavarajA1

    Reply 3 years ago

    Thank you..

    0
    couscousbzh35
    couscousbzh35

    4 years ago

    i worked also with the esp8266, good and chip device, but not stable.

    0
    mseromenho
    mseromenho

    Reply 4 years ago

    Hi, do you know other similar device to NodeMcu but more stable?