William Lu
Created July 26, 2022

iSense: Smart Home Security System

Make IoT-based Smart Home Security system to monitor daily home activity and control all the home appliances with Blynk app & Switches.

iSense: Smart Home Security System

Things used in this project

Hardware components

Spresense boards (main & extension)
Sony Spresense boards (main & extension)
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×2
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×2
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×2
Buzzer
Buzzer
×3
LED (generic)
LED (generic)
×6
Jumper wires (generic)
Jumper wires (generic)
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×3
Relay Module (Generic)
×4
LED Light Bulb, Frosted GLS
LED Light Bulb, Frosted GLS
×4
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×4

Software apps and online services

Arduino IDE
Arduino IDE
Fritzing
Blynk
Blynk

Hand tools and fabrication machines

Extraction Tool, 6 Piece Screw Extractor & Screwdriver Set
Extraction Tool, 6 Piece Screw Extractor & Screwdriver Set

Story

Read more

Schematics

Integrate Circuits

Integrate Circuits 2

Code

PIR_SENSOR_Spresense_FOR_MOTION_DETECTOR

Arduino
// arduino motion sensor 
 int val = 0 ;  
 void setup()  
 {  
 Serial.begin(9600);  
 pinMode(21,INPUT); // pir sensor output pin connected  
 pinMode(7,OUTPUT); // Green led pin  
 pinMode(8,OUTPUT); // Red led pin  
 pinMode(9,OUTPUT); // Buzzer pin  
 }  
 void loop()   
 {  
 val = digitalRead(21); // pir sensor output pin connected  
 Serial.println(val); // see the value in serial monitor in Arduino IDE  
 delay(100);  
 if(val == 0 )  
 {  
 digitalWrite(7,HIGH);  // Green led on  
 digitalWrite(8,LOW);  // Red led off  
 digitalWrite(9,LOW); // Buzzer on  
 }  
 else  
 {  
 digitalWrite(7,LOW);  // Green led off  
 digitalWrite(8,HIGH); // Red led on  
 digitalWrite(9,HIGH); // Buzzer off  
 }  
 }  

Main Code

Arduino
// SPRESENSE motion sensor
int val = 0 ;  

// defines pins numbers
 int trigerPin = 2;
 int echoPin = 3;
 int buzzer = 14;
 int ledPin = 15;

// defines variables
long duration;
int distance;
int v;

#include <DHT.h> 
 #define DHTPIN 4 // The data pin of DHT11/DHT22 should be connected to the digtal pin 4 of SPRESENSE.   
 #define DHTTYPE DHT11
 DHT dht ( DHTPIN, DHTTYPE ) ;

 void setup()  
 {  
 Serial.begin(9600);   // sensor buart rate  
 pinMode(1,INPUT);    // pir sensor output pin connected to D1  
 pinMode(6,OUTPUT);   // led pin  
 pinMode(10,OUTPUT);   // Relay PIN  
 digitalWrite(10,HIGH); // Relay Normaly OFF  

pinMode(trigerPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(buzzer, OUTPUT);
pinMode(ledPin, OUTPUT);

 pinMode(21,INPUT); // pir sensor output pin connected  
 pinMode(7,OUTPUT); // Green led pin  
 pinMode(8,OUTPUT); // Red led pin  
 pinMode(9,OUTPUT); // Buzzer pin  

 Serial.begin ( 9600 ) ;
 dht.begin (  ) ;    
 }  
 void loop()   
 {  
  
float humidity = dht.readHumidity ( ) ;  
  float Temprature = dht.readTemperature (true ) ;

   if ( isnan ( Temprature ) || isnan ( humidity ) ) {
     Serial.println ( " Sensor is not avaliable right now " ) ;  }

 else

{

Serial.print ( " Temprature is " ) ;  
     Serial.print ( Temprature ) ;         
     Serial.println ( " F " ) ;      
     Serial.print ( " Humidity in % is : " ) ;                    
     Serial.print ( humidity ) ;   
     Serial.print ( " % \t " ) ;     
                                                           
   }
  
 val = digitalRead(1); // pir sensor output pin connected  
 Serial.println(val); // see the value in serial monitor in Arduino IDE  
 delay(100);  

 // Clears the trigPin
digitalWrite(trigerPin, LOW);
delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigerPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigerPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

// Calculating the distance
distance= duration*0.034/2;

v = distance;


val = digitalRead(21); // pir sensor output pin connected  
 Serial.println(val); // see the value in serial monitor in Arduino IDE  
 delay(100);  

 if(val == 0 )  
 {  
 digitalWrite(7,HIGH);  // Green led on  
 digitalWrite(8,LOW);  // Red led off  
 digitalWrite(9,LOW); // Buzzer on  
 }  
 else  
 {  
 digitalWrite(7,LOW);  // Green led off  
 digitalWrite(8,HIGH); // Red led on  
 digitalWrite(9,HIGH); // Buzzer off  
 }  
 //}  

 if(val == 1 )  
 {  
 digitalWrite(6,HIGH);  // LED ON  
 digitalWrite(10,LOW);  // Relay ON   
 }  
 else  
 {  
 digitalWrite(6,LOW);  // LED OFF  
 digitalWrite(10,HIGH); // Relay OFF   
 }  
 //}  

if (v <= 5){
  digitalWrite(buzzer, HIGH);
  digitalWrite(ledPin, HIGH);
}
else{
  digitalWrite(buzzer, LOW);
  digitalWrite(ledPin, LOW);
}
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}

Credits

William Lu

William Lu

4 projects • 1 follower
A motivated biomedical engineer with experience in 3D CAD modeling, assembling, FEA, computer vision, and machine learning object detection.

Comments