#define BLYNK_TEMPLATE_ID "TMPL3MCsoad9x"
#define BLYNK_TEMPLATE_NAME "stove control"
#define BLYNK_AUTH_TOKEN "2R4x1bFGYpvO-nNuF5QRoGqxBPA0SWTY"
char auth[] = "2R4x1bFGYpvO-nNuF5QRoGqxBPA0SWTY";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
#define NTC_PIN 34 // Analog pin for NTC thermistor (change to the appropriate pin)
#define NTC_BETA 3950 // Beta value for your NTC thermistor
#define NTC_R0 10000 // Resistance at 25°C (room temperature)
#define SERIES_RESISTOR 10000 // Value of the series resistor (in ohms)
#define VIRTUAL_PIN V3 // Virtual pin for the temperature display on the Blynk app
#define BUZZER_PIN 12 // GPIO pin for the buzzer (change to the appropriate pin)
#define LED_PIN V4 // Virtual pin for the LED widget on the Blynk app
#define TEMP_THRESHOLD 50 // Temperature threshold for activation (in Celsius)
Servo servo;
int servoPosition;
void setup() {
Serial.begin(115200);
servo.attach(2);
servoPosition = servo.read(); // Read the current position of the servo
Blynk.virtualWrite(V5, servoPosition); // Update the Blynk app with the initial servo position
Blynk.begin(auth, ssid, pass);
pinMode(BUZZER_PIN, OUTPUT);
}
BLYNK_WRITE(V0)
{
servo.write(param.asInt());
}
void loop() {
Blynk.run();
servoPosition = servo.read(); // Read the current position of the servo
Blynk.virtualWrite(V5, servoPosition); // Update the Blynk app with the initial servo position
float rawADC = analogRead(NTC_PIN);
float resistance = SERIES_RESISTOR / ((4095.0 / rawADC) - 1.0);
float temperature = 1.0 / ((1.0 / (25 + 273.15)) + (1.0 / NTC_BETA) * log(resistance / NTC_R0)) - 273.15;
Blynk.virtualWrite(VIRTUAL_PIN, temperature);
// Check if temperature exceeds the threshold
if (temperature > TEMP_THRESHOLD) {
digitalWrite(BUZZER_PIN, HIGH); // Turn on the buzzer
Blynk.virtualWrite(LED_PIN, 255); // Turn on the virtual LED
} else {
digitalWrite(BUZZER_PIN, LOW); // Turn off the buzzer
Blynk.virtualWrite(LED_PIN, 0); // Turn off the virtual LED
}
// Print temperature to the serial monitor
Serial.print("Temperature: ");
Serial.println(temperature);
delay(1000); // You can adjust the update interval as needed
}