#define BLYNK_TEMPLATE_ID "TMPL6QgPZV8WB"
#define BLYNK_TEMPLATE_NAME "BynkHW2"
#define BLYNK_AUTH_TOKEN "_3P3f-b_3jrgW5q2cx7Ug-mShq8zXIPt"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// ===== Choose pins (you can change, but keep consistent with Wokwi wiring) =====
const int LED_PIN = 23;
const int SW1_PIN = 18;
const int SW2_PIN = 19;
const int POT_PIN = 34; // ADC
// ===== Virtual pins (MUST match Blynk Datastreams) =====
#define VPIN_LED V0
#define VPIN_SW1 V1
#define VPIN_SW2 V2
#define VPIN_SOIL V3
BlynkTimer timer;
BLYNK_CONNECTED() {
Serial.println("✅ Blynk connected!");
}
// LED button from Blynk (V0)
BLYNK_WRITE(VPIN_LED) {
int state = param.asInt(); // 0/1
digitalWrite(LED_PIN, state);
Serial.print("LED=");
Serial.println(state);
}
// Send buttons + pot to Blynk
void sendInputs() {
int sw1 = (digitalRead(SW1_PIN) == LOW) ? 1 : 0; // pressed=1
int sw2 = (digitalRead(SW2_PIN) == LOW) ? 1 : 0;
int pot = analogRead(POT_PIN); // 0..4095
int soil = map(pot, 0, 4095, 0, 100); // 0..100
if (soil < 0) soil = 0;
if (soil > 100) soil = 100;
Blynk.virtualWrite(VPIN_SW1, sw1);
Blynk.virtualWrite(VPIN_SW2, sw2);
Blynk.virtualWrite(VPIN_SOIL, soil);
Serial.print("SW1=");
Serial.print(sw1);
Serial.print(" SW2=");
Serial.print(sw2);
Serial.print(" Soil=");
Serial.println(soil);
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
pinMode(SW1_PIN, INPUT_PULLUP);
pinMode(SW2_PIN, INPUT_PULLUP);
Serial.println("Connecting to Blynk...");
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(500L, sendInputs);
}
void loop() {
Blynk.run();
timer.run();
}