IOT Water Quality monitoring using Arduino,pH Sensor,Nodemcu ESP8266
Table of Contents
IoT Water Quality Monitoring:
Water Quality Monitoring System using pH Sensor– In this Tutorial, you will learn how to make an IoT based water quality monitoring system using Arduino, pH Sensor, Nodemcu esp8266 wifi module and Blynk Application. As this is an IoT “Internet of Things” based project, the water quality can be monitored from anywhere around the world. In this tutorial, I will practically explain how to measure the pH value of the Well water, and I will also explain whether the water under test is good or bad for health. In this Tutorial, you will also learn how to use the 16×2 LCD widget in the Blynk application. This is Version2 of the pH sensor Water Quality Monitoring System.
Read our latest article on “ESP32 Hydroponic System using pH Sensor, EC Sensor, A02YYUW Waterproof Ultrasonic Sensor, DS18B20 waterproof one-wire digital temperature sensor, and Blynk application“.
Recently I uploaded the articles on
“Water quality monitoring using Turbidity Sensor and Arduino”.
“Arduino Hydroponics System” and
“Soil Nutrients Monitoring using NPK Sensor”
While in Version1 I covered the extreme basics like for example
- What is pH?
- How does a pH sensor work?
- How to measure the pH value of different liquids?
In version1 I also explained how to calibrate the pH sensor. So if you are using a pH sensor for the First time then I highly recommend first you should watch Version1 and then you can resume from here.
In this tutorial, we will cover
- Complete Circuit Diagram
- pH sensor Unboxing
- pH Sensor Pinout
- pH sensor and Nodemcu ESP8266 wifi module interfacing with Arduino.
- Arduino and Nodemcu Programming and finally
- Testing
Amazon Purchase Links:
Gravity: Analog pH Sensor / Meter Kit For Arduino by DFrobot:
Other Tools and Components:
Super Starter kit for Beginners
PCB small portable drill machines
DISCLAIMER:
Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
Circuit Diagram:
This is the circuit diagram of the Nodemcu esp8266 wifi module Power Supply. This Schematic is designed in cadsoft Eagle 9.1.0 version. This is 5v regulated Power supply which is used to power up the Nodemcu esp8266 wifi module. This Power Supply is based on the famous LM7805 voltage regulator. J1 is the female power jack and this is where we connect a 12v adaptor, battery, or a solar panel. Two 470uf capacitors are connected at the input and output sides of the voltage regulator. A 330-ohm resistor is connected in series with a 2.5v led. This is a current limiting resistor. The output of the voltage regulator is connected with the Vin pin of the Nodemcu esp8266 wifi module and the ground is connected with the ground. SV1 and SV2 are the female headers. The connections of the Nodemcu module and pH sensor will be explained during the interfacing.
This is the Final Power Supply board designed for powering up the Nodemcu ESP8266 wifi module. It’s PCB designing, online order placement, and Soldering is already explained in my previous tutorial.
High quality & Only 24 Hours Build time:
Download PCB Gerber Files from the PCBWay official website:
Download link of the Nodemcu library for cadsoft eagle:
Gerber files generation and online order placement:
This PCB is developed by the PCBWay Company. The PCB board file can be downloaded from my Website.
About the DFrobot pH Sensor kit:
This is the analog pH sensor kit from the DFrobot, DFrobot is a leading robotics and open source hardware provider. They create innovative, user-friendly hardware & software products that become the building blocks in all kinds of electronic projects. I personally recommend you should definitely visit www.dfrobot.com .
This pH sensor kit can be used in Water quality monitoring equipments, it can be used in the water tanks, Fish aquarium, this pH Sensor kit can be used with GSM, nodemcu esp8266 wifi module for remote notifications.
This pH sensor kit is best for measuring the water quality and other parameters. It has an LED that works as the Power Indicator, a pH sensor, a BNC connector, a variable resistor that is used for the calibration which I will explain during the testing and PH2.0 sensor interface circuit.
pH Sensor Kit Interfacing with Arduino:
For the step by step, interface connections watch the video Tutorial given at the end of this Article.
Connect the red wire with the Arduino’s 5v…
Connect the black wire with the Arduino’s Ground…
Connect the blue wire with the Arduino’s Analog pin A0.
Connect the TX and RX Pins of the Nodemcu ESP8266 wifi module with Pin number2 and Pin number3 of the Arduino.
Connect Ground Pin of the Nodemcu module with the Arduino’s ground.
Note: this old version of the Blynk app is no more functional. For the blynk mobile App setup and Blynk.cloud dashboard setup ready my article on the New Blynk V2.0. In this article I have explained how to migrate your projects from Blynk 1.0 to the new Blynk V2.0. You can also watch the video.
Blynk Application for the Water Quality Monitoring System:
- First of all, open the Blynk application.
- set the project name as pH meter.
- Click on the Choose device and select Nodemcu.
- Make sure you set the connection type to wifi and then click on the create button, an authentication token will be sent on your email id, which will be then used in the programming, simply copy and paste it in programming.
- Now click on the screen and search for the LCD widget and add it.
- Now Click on the LCD, Select Advanced.
- Click on the Pin and select Virtual Pin V2.
Our application is ready and now let’s discuss the programming.
IoT water Quality Monitoring Programming:
In this project two Programs are used, one program is written for the Arduino while the other Program is written for the Nodemcu ESP8266 wifi module. Let’s first of all start with the Arduino Programming.
Arduino Programming for the Water Quality Monitoring System:
This is the same Program I used in Version1 of the pH sensor water quality monitoring system. This time I made a few changes, I added these two libraries. The stdlib.h library has a standard function which is used for converting the float value into the String, while the softwareserial.h library is used for creating multiple Serial Ports. As I always say never use the Arduino’s default serial port for communication with other devices. As you know in Arduino we have only one Serial port which is on pin number 0 and pin number 1. The Arduino’s default Serial Port should only be used for debugging purposes.
Now the question is if we are using the Arduino’s default Serial port for the debugging purposes then how we will connect the Nodemcu Module with the Arduino? Well, no worries at all we can use the software serial library for creating multiple Serial Ports. So that’s the reason I added the software serial library and defined a Serial Port with the name Nodemcu on Pin number 2 and Pin number 3. So the Nodemcu module TX and RX Pins will be connected with the Arduino’s Pin number 2 and Pin number 3…
Another change that I made to the program is I added this function which is used to convert a float value into the String value. Then I added this String value along with the comma which is used as the delimiter. Finally, the String message is sent to the Nodemcu module and at the end, we empty the String for the new day.
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 |
#include <stdlib.h> #include <SoftwareSerial.h> SoftwareSerial nodemcu(2,3); #define SensorPin 0 //pH meter Analog output to Arduino Analog Input 0 unsigned long int avgValue; //Store the average value of the sensor feedback float b; int buf[10],temp; // for float value to string converstion int f; float val; // also works with double. char buff2[10]; String valueString = ""; String Value = ""; void setup() { pinMode(13,OUTPUT); Serial.begin(9600); nodemcu.begin(9600); } void loop() { for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value { buf[i]=analogRead(SensorPin); delay(10); } for(int i=0;i<9;i++) //sort the analog from small to large { for(int j=i+1;j<10;j++) { if(buf[i]>buf[j]) { temp=buf[i]; buf[i]=buf[j]; buf[j]=temp; } } } avgValue=0; for(int i=2;i<8;i++) //take the average value of 6 center sample avgValue+=buf[i]; float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt phValue=3.5*phValue; //convert the millivolt into pH value Value = dtostrf(phValue, 4, 2, buff2); //4 is mininum width, 6 is precision valueString = valueString + Value +","; Serial.println(valueString); nodemcu.println(valueString); valueString = ""; delay(1000); } |
Nodemcu Programming for the Water Quality Monitoring System:
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 |
/* * lcd.print(x,y,"messsage"); * where x is a symbol position(0 to 15) * y is a line number (0 or 1) * lcd.clear(); */ #define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> #include <SoftwareSerial.h> #include <SimpleTimer.h> WidgetLCD lcd(V2); String data; String I; char auth[] = "1748acab0e3c4c7baca832f4a9d9e3fb"; // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "ZONG MBB-E8231-6E63"; char pass[] = "electroniclinic"; SimpleTimer timer; String myString; // complete message from arduino, which consistors of snesors data char rdata; // received charactors // This function sends Arduino's up time every second to Virtual Pin (1). // 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(V1, millis() / 1000); } void setup() { // Debug console Serial.begin(9600); Blynk.begin(auth, ssid, pass); timer.setInterval(1000L,sensorvalue1); } void loop() { if (Serial.available() == 0 ) { Blynk.run(); timer.run(); // Initiates BlynkTimer } if (Serial.available() > 0 ) { rdata = Serial.read(); myString = myString+ rdata; Serial.print(rdata); if( rdata == '\n') { I = getValue(myString, ',', 0); myString = ""; // Serial.println(I); lcd.print(0,0,"pH Value:"); } } } void sensorvalue1() { data = data + I; lcd.print(0,0,"pH Value:"); lcd.print(0,1,data); data = ""; } String getValue(String data, char separator, int index) { int found = 0; int strIndex[] = { 0, -1 }; int maxIndex = data.length() - 1; for (int i = 0; i <= maxIndex && found <= index; i++) { if (data.charAt(i) == separator || i == maxIndex) { found++; strIndex[0] = strIndex[1] + 1; strIndex[1] = (i == maxIndex) ? i+1 : i; } } return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; } |
The pH of pure water is 7. In general water with a pH lower than 7 is considered acidic, and with a pH greater than 7 is considered basic. The normal range for pH in surface water systems is 6.5 to 8.5, and the pH range for groundwater systems is between 6 to 8.5. Waters taken from underground sources and not treated or modified in any way will have a pH between 7.2 and 7.8, which is the ideal range for good health.
The water under test is in the ideal range and has a pH value of around 7.4 which is considered good for health.
In my upcoming Tutorial, I will upgrade this Project and will use a waterproof temperature sensor “DS18B20” with the pH sensor. This way we can monitor the Water Quality and Temperature. I will practically perform some tests on the River water. So subscribe right now so that you never miss any of my upcoming tutorials.
Watch Video Tutorial:
Related Projects:
TDS meter Arduino, water Quality monitoring Project, TDS in Water
ESP32 and TDS Sensor-based IoT Water Quality Monitoring System:
Hi Engr Fahad,
Good day to you sir,
My name is Johan Sebastian and I am a student studying in Abu Dhabi Indian School, Abu Dhabi. I would like to know if i could use esp8266 nodemcu without the pcb board or the capacitors.
If you don’t use the PCB it’s ok. But make sure you use the capacitors, otherwise, the Nodemcu module will restart again and again.
i can use this without UNO?
can use this without Uno?
have coding or project that used ds18b20 water proof temperature sensor that connect to blynk?
Can i see the upgrade from this project with waterproof temperature censor?
sir can i know all about this project?