//Mzameli Mashiyi | Magna hydroponic monitoring system | 03 April 2024
//this was generated by Blynk when I created the dashboard
#define BLYNK_TEMPLATE_ID "TMPL21P2qR50i"
#define BLYNK_TEMPLATE_NAME "Led blink"
#define BLYNK_AUTH_TOKEN "4PEshq5vk_53b9pOFJljYv8f3TVmoTKy"
//get the libraries
#include <DHTesp.h>
#include <BlynkSimpleEsp32.h>
//these are pins I used for the connections
#define DHTPIN 15
#define LED_PIN 21
//connecting to the wokwi server
DHTesp dht;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST"; //this is the wokwi wifi name
char pass[] = ""; //always remeber to leave this blank
BlynkTimer timer;
//set up the code
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
dht.setup(DHTPIN, DHTesp::DHT22); // Initialize DHT sensor
Blynk.begin(auth, ssid, pass);
timer.setInterval(2000L, sendDHTData); // Send DHT data every 2 seconds
}
//write to the Blynk dashboard
BLYNK_WRITE(V3) {
int buttonState = param.asInt();
if (buttonState == 1) {
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
}
void sendDHTData() {
float t = dht.getTemperature();
float h = dht.getHumidity();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
//send data to the virtual pins on Blynk
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V1, h);
//The following code is for the humidity
Serial.print("Humidity: ");
Serial.print(h);
Serial.print("%\t");
//The following code is for the temperature
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" °C");
}
void loop() {
Blynk.run();
timer.run();
}