#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include "ThingSpeak.h"
#include <DHT.h>
const char* ssid = "Wokwi-GUEST"; // your network SSID (name)
const char* password = ""; // your network password
WiFiClient client;
unsigned long myChannelNumber = 2316255;
const char * myWriteAPIKey = "TPQOEG1MEZZBYC70";
// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 3000;
float temperatureC;
float humidity;
#define DHTPIN 12
#define DHTTYPE DHT22
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
DHT dht(DHTPIN ,DHTTYPE);
void setup()
{
Serial.begin(9600);
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.clear(); // clear display
lcd.setCursor(0, 0); // move cursor to (0, 0)
lcd.print("Hello"); // print message at (0, 0)
lcd.setCursor(2, 1); // move cursor to (2, 1)
lcd.print("Cloud"); // print message at (2, 1)
delay(2000);
lcd.clear();
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect");
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, password);
delay(5000);
}
}
Serial.println("\nConnected.");
}
void loop()
{
// display the above for two seconds
// display the above for two seconds
if ((millis() - lastTime) > timerDelay) {
temperatureC = dht.readTemperature();
Serial.print("Temperature (ºC): ");
Serial.println(temperatureC);
humidity = dht.readHumidity();
Serial.print("Humidity (%): ");
Serial.println(humidity);
lcd.clear(); // clear display
lcd.setCursor(3, 0); // move cursor to (3, 0)
lcd.print("Temp: "); // print message at (3, 0)
lcd.print(temperatureC); // print message at (3, 0)
lcd.setCursor(3, 1); // move cursor to (0, 1)
lcd.print("Hum: "); // print message at (3, 0)
lcd.print(humidity); // print message at (0, 1)
delay(2000);
}
}