/* Using TaskScheduler timer */
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL69l7AIcVZ"
#define BLYNK_TEMPLATE_NAME "Assign2"
#define BLYNK_AUTH_TOKEN "Puc1BSB7TTSea4q0cqcFQxNbpaaH-khL"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <TaskScheduler.h>
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define SW1_PIN 12
#define SW2_PIN 14
#define POT_PIN 36 // VP = 36, AC0
void t1Callback();
Task t1(500, TASK_FOREVER, &t1Callback);
Scheduler runner;
void t1Callback() {
int rawVal = analogRead(POT_PIN);
int moisturePercent = 100 * (int)rawVal / 4095; // Convert raw value to number within the range 0-100
// sending the signal of potentiometer to to blynk
Blynk.virtualWrite(V3, moisturePercent);
// sending the singal of button to blynk
Blynk.virtualWrite(V1, digitalRead(SW1_PIN));
Blynk.virtualWrite(V2, digitalRead(SW2_PIN));
}
void setup() {
Serial.begin(115200);
pinMode(SW1_PIN, INPUT_PULLUP);
pinMode(SW2_PIN, INPUT_PULLUP);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
runner.init();
runner.addTask(t1);
t1.enable();
}
void loop() {
Blynk.run();
runner.execute();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Just some testing that want to save
// /* Using Blynk timer */
// #define BLYNK_PRINT Serial
// /* Fill in information from Blynk Device Info here */
// #define BLYNK_TEMPLATE_ID "TMPL69l7AIcVZ"
// #define BLYNK_TEMPLATE_NAME "Assign2"
// #define BLYNK_AUTH_TOKEN "Puc1BSB7TTSea4q0cqcFQxNbpaaH-khL"
// #include <WiFi.h>
// #include <WiFiClient.h>
// #include <BlynkSimpleEsp32.h>
// // Your WiFi credentials.
// // Set password to "" for open networks.
// char ssid[] = "Wokwi-GUEST";
// char pass[] = "";
// #define MOIST_PIN 36 // Use a clearer name for the pin constant
// BlynkTimer timer; // You need this to trigger the sensor reading
// void myTimerEvent() {
// int val = analogRead(MOIST_PIN);
// int moisturePercent = 100 * (int)val / 4095;
// // Send to Blynk and Serial
// Blynk.virtualWrite(V3, moisturePercent);
// Serial.print("Moisture: ");
// Serial.print(moisturePercent);
// Serial.println("%");
// }
// void setup() {
// Serial.begin(115200);
// Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// timer.setInterval(1000L, myTimerEvent);
// }
// void loop() {
// Blynk.run();
// timer.run();
// }SW2 (14)
SW1 (14)
LED (5)
POT (13)