Dr Panos
Published © GPL3+

Smart Home

Simple project for motitoring internal - external home enviromental conditions, motion, fire detection and controling 4 appliences with app

IntermediateShowcase (no instructions)353
Smart Home

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Arduino Ethernet Shield 2
Arduino Ethernet Shield 2
×1
Arduino 4 Relays Shield
Arduino 4 Relays Shield
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Grove - Gas Sensor(MQ2)
Seeed Grove - Gas Sensor(MQ2)
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Story

Read more

Schematics

img_20210311_212607_NePKTkuCg7.jpg

screenshot_2021-03-11-21-22-53-651_cc_blynk_esk22WUHEO.jpg

screenshot_2021-03-11-21-29-38-331_cc_blynk_TLERWHJRP1.jpg

Code

Blynk_ethernet_smarthome.ino

C/C++
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

#define W5100_CS  10
#define SDCARD_CS 4

#define DHTaPIN 9
#define DHTbPIN 3
#define DHTaTYPE DHT11     // DHT 11)
#define DHTbTYPE DHT22   // DHT 22 (AM2302), AM2321
DHT dhta(DHTaPIN, DHTaTYPE); // Initialize DHT sensor for normal 16mhz Arduino
DHT dhtb(DHTbPIN, DHTbTYPE); // Initialize DHT sensor for normal 16mhz Arduino

 
BlynkTimer timer;


const int btn6Pin = A2;
const int btn7Pin = A4;
WidgetLED led6(V10);
WidgetLED led7(V0);
 

// V6 LED Widget represents the physical button state
boolean btn6State = false;
void buttonLed6Widget()
{
  // Read button
  boolean isPressed = (digitalRead(btn6Pin) == HIGH);

  // If state has changed...
  if (isPressed != btn6State) {
    if (isPressed) {
      led6.on();
    } else {
      led6.off();
    }
    btn6State = isPressed;
  }
}

// V7 LED Widget represents the physical button state
boolean btn7State = false;
void buttonLed7Widget()
{
  // Read button
  boolean isPressed = (digitalRead(btn7Pin) == HIGH);

  // If state has changed...
  if (isPressed != btn7State) {
    if (isPressed) {
      led7.on();
    } else {
      led7.off();
    }
    btn7State = isPressed;
  }
}

float temp_internal;    // Stores internal temperature value
float hum_internal;     
float temp_external;    // Stores external temperature value
float hum_external;

int fire = A4; //virtual pin for led
int fire2 = A3; //buzzer,pumb
int smokeA0 = A5; //analog input
int Relay4 = 4;   
int Relay3 = 5;  
int Relay2 = 6;    
int Relay1 = 7;

void temp ()
  {Blynk.virtualWrite(V11, hum_external);
  Blynk.virtualWrite(V12, temp_external);
  Blynk.virtualWrite(V5, hum_internal);
  Blynk.virtualWrite(V6, temp_internal);}

/*
 * PIR sensor 
 */
 
int ledPin = A2;                // choose the pin for the LED
int inputPin = A1;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

 

void setup()
{
  
                              
 pinMode(SDCARD_CS, OUTPUT);
 digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  Blynk.begin(auth);

  dhta.begin();
  dhtb.begin();

 pinMode(smokeA0, INPUT); 
 pinMode(fire, OUTPUT);
 pinMode(fire2, OUTPUT);

 digitalWrite(fire, LOW);
 digitalWrite(fire2, LOW);

 // Setup a function to be called every second
   
  timer.setInterval(1000L, temp);
     pinMode(btn6Pin, INPUT_PULLUP);
  timer.setInterval(500L, buttonLed6Widget);
  
   pinMode(btn7Pin, INPUT_PULLUP);
  timer.setInterval(1000L, buttonLed7Widget);
 
  pinMode(ledPin, OUTPUT);      // declare LED as output pir
  pinMode(inputPin, INPUT);     // declare sensor as input pir
   // Initialize Relays
  pinMode(Relay4, OUTPUT);
  pinMode(Relay3, OUTPUT);
  pinMode(Relay2, OUTPUT);
  pinMode(Relay1, OUTPUT);

  digitalWrite(Relay4, LOW);
  digitalWrite(Relay3, LOW);
  digitalWrite(Relay2, LOW);
  digitalWrite(Relay1, LOW);
}


void loop()
{
  Blynk.run();
  timer.run();
  
//SMOKE
  int analogSensor = analogRead(smokeA0);

 
  // Checks if it has reached the threshold value
 if (analogSensor >= 500) {
    digitalWrite(fire, HIGH);
    digitalWrite(fire2, HIGH);
  }
  else {
    digitalWrite(fire, LOW);
    digitalWrite(fire2, LOW);
      }
   
    // 1. Read data from Internal Sensor and store it to variables temp_internal and hum_internal
  hum_internal = dhta.readHumidity();
  temp_internal = dhta.readTemperature();  
    
    // 2. Read data from DHT22 and store it to variables hum and temp
  hum_external = dhtb.readHumidity();
  temp_external = dhtb.readTemperature();


  
  //pir code
  
  { val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
    pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH){
    pirState = LOW;}}}
 }

Credits

Dr Panos

Dr Panos

2 projects • 1 follower

Comments

Add projectSign up / Login