/*************************************************************
This is a simple demo of sending and receiving some data.
Be sure to check out other examples!
*************************************************************/
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPL6gNXqcdhB"
#define BLYNK_TEMPLATE_NAME "Quickstart Device"
#define BLYNK_AUTH_TOKEN "0p2KqDDiC6Yw10Hw8TzI74vA_HRtFccr"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials.
// Set password to "" for open networks.
//char ssid[] = "BobaCocaLola_2.4G";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define LED1_PIN 5
#define SW1_PIN 14
#define SW2_PIN 27
#define POT_PIN 34
#define VPIN_LED V0
#define VPIN_SW1 V1
#define VPIN_SW2 V2
#define VPIN_SOIL V3
BlynkTimer timer;
BLYNK_WRITE(VPIN_LED)
{
int ledState = param.asInt();
digitalWrite(LED1_PIN, ledState);
}
void readSensors()
{
Blynk.virtualWrite(VPIN_SW1, digitalRead(SW1_PIN) == LOW ? 255 : 0);
Blynk.virtualWrite(VPIN_SW2, digitalRead(SW2_PIN) == LOW ? 255 : 0);
int potValue = analogRead(POT_PIN); // 0–4095
int soilMoisture = map(potValue, 0, 4095, 0, 100);
Blynk.virtualWrite(VPIN_SOIL, soilMoisture);
}
void setup()
{
Serial.begin(115200);
pinMode(LED1_PIN, OUTPUT);
pinMode(SW1_PIN, INPUT_PULLUP);
pinMode(SW2_PIN, INPUT_PULLUP);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(500L, readSensors);
}
void loop()
{
Blynk.run();
timer.run();
}