Introduction: Flowmeter NodeMcu Counting Litres

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

1 NodeMcu

or (I prefer this one)

1 Breadboard (depends on the NodeMcu version, this works for the second one I mentioned above

3 breadboard cables, like this ones , you just need 3, so you can keep the rest for other projects.

All the code was developed in the Arduino IDE. (

In the end I made an example with ESPlorer using the LUA language to try to get the same results (

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 (

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, 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 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, 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:

Software 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


Tony_Alvarez made it!(author)2017-03-27

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.

BasavarajA1 made it!(author)2017-03-19

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?



mseromenho made it!(author)2017-03-19

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.

BasavarajA1 made it!(author)2017-03-19

Thank you..

AbhiB10 made it!(author)2017-02-09

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 ​

mseromenho made it!(author)2017-02-17

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

couscousbzh35 made it!(author)2016-07-06

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

mseromenho made it!(author)2016-07-16

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

couscousbzh35 made it!(author)2016-07-17


kokolisso made it!(author)2016-07-15

Felicidades... desde México!

mseromenho made it!(author)2016-07-16

Obrigado ;)

robertolam made it!(author)2016-06-20

Hi Manuel, nice and very usefull work!

mseromenho made it!(author)2016-06-20

Thanks :)

DIY+Hacks+and+How+Tos made it!(author)2016-06-18

Welcome to Instructables. Thanks for sharing.

mseromenho made it!(author)2016-06-19

Thanks! I hope I can help others with this, Instructables help me a lot in the past :)

About This Instructable




Bio: Student of the Dep. of Electrical Engineering, University of Algarve, Portugal
More by mseromenho:Flowmeter NodeMcu Counting Litres
Add instructable to: