Another illustration on ESP8266 12/12E as smart metering using liquid/Water flow sensor. Water flow sensor is capable of measuring flows in pipes from 0.15 to 60 liters per minute, suitable for measuring water consumption or detecting pipe leakage and monitoring agricultural irrigation.
Smart Metering often refers to monitor the supply of water, however highly reliable smart metering cannot only be used for managing utility supplies but also brings benefits to managing liquid storage, inventories such as grain in silos and movement of goods., coffee machines and cola dispenser. Etc.
As you can see the diagram below we demonstrate how t and wire the ESP8266 12/12E together with the water/liquid flow sensor. For integration in Arduino IDE please refer to this link and For flashing using NodeMCU to ESP8266 01 or Flashing with ESP8266 Download Tool just follow this link. Below you can download the binary file ai-thinker-v1.1.1.bin running at baud rate 11520. if you are using MAC OS refer to this link Note: The AT command must be end with “\r\n”. For Arduino, must type the AT command like this > Serial1.print(“AT+GMR\r\n”);
Components Required
- ESP8266 12, 12E, ESP8266 NodeMCU, ESPDuino, WeMos.
- Liquid / Water Flow Sensor
- 5V Regulator (L7805)
- 3.3v Regulator (AMS1117)
- Capacitor
- Resistors
- Solder Less Breadboard
- LED 3mm (Red, Green)
- Male Pin
- Jumper Wires / DuPont Wires
- Tactile Push Button
Wiring Guide
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
#include <ESP8266WiFi.h> //Library can be download below #include <WiFiClient.h> //Library can be downloaded below #include <ESP8266WebServer.h> //Library can be downloaded below #include <PubSubClient.h> int sensorPin1 = 5; //int flowPin2 = 4; //int flowPin3 = 3; //int flowPin4 = 2; unsigned long flow1count = 0; unsigned long flow2count = 0; #define countof(a) (sizeof(a) / sizeof(a[0])) /* Connecting to existing wifi AP Network */ //char ssid[] = "14CORE"; // your network SSID (name) //char password[] = "we do what we must, because we can"; // your network password /* Make you own stand alone wifi networ accesspoint*/ const char* ssid = "14CORE"; const char* password = "1234567890"; // Set your IP address for your suitable for your network IP/SEGMENT IPAddress server(192, 168, 4, 100); PubSubClient client(server); String webString = "14CORE | Water Flow Sensor with ESP8266"; // String to display // Callback function void callback(const MQTT::Publish& pub) { if(pub.payload_string().equals("flow1")) { webString = "Flow 2: " + String(flow1count/450.0) + " L"; // Arduino has a hard time with float to string client.publish("outTopic",webString); } else if(pub.payload_string().equals("flow2")) { webString = "Flow 2: " + String(flow2count/450.0) + " L"; client.publish("outTopic",webString); // send to someones browser when asked } else Serial.print("14CORE | Flow Sensor ") Serial.print("Flow 1 in Liters: "); Serial.print(flow1count/450.0); Serial.print("\tFlow 2 in Liters: "); Serial.print(flow2count/450.0); Serial.print("\tFlow 1 in pulses: "); Serial.print(flow1count); Serial.print("\tFlow 2 in pulse: "); Serial.println(flow2count); delay(500); { } Serial.print(pub.topic()); Serial.print(" => "); Serial.println(pub.payload_string()); } void setup() { Serial.begin(115200); pinMode(sensorPin1, INPUT_PULLUP); attachInterrupt(sensorPin1, flow1, CHANGE); pinMode(flowPin2, INPUT_PULLUP); attachInterrupt(flowPin2, flow2, CHANGE); client.set_callback(callback); // Connect to existing wifi network WiFi.begin(ssid, password); Serial.print("\n\r \n\rWorking to connect"); // Wait 5mili for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("Connecting ") Serial.print("."); } Serial.println(""); Serial.print Serial.println("14CORE | ESP8266 Server"); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); if (client.connect("14CORE | ESP8266 Liquid Flow Sensor")) { client.publish("outTopic","flow boot up"); client.subscribe("inTopic"); } } void loop() { client.loop(); } void flow1() { flow1count +=1; } void flow2() { flow2count +=1; } |
Downloads
- Download ESP8266 WifiClient & ESP8266Wifi | Zip
- Download Arduino Client for MQTT PubSubClient | Zip
- Download ESP8266 WebServer | Zip
- Download ESP8266 Flash Tool | Link
- Download NodeMCU Flash Software | Link
Has anyone gotten this to work lately? I get a long list of compiler errors with this code.
no matching function for call to ‘PubSubClient::PubSubClient(IPAddress&)’
I tried to interface the waterflow sensor with node mcu but compile error was present and i download latest json code and installed node mcu library but why the compile error was occurred i don’t know please can any one clarify me.