#include <Servo.
h>
#include<Arduino.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define DHTTYPE DHT11
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
#include <SPI.h>
#include <Wire.h>
#include <MFRC522.h>
#define SS_PIN 5
#define RST_PIN 0
MFRC522 mfrc522(SS_PIN, RST_PIN);
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL2bMworSrg"
#define BLYNK_TEMPLATE_NAME "Smart Home"
#define BLYNK_AUTH_TOKEN "rYSn8ZevfFcnIUAnqgUYhYhtULYnEP63"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
1
char ssid[] = "Memo";
char pass[] = "Mom159753";
BlynkTimer timer;
#define k_led_pin 14
#define r_led_pin 26
#define h_led_pin 27
#define r_window_pin 32
#define h_window_pin 33
#define h_curtain_pin 26
#define h_tv_pin 36
#define h_condition_pin 12
#define m_door_pin 25
#define SS 5
#define RAIN 34
#define DHTPIN 17
#define DS 16
#define SHCP 2
#define STCP 4
#define valve 13
#define GAS_SENS 35
DHT dht( DHTPIN , DHTTYPE);
int pos = 0;
int k_led_state = 0;
int r_led_state = 0;
int h_led_state = 0;
int r_window_state = 0;
int h_window_state = 0;
int h_curtain_state = 0;
int h_tv_state = 0;
int h_condition_state = 0;
int main_door_state = 0;
#define k_led_vpin V1
#define r_led_vpin V2
#define h_led_vpin V3
#define r_window_vpin V4
#define h_window_vpin V0
2
#define h_curtain_vpin V5
#define h_tv_vpin V6
#define h_condition_vpin V7
#define m_door_vpin V8
BLYNK_CONNECTED() {
[Link](k_led_vpin);
[Link](r_led_vpin);
[Link](h_led_vpin);
[Link](r_window_vpin);
[Link](h_window_vpin);
[Link](h_curtain_vpin);
[Link](h_tv_vpin);
[Link](h_condition_vpin);
[Link](m_door_vpin);
}
BLYNK_WRITE(k_led_vpin) {
k_led_state = [Link]();
digitalWrite(k_led_pin, k_led_state);
}
BLYNK_WRITE(r_led_vpin) {
r_led_state = [Link]();
digitalWrite(r_led_pin, r_led_state);
}
BLYNK_WRITE(h_led_vpin) {
h_led_state = [Link]();
digitalWrite(h_led_pin, h_led_state);
}
BLYNK_WRITE(r_window_vpin) {
r_window_state = [Link]();
if(r_window_state == 1){
servo1_on();
}else{
servo1_off();
}
}
BLYNK_WRITE(h_window_vpin) {
h_window_state = [Link]();
3
if(h_window_state == 1){
servo2_on();
}else{
servo2_off();
}
}
BLYNK_WRITE(h_curtain_vpin) {
h_curtain_state = [Link]();
digitalWrite(h_curtain_pin, h_curtain_state);
}
BLYNK_WRITE(h_tv_vpin) {
h_tv_state = [Link]();
if(h_tv_state == 1){
lcd_on();
}else{
lcd_off();
}
}
BLYNK_WRITE(h_condition_vpin) {
h_condition_state = [Link]();
digitalWrite(h_condition_pin, h_condition_state);
}
BLYNK_WRITE(m_door_vpin) {
main_door_state = [Link]();
if(main_door_state == 1){
servo3_on();
}else{
servo3_off();
}
}
void servo1_off(){
[Link](0);
}
void servo1_on(){
[Link](90);
}
void servo2_off(){
[Link](0);
}
void servo2_on(){
4
[Link](90);
}
void servo3_off(){
[Link](0);
}
void servo3_on(){
[Link](90);
}
void servo4_off(){
[Link](0);
}
void servo4_on(){
[Link](90);
}
static const uint8_t image_data_Saraarray[1024] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xfc, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x3f, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x0f, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x07, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x03, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x7f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x3f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x3f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x1f, 0xff, 0xff,
0xff,
5
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x80, 0x00, 0x00, 0x0f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xf0, 0x1c, 0x45, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xf8, 0x3f, 0xf7, 0xfe, 0x83, 0xc0, 0x00, 0x00, 0x0f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x03, 0x39, 0xc0, 0x00, 0x00, 0x07, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xfc, 0x3f, 0xfd, 0x79, 0xff, 0xe0, 0x00, 0x06, 0x07, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0x20, 0x00, 0x07, 0x07, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x3b, 0x87, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7b, 0x8f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x04, 0x39, 0x8f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xec, 0x00, 0x06, 0x79, 0x1f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x07, 0xff, 0xde, 0x00, 0x04, 0x7a, 0x1f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 0x9e, 0x00, 0x01, 0xc4, 0x3f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xec, 0x00, 0x01, 0xa8, 0x3f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x03, 0xe0, 0x7f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xfc, 0x00, 0x01, 0x00, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff,
0xff,
6
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0xe0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x0f, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x07, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x07, 0xfe, 0x00, 0x01, 0xff, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x0c, 0x3f, 0xfc, 0x00, 0x00, 0x01, 0xff,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0x00, 0x03, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x0f,
0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0x0f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x7f,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00,
0x01,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xe1, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x0f, 0x3f, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x1d, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x17, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x17, 0xff, 0x93, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x27, 0xff, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x2f, 0xfb, 0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x3f, 0xfe, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf9, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
7
0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xf7, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xf8, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xf8, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xf8, 0x00, 0x00, 0x00, 0x03, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xf8, 0x00, 0x00, 0x00, 0x07, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xf8, 0x00, 0x00, 0x00, 0x07, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xf0, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xe0, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0xc0, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0xff, 0x80, 0x00, 0x00, 0x00, 0x3f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00
};
void sendSensor()
{
float h = [Link]();
float t = [Link](); // or [Link](true) for Fahrenheit
if (isnan(h) || isnan(t)) {
[Link]("Failed to read from DHT sensor!");
return;
}
[Link](V10, t);
[Link](V9, h);
}
void lcd_on(){
[Link]();
// Draw bitmap on the screen
[Link](0, 0, image_data_Saraarray, 128, 64, 1);
[Link]();
8
}
void lcd_off(){
[Link]();
[Link]();
}
void gas(){
int gasValue = analogRead(GAS_SENS);
if(gasValue > 200){
digitalWrite(valve,HIGH);
}else{
digitalWrite(valve,LOW);
}
}
void setup()
{
[Link]();
mfrc522.PCD_Init();
if() {
[Link](F("SSD1306 allocation failed"));
for(;;);
}
delay(2000); // Pause for 2 seconds
[Link]();
[Link](100L, sendSensor);
[Link](r_window_pin);
[Link](h_window_pin);
[Link](m_door_pin);
[Link](15);
[Link](115200);
pinMode(k_led_pin, OUTPUT);
pinMode(r_led_pin, OUTPUT);
pinMode(h_led_pin, OUTPUT);
pinMode(GAS_SENS, INPUT);
pinMode(valve, OUTPUT);
pinMode(h_curtain_pin, OUTPUT);
pinMode(h_condition_pin, OUTPUT);
pinMode(RAIN, INPUT);
[Link](BLYNK_AUTH_TOKEN, ssid, pass);
//[Link](pos);
}
9
void check(){
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// if the card was read
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Read the UID of the card and write to the serial port
[Link]();
[Link]("UID Tag :");
String content = "";
byte letter;
for (byte i = 0; i < [Link]; i++)
{
[Link]([Link][i] < 0x10 ? " 0" : " ");
[Link]([Link][i], HEX);
[Link](String([Link][i] < 0x10 ? " 0" : " "));
[Link](String([Link][i], HEX));
}
[Link]();
[Link]();
if ([Link](1) == "D3 7E 56 C5")
{
access_granted();
}
else
{
access_denied();
}
}
void access_granted(){
[Link]("Access Granted! ");
servo4_on();
delay(1000);
servo4_off();
delay(1000);
10
}
void access_denied(){
[Link]("Access Denied! ");
void loop()
{
//[Link]( 90 );
check();
[Link]();
[Link]();
gas();
//[Link](r_window_state);
}
11