#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include "ThingSpeak.h"
const char* WIFI_SSID = "Wokwi-GUEST"; // Replace with your Wi-Fi name
const char* WIFI_PASS = ""; // Replace with your Wi-Fi password
const int myChannelNumber = 2382004;
const char* myApikey = "RV8UIUMXWHVEFV13"; // Replace with your ThingSpeak API Key
const char* server = "api.thingspeak.com";
LiquidCrystal_I2C lcd(0x27, 20, 4);
WiFiClient client;
float t;
float pH;
float nh3;
long readT() {
long t = random(1700, 2900) * 0.01;
return t;
}
long readNh3() {
long nh3 = random(90, 5000) * 0.01;
return nh3;
}
long readPh() {
long pH = random(400, 1000) * 0.01;
return pH;
}
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.print("Aqua Sensor");
delay(3000);
lcd.clear();
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void loop() {
ThingSpeak.begin(client);
t = readT();
pH = readPh();
nh3 = readNh3();
Serial.println("Data from AQUA SENSORS");
Serial.print("Temp : ");
Serial.println(t, 1);
Serial.print("pH : ");
Serial.println(pH, 1);
Serial.print("NH3 : ");
Serial.println(nh3, 1);
lcd.setCursor(0, 0);
lcd.print("Temp");
lcd.setCursor(0, 1);
lcd.print(t, 1);
lcd.setCursor(6, 0);
lcd.print("pH");
lcd.setCursor(6, 1);
lcd.print(pH, 1);
lcd.setCursor(11, 0);
lcd.print("NH3");
lcd.setCursor(11, 1);
lcd.print(nh3, 1);
ThingSpeak.setField(1, t);
ThingSpeak.setField(2, pH);
ThingSpeak.setField(3, nh3);
int status = ThingSpeak.writeFields(myChannelNumber, myApikey);
if (status == 200) {
Serial.println("Data sent to ThingSpeak!");
} else {
}
delay(2000);
lcd.clear();
}