Combined Turbidity & Temp Sensors With Esp 8266
Combined Turbidity & Temp Sensors With Esp 8266
Combined Turbidity & Temp Sensors With Esp 8266
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFi.h>
// Pin configurations
#define ONE_WIRE_BUS 2
#define sensorPin A0 // Assuming the sensor pin is connected to A0
// WiFi credentials
const char* ssid = "SERVANAWireless"; // Change this to your WiFi SSID
const char* password = "PASSWORD10"; // Change this to your WiFi password
// Variables
float volt = 0;
int ntu = 0;
// LCD Configuration
LiquidCrystal_I2C lcd(0x27, 2, 16); // Change the address if necessary
// OneWire instance
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer;
void setup()
{
// Serial and LCD initialization
Serial.begin(9600);
lcd.begin(2, 16);
lcd.backlight();
Serial.print("Locating devices...");
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
if (!sensors.getAddress(insideThermometer, 0))
Serial.println("Unable to find address for Device 0");
sensors.setResolution(insideThermometer, 9);
// WiFi connection
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop()
{
// Temperature measurement
Serial.print("Requesting temperatures...");
sensors.requestTemperatures();
Serial.println("DONE");
printTemperature(insideThermometer);
// Voltage measurement
volt = 0;
for (int i = 0; i < 800; i++)
{
volt += ((float)analogRead(sensorPin) / 1023) * 5;
}
volt = volt / 800;
volt = round_to_dp(volt, 2);
if (volt < 2.5)
{
ntu = 3000;
}
else
{
ntu = -1120.4 * square(volt) + 5742.3 * volt - 4353.8;
}
// LCD Display
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(volt);
lcd.print(" V");
lcd.setCursor(0, 1);
lcd.print(ntu);
lcd.print(" NTU");
// WiFi communication
// You can add your code here to send or receive data via WiFi
// For example, you can use the ESP8266HTTPClient library to make HTTP requests
// See https://arduino-esp8266.readthedocs.io/en/latest/esp8266httpclient.html for more details
delay(10);
}