/*************************************************************
This example shows how value can be pushed from Arduino to
the Blynk App.
WARNING :
For this example you'll need Adafruit DHT sensor libraries:
https://github.com/adafruit/Adafruit_Sensor
https://github.com/adafruit/DHT-sensor-library
App dashboard setup:
Value Display widget attached to V5
Value Display widget attached to V6
*************************************************************/
/* Fill-in information from Blynk Device Info here */
/*
#define BLYNK_TEMPLATE_ID "TMPL6fNnUALBQ"
#define BLYNK_TEMPLATE_NAME "Workshop IoT"
#define BLYNK_AUTH_TOKEN "NKCZV7-xFuNHop5_2TQLBzn63SW-Wk5M"
//*/
#define BLYNK_TEMPLATE_ID "TMPL6vykiTo6x"
#define BLYNK_TEMPLATE_NAME "Monitor Aglaonema"
#define BLYNK_AUTH_TOKEN "Rt4atWe9B3XixmTdxu3eF80W2cwuLnR-"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
int ldrPin = 32; // pin LDR
int soilPin = 34; // tanah
int relayPin = 35; // relay
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
int ldrAnalog = analogRead(ldrPin);
int soilAnalog = analogRead(soilPin);
// You can send any value at any time.
// Please don't send more that 10 values per second.
Serial.print(ldrAnalog);
Serial.print(";");
Serial.println(soilAnalog);
if(soilAnalog>3000){
digitalWrite(relayPin, HIGH);
}else{
digitalWrite(relayPin, LOW);
}
Blynk.virtualWrite(V7, ldrAnalog);
Blynk.virtualWrite(V8, soilAnalog);
}
void setup()
{
// Debug console
Serial.begin(115200);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// You can also specify server:
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080);
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}