Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Header declearation
- #include <LiquidCrystal_I2C.h> // Library for I2C lcd
- #include <SPI.h> // Library for serial peripherals
- #include <WiFi.h> // Library for wifi functions
- #include <BlynkSimpleEsp32.h> // Library for Blynk on ESP32
- #include "DFRobot_ESP_PH.h" // Library for reading ph
- #include <EEPROM.h> // Library to access eeprom
- // Pin Assignment and declearation
- // Pin connection list
- // pin VP(39) of esp32 is connected to out(data) pin of turbidity sensor
- // pin D35(35) of esp32 is connected to Po(Ph) pin of Ph sensor
- // pin D22(SCL) of esp32 is connected to SCL pin of I2C display
- // pin D21(SDA) of esp32 is connected to SDA pin of I2C display
- #define BLYNK_PRINT Serial // Define serial communication for Blynk
- #define ESPADC 4095.0 //the esp Analog Digital Convertion value
- #define ESPVOLTAGE 3300 //the esp voltage supply value
- #define analogTurbPin 39 // Turbidity module pin out is connected to analog pin 39
- #define analogPhPin 35 // PH module pin P0 connected to analog pin 35
- const char* ssid = "no internet";//Write your wifi network's name here
- const char* password = "monenaito";//Write your password here
- char auth[] = "0VxrOQfrKy0SrGr3P2C71zgO6h-HQwwu"; // Auth Token from Blynk Project
- LiquidCrystal_I2C lcd(0x27, 16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
- BlynkTimer timer; // timer function of Blynk to call
- DFRobot_ESP_PH ph; // ph object of DFROBOT_ESP_PH class
- long turbidityTotal;
- float turbidity, phValue, temperature = 30;
- int x;
- //const float C = 21.34; // Constant of straight line (Y = mx + C)
- //const float m = -5.70; // Slope of straight line (Y = mx + C)
- // Function to write sensor data I2C LCD display
- void displaySensorDataToLCD(float turbidity, float ph)
- {
- lcd.setCursor(0, 0);
- lcd.print("Turbidity | Ph");
- lcd.setCursor(3, 1);
- lcd.print(turbidity,2);
- lcd.setCursor(10, 1);
- lcd.print("|");
- lcd.setCursor(12, 1);
- lcd.print(ph,2);
- }
- void readSendSensorData()
- {
- turbidityTotal = 0;
- float turbidityAvg = 0;
- turbidity=0;
- //taking 10 sample and adding with 10 milli second delay
- for(x=0; x<10 ; x++)
- {
- turbidityTotal += analogRead(analogTurbPin);
- delay(10);
- }
- turbidityAvg = turbidityTotal/10;
- turbidity = abs(4095-turbidityAvg)/800;
- if(turbidity>5.0)
- {
- turbidity = 5.0;
- }
- float phVoltage = analogRead(analogPhPin)/ESPADC*ESPVOLTAGE; // read the voltage
- phValue = ph.readPH(phVoltage, temperature); // convert voltage to pH with temperature compensation
- // Send sensor readings to Blynk
- // Please don't send more that 10 values per second.
- Blynk.virtualWrite(V5, turbidity);
- Blynk.virtualWrite(V6, phValue);
- displaySensorDataToLCD(turbidity, phValue); // Send sensor data to display function
- }
- void setup() {
- Serial.begin(9600); // Setup serial communication
- Blynk.begin(auth, ssid, password); // Setup blynk server
- EEPROM.begin(32); // needed to permit storage of calibration value in eeprom
- ph.begin(); // begin ph object
- // Start I2C LCD module and show 'IOT Based Water Quality Monitor' for 1.5 seconds ar powering up
- lcd.begin(16,2);
- lcd.init();
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("IOT based Water");
- lcd.setCursor(0, 1);
- lcd.print("Quality Monitor");
- delay(1500);
- lcd.clear();
- // End powerup display and clear the display
- // Setup a function to be called every second
- timer.setInterval(1000L, readSendSensorData);
- }
- void loop()
- {
- Blynk.run();
- timer.run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement