/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6YgJabUNV"
#define BLYNK_TEMPLATE_NAME "smart farming"
#define BLYNK_AUTH_TOKEN "qQoQ9u2O0ow_F4Oto2QOVhWY5PeDqHmX"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials. Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
const int pin= 32;
int adc;
int moisture;
BLYNK_WRITE(V2) // Executes when the value of virtual pin 0 changes
{
if(param.asInt() == 1)
{
// execute this code if the switch widget is now ON
digitalWrite(4,HIGH); // Set digital pin 2 HIGH
}
else
{
// execute this code if the switch widget is now OFF
digitalWrite(4,LOW); // Set digital pin 2 LOW
}
}
void setup() {
// Debug console
Serial.begin(9600);
pinMode(4, OUTPUT); // Initialise digital pin 4 as an output pin
pinMode(16, OUTPUT); // Initialise digital pin 16 as an output pin
pinMode(32,INPUT);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop() {
Blynk.run();
adc= analogRead(pin);
moisture= map(adc,0,4095,0,100);
int pH= random(0, 14);
if(moisture <65){
digitalWrite(4,HIGH);
}
else{
digitalWrite(4,LOW);
}
// Print sensor values for debugging
Serial.print("Moisture: ");
Serial.print(moisture);
Serial.println("%");
Serial.print("pH: ");
Serial.println(pH);
// Update Blynk widgets with sensor values
Blynk.virtualWrite(V0, moisture);
Blynk.virtualWrite(V1, pH);
delay(1000);
}