IOT Water Quality monitoring using Arduino, pH Sensor, ESP8266 & Blynk
Description:
water quality monitoring- In this tutorial, you will learn how to use Arduino, pH sensor, Nodemcu esp8266 wifi module and Blynk Framework to build an IoT based water quality monitoring system. As this is a project based on the IoT “Internet of Things,” you can track water quality from anywhere in the world.
In this episode, I will explain how to calculate the Well Water’s pH level, and I will also clarify whether the water being checked is good or bad for safety. In this tutorial, in the blynk software, you will also learn how to use the16x2 LCD widget.
In this tutorial, we will cover
- Complete Circuit Diagram of water quality monitoring
- pH Sensor Pinout information.
- Nodemcu wifi module and pH sensor interfacing with Arduino and programming.
- Arduino and Nodemcu Programming and finally
- Testing
The Amazon Purchase links are given below:
Nodemcu esp8266 wifi module: Best price https://amzn.to/2ZzhWpz
Gravity: Analog pH Sensor / Meter Kit For Arduino by DFrobot: https://amzn.to/2QtK899
Arduino Uno: https://amzn.to/39aq6ZT
Mega 2560: https://amzn.to/2SszMsI
lm7805 Voltage Regulator: https://amzn.to/2ERYoTJ
330-ohm resistors pack: https://amzn.to/2Qj1Igg
female DC power jack socket: https://amzn.to/377Pg9M
470uf capacitors: https://amzn.to/2MrN3xR
5×7 cm Vero board: https://amzn.to/37b7KWO
female headers: https://amzn.to/350w6RE
connection wires: https://amzn.to/2MvOJXd
Super Starter kit for Beginners: https://amzn.to/398dliF
Jumper Wires: https://amzn.to/2SrnBwo
Bread Board: https://amzn.to/2MxV5FM
12v Adaptor: https://amzn.to/2MuOlZk
PCB plate: https://amzn.to/2MuwNMB
Variable Supply: https://amzn.to/39d0KdP
Digital Multimeter: https://amzn.to/34WbVoa
Vero Board / stripboard: https://amzn.to/39nL9Zg
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2PVwexF
Solder wire: https://amzn.to/2QlOvTS
Wire Stripper: https://amzn.to/353tYJa
wirecutter: https://amzn.to/2tV2lFj
PCB small portable drill machine: https://amzn.to/2MvQqnx
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 of the water quality monitoring:
This is the nodemcu esp8266 power supply circuit diagram. This circuit is designed in the version 9.1.0 of the cadsoft Eagle. This is a 5v regulated power supply that is used to power the wifi module Nodemcu esp8266. The famous voltage regulator lm7805 is used in the circuit. J1 is the female power jack and this is where we connect a 12v adapter, battery or solar panel, two 470uf capacitors are attached to the voltage regulator r input and output side. In series, a 330 ohm resistor is connected to a led of 2.5v. This is a resistor that is inherently restricting.The voltage regulator output is connected to the Nodemcu esp8266 wireless module’s Vin pin and the input is connected to the ground SV1 and SV2 are the headers for women.
This is the Final Power Supply Board to power the wifi unit Nodemcu ESP8266.
pH Sensor Kit Interfacing with Arduino:
Attach the red wire to the 5v of the Arduino…
Connect the black wire to the ground of the Arduino…
Connect the blue wire to the analog pin A0 of the Arduino…
Link the Nodemcu ESP8266 wifi module TX and RX pins with Arduino’s Pin number2 and Pin number3.
The ground of Arduino is connected to the ground pin of nodemcu module
Blynk Application for the Water Quality Monitoring System:
- First of all, open the application for blynk.
- Set the name of the plan to the pH meter.
- Tap on the selected computer to select nodemcu. Make sure that you set the type of connection to wifi and then
- tap on the build key, an authentication token will be sent to your email I d and used in programming, simply copy and paste it into programming.
- Now tap on the screen to scan for and add the LCD overlay.
- Now pick Advanced by clicking on the LCD.
- Tap on the button for the virtual pin and pick the virtual v2
Our application is ready and let’s talk about programming now.
Programming:
Two programs are used in this project, one is written for the Arduino while the other is written for the wifi module Nodemcu ESP8266. Let’s start with Arduino Programming first of all.
Arduino Programming for the Water Quality Monitoring System:
This is the same software that I used in the pH sensor pH monitoring system for water quality. I’ve made some changes this time, including these two libraries. The stdlib.h library has a basic function to convert the float value to the string, while the code serial.h library is used to create multiple serial ports.
As I always say, to communicate with other devices, never use the default serial port of Arduino. We only have one Serial port, as you know in Arduino, on pin number 0 and pin number 1. The default Serial Port of Arduino should be used for debugging purposes only. Now the question is whether we use the default Serial port of Arduino for debugging purposes then how do we connect the Nodemcu module to the Arduino? … Okay, we can use the serial library software to create multiple Serial Ports at all.So that’s why I added the serial library of the program and specified a serial port on Pin number 2 and Pin number 3 with the name Nodemcu. So the TX and RX Pins Nodemcu module will be attached to Pin number 2 and Pin number 3 of the Arduino …
Another adjustment I made to the program is that I added this feature to convert a float value to the value of the sequence. Then, along with the comma that is used as the delimiter, I inserted this String value. The String message is eventually sent to the Nodemcu module and we delete the String for the new day at the end.
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 maximum water’s pH is 7. Water with a range of pH below 7 is considered acidic and is considered basic with a pH greater than 7. Waters from natural sources that have not been filtered or altered in any way will have a pH between 7.2 and 7.8, which is the optimum range for good health.
I will upgrade this project in my next project and use the pH sensor with a waterproof temperature sensor “DS18B20.” It helps us to track the consistency and temperature of the air. I’m basically going to do some river water tests. So sign up now so you’ll never miss any of my forthcoming tutorials.