/*************************************************************
This sketch shows how to write values to Virtual Pins
NOTE:
BlynkTimer provides SimpleTimer functionality:
http://playground.arduino.cc/Code/SimpleTimer
App dashboard setup:
Value Display widget attached to Virtual Pin V5
*************************************************************/
#define BLYNK_TEMPLATE_ID "TMPL6TGh9X0gP"
#define BLYNK_TEMPLATE_NAME "sheep and piston and rod"
#define BLYNK_AUTH_TOKEN "_KOAjVFxMDu-D9I8rBaWcn3Wktjq_UmD"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define LED 15
#define ledPin 34
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// 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.
int val = 0;
BLYNK_WRITE(V1)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if(pinValue == 1){
digitalWrite(LED , HIGH);
}
else {
digitalWrite(LED , LOW);
}
// process received value
}
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
pinMode(LED, OUTPUT);
pinMode(LED, OUTPUT);
pinMode(ledPin, OUTPUT);
// 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);
}
void loop()
{
Blynk.run();
val = analogRead(ledPin);
Serial.print("val = "); // พิมพ์ข้อมความส่งเข้าคอมพิวเตอร์ "val = "
Serial.println(val); // พิมพ์ค่าของตัวแปร val
Serial.println();
if (val > 50) {
Serial.print("dirty water"); // สั่งให้ ขา D21 ปล่อยลอจิก 0 ไฟ LED ด
}
else{
Serial.print("clean water");
}
Serial.println();
delay(1000);
}