//3 buttons for Climate check, Find my Phone, confirm Schedule
#define BLYNK_TEMPLATE_ID "TMPL5zo0m681d"
#define BLYNK_TEMPLATE_NAME "ESP32 DHT22 blynk"
#define BLYNK_AUTH_TOKEN "4gPex1bMu-0xOKPR0PJIbxOQfYI50cwc"
#define sensor_pin 27
#include <LiquidCrystal_I2C.h>
#include <DHTesp.h> //DHT sensor header file
#include <DHT.h>
#include <PubSubClient.h>
#include <Arduino.h>
#include <WiFi.h> //Wifi header file
#include <WiFiClient.h> //Wifi header file
#include <BlynkSimpleEsp32.h> //blynk header file
#include <NTPClient.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
char auth[] = BLYNK_AUTH_TOKEN; // blynk token define above
char ssid[] = "Wokwi-GUEST"; // Since it is a simulation a default Wokwi SSID wifi name is used
char pass[] = ""; // no password
const int DHT_PIN = 15; // The sensor it connected to pin 21
DHTesp dhtSensor;
BlynkTimer timer;
int led_pin = 23;
const int buzzerPin = 23;
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define PULSE_PIN 25 // pulse sensor pin connection
//int buttonpintemp = 4;
int buttonvoicerec = 13;
int findme = 34;
int ledpin = 18;
const int buzzrepin = 23;
bool tempbuttonstate = false;
int findmestate = HIGH;
int minHeartRate = 60;
int maxHeartRate = 100;
//bool findmestate =false;
void setup() {
// all my setup codes are here
// Wire.begin(23, 22);
Serial.begin(115200);
WiFi.begin(ssid, pass);
timeClient.begin();
Blynk.begin(auth,ssid,pass); // Setup the connection to blynk
dhtSensor.setup(DHT_PIN, DHTesp::DHT22); // Sensor setup
//timer.setInterval(2500L,sendSensor); // call the sendSensor function after 2500 millisecond interval
lcd.init(); // initialize the lcd
lcd.backlight(); // To turn on the backlight,
lcd.clear();
lcd.setCursor(0, 0);
digitalWrite(ledpin, LOW);
tempbuttonstate == LOW;
pinMode(findme, INPUT);
//pinMode(findme, INPUT);
pinMode(buttonvoicerec, INPUT);
pinMode(ledpin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
Serial.println("TESTING LIGHT BUTTON");
}
BLYNK_WRITE(V6) // Executes when the value of virtual pin 0 changes
{
if(param.asInt() == 1)
{
// execute this code if the switch widget is now ON
tone(buzzerPin, 1000); // You can adjust the frequency as needed
delay(10); // Sound duration
// Deactivate the buzzer (no sound)
noTone(buzzerPin);
Serial.println("1");
}
}
void loop() {
timeClient.update();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(timeClient.getFormattedTime());
TempAndHumidity data = dhtSensor.getTempAndHumidity();
int t = data.temperature;
float h = data.humidity;
int alarmon = 1;
int alarmoff = 0;
Blynk.run(); //call the run function in the loop
timer.run();
BLYNK_CONNECTED();
Blynk.syncVirtual(V4); // will cause BLYNK_WRITE(V4) to be executed
Blynk.virtualWrite(V0,t); // temp will be pushed into V0 virtual pin
Blynk.virtualWrite(V1,h);// humidity will be pushed into V2 virtual pin
lcd.setCursor(0,1);
lcd.print("Temp:" + String(t) + "C" + " Humd:" + String(h) + "%");
// Read pulseValue from PULSE_PIN
int16_t pulseValue = analogRead(PULSE_PIN);
// Convert pulseValue to voltage
float voltage = pulseValue * (5 / 4095.0);
// calculate heartRate from voltage
int heartRate = (voltage / 3.3) * 675;
if (heartRate < minHeartRate){
//lcd.clear();
Serial.println("Heart rate below ");
//lcd.setCursor(0, 1);
Serial.println("minimum: ");
Serial.println(heartRate);
//lcd.setCursor(13,1);
Serial.println("b/m");
delay(20); // Wait for the other half of the blink interval
}
else if (heartRate > maxHeartRate){
//lcd.clear();
Serial.println("Heart rate above ");
//lcd.setCursor(0, 1);
Serial.println("maximum: ");
lcd.println(heartRate);
//lcd.setCursor(13,1);
Serial.println("b/m");
delay(20); // Wait for the other half of the blink interval
}else{
//lcd.clear();
Serial.println("Heart Monitor");
//lcd.setCursor(0, 1);
Serial.println("Heart rate:");
Serial.println(heartRate);
//lcd.setCursor(13,1);
Serial.println("b/m");
delay(100); // Wait for the other half of the blink interval
}
// Read the state of the button
int value = digitalRead((findme));
if (findmestate != value) {
findmestate = value;
if (value == HIGH) {
Blynk.virtualWrite(V5,alarmon);
Serial.println("alarm on");
digitalWrite(ledpin, HIGH);
Serial.println(" released");
}
if (value == LOW) {
Blynk.virtualWrite(V5,alarmoff);
digitalWrite(ledpin, LOW);
Serial.println(" pressed");
}
}
delay(300);
}