Ever lose something because of someone entering your room? To prevent intruders from entering a room when no one is in the house/office. To track every person’s entry or departure.
To prevent intruders from entering a room when no one is in the house/office. To track every person’s entry or departure.
This project will detect any intruders and alarm you are using the components of an LED, a buzzer, ultrasonic sensor, motion detector, smartphone app, and power supply.
Contribute to design and development of home security systems. Users will get alert when they open and close the door that is set with a sensor for detection.
The system is designed to detect intrusion (unauthorized entry) into a building or other area. This project can be used in residential, commercial, industrial, and military properties for protection against burglary or property damage, as well as personal protection against intruders
A compact, low-profile project is attached to the wall of the area which has to be monitored. This project consists of a camera and sensors that will capture the image of the intruder and notify the owner.
The Solution / How this Project works?This system is designed to provide security of houses and property. Below we will see that the basis for creating this system is the Sony Spresense Board. All sensors that belong to this project are connected to the Sony Spresense board.
A camera board (missing) will be used to monitor anyone entering and leaving the house. Security camera serves to send live video to an android app or iPhone app.
Sensors are set up by the owners of the property. The distance sensor serves to inform the owner of the house via the phone app that someone is outside the door and how far away he/she is.
Also, the distance sensor would serve as entry sensor, contact sensor, door sensor. It's used to detect/monitor entrances. The distance sensor will have pulse change due to door is opening. The alarm will go on when someone try to break into the house.
The speaker is placed inside the house where alerts can be easily heard. If motion is detected, the buzzer/alarm will go on, and a message will be sent to the phone app and turn on the lights in front of the house. When motion is detected, the camera will start to capture image or video when there are people moving in front the door.
The home security system consists of two parts from indoor to outdoor. Bring smart security inside and see what’s happening at home.
How it works. How does this project work?- Record and Capture: Record your videos and capture photos to review, save, and share the moments you missed at any time.
- Person Alerts: Customize your alerts and minimize interruptions by getting notifications only when your device spots a person.
- Rich Notifications: See exactly what triggered an alert with a photo preview right in the notification without opening the App.
How does Spresense board with PIR sensor Works?
If the pir sensor detect motion, the value of the variable pir_data will be 1 and the LED will turn on and buzzer (alarm) will buzz/trigger (go on). If there is no detect motion the value of variable will be 0 and the LED will turn off.
It will connect to the indoor camera(missing). When motion was detected, you could quickly check what's happening at home. Place a few indoor cameras to cover the entire house. Bring smart security inside and see what’s happening at home.
The LED go ON, the buzzer starts to beep. You might have just caught a thief trying to break-in...
PIR sensor connections
1). PIR to Sony Spresense Board
- Connect the Vcc of PIR to Vout 5V on Sony Spresense Board
- Connect the GND of PIR to GND on Sony Spresense Board
- Connect the OUTPUT pin of PIR to Digital pin D21 on Sony Spresense Board
2). Buzzer to Sony Spresense Board
- Connect one pin of buzzer to digital pin D9 on Sony Spresense Board
- Connect other pin of buzzer to GND on Sony Spresense Board
3). LEDs to Sony Spresense Board
- Connect a red LED positive to Digital pin D8 on Sony Spresense Board through a resistor.
- Connect a yellow LED positive to Digital pin D7 on Sony Spresense Board.
- Connect the LEDs negative to GND on Sony Spresense Board through a resistor.
HC-SR501 PIR Sensor Sensitivity and Time Delay is adjustable
- There are two potentiometers onboard.
- One is to adjust the sensitivity, and the other is to adjust delay time.
- Also, there are two trigger mode. One is Single trigger mode, which means that delay is started immediately upon detecting motion, and continued detection is blocked. The other is Repeatable trigger mode, timely delay is re-started every time motion is detected.
https://youtube.com/shorts/2l1Yx57YpeE
Code
// 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
}
}
Step 2: Door Security System with Ultrasonic SensorAn ultrasonic sensor will use to detect the unauthorized opening of your home's main door. The homeowner can track door activity in daily base.
As an IoT project designed using for Sony Spresense Challenge, I chosen to go with the idea of designing a simple home security system using Sony Spresense Board, an HC-SR04 ultrasonic sensor and the IFTTT app.
This system would operate as follows: Sony Spresense Board with a sensor attached to it is placed against the wall behind the main door of the home and is activated along with its components. As the door opens, it would normally swing towards the Sony Spresense Board, enabling the sensor to detect the close proximity of the opened door. The alarm will go on whenever an intrusion was detected. It will also connect to the camera to check who is enter and leave their place.
HC-SR04 ultrasonic sensor connections
- The HC-SR04 ultrasonic sensor has four pins out of which two are used to provide power to the sensor and the other two are for the data.
- Connect the VCC pin of the ultrasonic sensor to the VIN pin of the Sony Spresense Board.
- Join the GND pin of the ultrasonic sensor with the GND pin of the Sony Spresense Board.
- Connect the TRIG and ECHO pins of the ultrasonic sensor with the digital-2 and digital-3 pins of the Sony Spresense Board as shown below in the circuit diagram.
Now connect the Micro USB cable to the Sony Spresense Board so that the ultrasonic sensor starts working and you can see the values on the serial monitor screen.
Code
// defines pins numbers
int trigerPin = 2;
int echoPin = 3;
int buzzer = 14;
int ledPin = 15;
// defines variables
long duration;
int distance;
int v;
void setup() {
pinMode(trigerPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(buzzer, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// 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;
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);
}
Step 3: PIR SENSOR FOR Outdoor MOTION DETECTIONMotion been detected when someone come to your house, the camera (doorbell) will record front door activity.
At night, the light on the front door will turn on when people come to your property.
See What happens at home when you're not there. See what the kids do at home when you're not there. Alway know when and where your packages were delivered.
Receive notification when something happens, and even get alerts when the kids come home from school.
Schematics and connections
Connections
Sony Spresense Board PIR Sensor
D1 Pin OUT Pin
Vout ( +5V ) VCC
GND GND
Sony Spresense Board Relay Module
D10 Pin IN1 OUT Pin
Vout ( +5V ) VCC
GND GND
AC Bulb 220 V AC Supply Relay Module
Normally Open
Phase Common
Terminal 1 Normally Closed
Terminal 2 Neutral
Code
int val = 0 ;
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
}
void loop()
{
val = digitalRead(1); // pir sensor output pin connected
Serial.println(val); // see the value in serial monitor in Arduino IDE
delay(100);
if(val == 1 )
{
digitalWrite(6,HIGH); // LED ON
digitalWrite(10,LOW); // Relay ON
}
else
{
digitalWrite(6,LOW); // LED OFF
digitalWrite(10,HIGH); // Relay OFF
}
}
Doors
- Camera will take photo or video when there are movement in front door and front porch.
- Surround your home with smart outdoor security cameras and stop crime before it happens. Complete with built-in lights, sirens, and night vision, you’ll be connected and feel protected around the clock.
- The doors of our future will not need keys. To unlock your house, the smart door can use facial recognition. Any people that are not recognized as residents at the premises will need to be let in by a resident. The doors can further be programmed to open when you approach your home and close when you leave.
Smart lights include the ability to control your lights remotely, change colors, and modify the brightness in a room. You can make it look like you’re at home when you’re on vacation, or turn off all of the lights without even getting out of bed.
The Idea
Smart Lighting
- Turn the lights on anytime, anywhere with motion-activated lights with smart controls.
- When you enter your home, the lighting can be turned on automatically without the necessity to press a button.
- When you leave your home, the system can turn the lights off automatically to save energy, and you don’t have to worry about it.
- All the home lighting can be connected to your smartphone, laptop, and other connected devices.
In this IoT project, I have shown how to make IoT-based Smart Home Automation using NodeMCU ESP8266 to control all the home appliances from the switches & Blynk IoT App. If the internet is not available, then you can control the home appliances from manual switches.
This Home Automation system has the following features:
- Connect NodeMCUs with the Blynk IoT App
- Control home appliances with WiFi(Blynk IoT App).
- Control home appliances with manual switches.
- Monitor real-time feedback in the Blynk App.
- Control home appliances manually without internet.
- You can connect any number of microcontrollers in this IoT network as per the requirements.
Bill of Materials (BOM)
- NodeMCU ESP8266
- 4-channel SPDT 5V Relay Module
- Push Buttons or Switch x 4
- Jumper wires
- Light bulbs x 4
- Power supply
- LEDs x 5
- Terminal Connectors
- Blynk IoT
- Arduino IDE
If the NodeMCU is connected with WiFi, then you can control the home appliances from Blynk IoT App.
You also can use multiple smartphones to control the appliances with Blynk App. For that, you have to log in same Blynk account from all the smartphones.
In this way, all smartphones will be sink to the Blynk server. You can control, monitor the real-time status of the relays from anywhere in the world with the Blynk IoT App.
Circuit Diagram of the NodeMCU Control Relays
For the NodeMCU, I have used the GPIO pins D1, D2, D5 & D6 to control the 4 relays. And the GPIO pins SD3, D3, D7 & RX are connected with push buttons to control the 4 relays manually.
I have used the INPUT_PULLUP function in Arduino IDE instead of using the pull-up resistors.
I have used a 5V mobile charger to supply the smart relay module.
The D3 pin should not be connected with GND during the booting process of NodeMCU.
Code
/**********************************************************************************
* TITLE: Blynk + Manual Button (momentary) control 4 Relays using NodeMCU (Real time feedback + no WiFi control)
* Preferences--> Aditional boards Manager URLs :
* https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json
*
* Download Board ESP8266 NodeMCU : https://github.com/esp8266/Arduino
*
* Download the libraries
* Blynk 1.0.1 Library: https://github.com/blynkkk/blynk-library
* AceButton Library: https://github.com/bxparks/AceButton
**********************************************************************************/
/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_AUTH_TOKEN ""
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";
bool fetch_blynk_state = true;
//#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <AceButton.h>
using namespace ace_button;
// define the GPIO connected with Relays and switches
#define RelayPin1 5 //D1
#define RelayPin2 4 //D2
#define RelayPin3 14 //D5
#define RelayPin4 12 //D6
#define SwitchPin1 10 //SD3
#define SwitchPin2 D3 //D3
#define SwitchPin3 13 //D7
#define SwitchPin4 3 //RX
#define wifiLed 16 //D0
//Change the virtual pins according the rooms
#define VPIN_BUTTON_1 V5
#define VPIN_BUTTON_2 V6
#define VPIN_BUTTON_3 V7
#define VPIN_BUTTON_4 V8
// Relay State
bool toggleState_1 = LOW; //Define integer to remember the toggle state for relay 1
bool toggleState_2 = LOW; //Define integer to remember the toggle state for relay 2
bool toggleState_3 = LOW; //Define integer to remember the toggle state for relay 3
bool toggleState_4 = LOW; //Define integer to remember the toggle state for relay 4
int wifiFlag = 0;
char auth[] = BLYNK_AUTH_TOKEN;
ButtonConfig config1;
AceButton button1(&config1);
ButtonConfig config2;
AceButton button2(&config2);
ButtonConfig config3;
AceButton button3(&config3);
ButtonConfig config4;
AceButton button4(&config4);
void handleEvent1(AceButton*, uint8_t, uint8_t);
void handleEvent2(AceButton*, uint8_t, uint8_t);
void handleEvent3(AceButton*, uint8_t, uint8_t);
void handleEvent4(AceButton*, uint8_t, uint8_t);
BlynkTimer timer;
// When App button is pushed - switch the state
BLYNK_WRITE(VPIN_BUTTON_1) {
toggleState_1 = param.asInt();
digitalWrite(RelayPin1, !toggleState_1);
}
BLYNK_WRITE(VPIN_BUTTON_2) {
toggleState_2 = param.asInt();
digitalWrite(RelayPin2, !toggleState_2);
}
BLYNK_WRITE(VPIN_BUTTON_3) {
toggleState_3 = param.asInt();
digitalWrite(RelayPin3, !toggleState_3);
}
BLYNK_WRITE(VPIN_BUTTON_4) {
toggleState_4 = param.asInt();
digitalWrite(RelayPin4, !toggleState_4);
}
void checkBlynkStatus() { // called every 2 seconds by SimpleTimer
bool isconnected = Blynk.connected();
if (isconnected == false) {
wifiFlag = 1;
Serial.println("Blynk Not Connected");
digitalWrite(wifiLed, HIGH);
}
if (isconnected == true) {
wifiFlag = 0;
if (!fetch_blynk_state){
Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
}
digitalWrite(wifiLed, LOW);
Serial.println("Blynk Connected");
}
}
BLYNK_CONNECTED() {
// Request the latest state from the server
if (fetch_blynk_state){
Blynk.syncVirtual(VPIN_BUTTON_1);
Blynk.syncVirtual(VPIN_BUTTON_2);
Blynk.syncVirtual(VPIN_BUTTON_3);
Blynk.syncVirtual(VPIN_BUTTON_4);
}
}
void setup()
{
Serial.begin(9600);
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
pinMode(RelayPin3, OUTPUT);
pinMode(RelayPin4, OUTPUT);
pinMode(wifiLed, OUTPUT);
pinMode(SwitchPin1, INPUT_PULLUP);
pinMode(SwitchPin2, INPUT_PULLUP);
pinMode(SwitchPin3, INPUT_PULLUP);
pinMode(SwitchPin4, INPUT_PULLUP);
//During Starting all Relays should TURN OFF
digitalWrite(RelayPin1, !toggleState_1);
digitalWrite(RelayPin2, !toggleState_2);
digitalWrite(RelayPin3, !toggleState_3);
digitalWrite(RelayPin4, !toggleState_4);
digitalWrite(wifiLed, HIGH);
config1.setEventHandler(button1Handler);
config2.setEventHandler(button2Handler);
config3.setEventHandler(button3Handler);
config4.setEventHandler(button4Handler);
button1.init(SwitchPin1);
button2.init(SwitchPin2);
button3.init(SwitchPin3);
button4.init(SwitchPin4);
//Blynk.begin(auth, ssid, pass);
WiFi.begin(ssid, pass);
timer.setInterval(2000L, checkBlynkStatus); // check if Blynk server is connected every 2 seconds
Blynk.config(auth);
delay(1000);
if (!fetch_blynk_state){
Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
}
}
void loop()
{
Blynk.run();
timer.run(); // Initiates SimpleTimer
button1.check();
button2.check();
button3.check();
button4.check();
}
void button1Handler(AceButton* button, uint8_t eventType, uint8_t buttonState) {
Serial.println("EVENT1");
switch (eventType) {
case AceButton::kEventReleased:
Serial.println("kEventReleased");
digitalWrite(RelayPin1, toggleState_1);
toggleState_1 = !toggleState_1;
Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);
break;
}
}
void button2Handler(AceButton* button, uint8_t eventType, uint8_t buttonState) {
Serial.println("EVENT2");
switch (eventType) {
case AceButton::kEventReleased:
Serial.println("kEventReleased");
digitalWrite(RelayPin2, toggleState_2);
toggleState_2 = !toggleState_2;
Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);
break;
}
}
void button3Handler(AceButton* button, uint8_t eventType, uint8_t buttonState) {
Serial.println("EVENT3");
switch (eventType) {
case AceButton::kEventReleased:
Serial.println("kEventReleased");
digitalWrite(RelayPin3, toggleState_3);
toggleState_3 = !toggleState_3;
Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);
break;
}
}
void button4Handler(AceButton* button, uint8_t eventType, uint8_t buttonState) {
Serial.println("EVENT4");
switch (eventType) {
case AceButton::kEventReleased:
Serial.println("kEventReleased");
digitalWrite(RelayPin4, toggleState_4);
toggleState_4 = !toggleState_4;
Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);
break;
}
}
Smart securitySmart security includes cameras, motion detectors, doorbells, keypads, window sensors, smoke detectors, and whatever other products that are available through your system of choice. With IFTTT, you can create Applets that enable your system when no one is home, provide you with tailored notifications when something happens, and even get alerts when the kids come home from school.
Step 5: Temperature Control/MonitorWith temperature control automation, you can adjust the home temperature to the level that suits you best. Smart thermostats control the temperature based on configurations set by users in accordance with their preferences. These controllers can check your current activity and change the temperature accordingly.
Schematics and Circuit connections
Code
#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 ( ) { // Void setup is the function which technically created at the top of the program. It is used to initialize variables, pin modes, start using libraries, etc.
Serial.begin ( 9600 ) ;
dht.begin ( ) ;
}
void loop ( ) { // The loop is ran again and again and consists the main code.
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 " ) ;
}
}
ConclusionSmart home technology is available for every part of our households, furthering the reach of the internet of things. When it comes to building a smart home that works for you, knowing where to start can be hard. There are many benefits to having a smart home, including making your home more energy efficient, improving security, and upgrading your space to fit your lifestyle.
This project still needs to be improved. The ideal project will include some features of IoT and home automation. There are a lot of things that were needed to work out. to integrate all the parts or components.
Comments