Smart Home Security System
Author : Gabriela Alecu
Master : AAC2
Code + demo : Gabriela_IoT
1. Overview
The system intends to help in recognizing the identity of the person that rings a doorbell. It has two main components: a Raspberry pi that does the image capturing and image processing, and an Arduino Uno, that displays the name of the person and is connected to the locking mechanism. This is just a prototype built into a box designed with a 3D printer specifically for testing.
2. Diagram
The button was connected between the Arduino's digital pin 4 and its ground pin. I declared the variable that holds the state of the button as ” INPUT _PULLUP”, which keeps the voltage across the pin at 5 volts. When the button is pressed and the circuit is closed, the voltage goes to 0 and is registered by a reading on pin 4.
3. Arduino
Display
The display is a TFT 3' display designed for Arduino and Raspberry Pi boards. The interaction with the display is controlled by the built-in library
TFTdisplay.
In the initial setup, we use the library to set the text size and color, and write “e la usa!” on the second row of the screen. This text will stay there because we have 3 options to be displayed and for all of them the second row of the screen must be the same.
// clear the screen with a black background
TFTscreen.background(0, 0, 0);
// write the static text to the screen
// set the font color to white
TFTscreen.stroke(255, 255, 255);
// set the font size
TFTscreen.setTextSize(2);
// write the text to the top left corner of the screen, 20 rows below the top
TFTscreen.text("e la usa!\n ", 0, 20);
// ste the font size very large for the loop
TFTscreen.setTextSize(2);
LED
In the loop function, which runs continuously, we read from the serial connection and write the contents to the first line of the screen, checking if the received data matches the owner's name. If this is the case, we open the door.
The “open_door” function merely signals that the door is open via the connected LED by switching it on for 5 seconds.
if (Serial.available() > 0) {
//Erase the previous first line of the screen
TFTscreen.stroke(0, 0, 0);
//Write the name again because, if not, sometimes the screen would get black
TFTscreen.text(personName, 0, 0);
//Read name from serial
String name = Serial.readStringUntil('\n');
if (name == "Gabi"){
open_door();
}
else{
//Convert from string to Char Array so the print function of the screen works
name.toCharArray(personName, name.length()+1);
// print the sensor value
TFTscreen.text(personName, 0, 0);
}
}
The Arduino is connected to a button used to manually open the door. It is connected to a digital read pin defined with a pullup and the ground pin, and periodically checks the voltage on this pin. If it is 0, then the button is pressed and I call the function “open_door”.
void open_door(){
digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(5000);
}
if (buttonState == LOW) {
open_door();
}
else {
digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW
}
3. Raspberry Pi
Flow of the project
Create Dataset folders containing photos of the people that need to be later detected by the project.
Run the “train_model.py” script, which uses the Haar Cascade algorithm to create encodings.pickle - a file that describes the facial features of each person in the dataset folder.
Run the facial_req.py script, which takes photos with the camera and analyses them using the OpenCV library and the pickle file created in the previous step. The names of the people in the picture are stored in a list called “names”. Using this list, I can send the names of the detected people to the Arduino over the serial connection. The logic behind sending the text to the Arduino is as follows:
If a person is recognised and known - send the name of the person via the serial connection
If a person is detected and not known - send “Nu stiu cine” through the serial connection, which will result in “Nu stiu cine e la usa” on the Arduino screen
If no one is detected - send “Nimeni nu” over the serial connection, which results in “Nimeni nu e la usa” on the Arduino screen.
#The default value for name is "Nu stiu cine" that gets updated every frame.
if not names:
if oldName != "Nimeni nu\n":
oldName = "Nimeni nu\n"f
ser.write(oldName.encode('utf-8'))
else:
if oldName != names[0]:
oldName = names[0]
ser.write(oldName.encode('utf-8'))
4. The box
5. Conclusion
This project is a prototype to show that IoT can make our lives easier without us having to spend a lot of money.
After building the box, I learned that sometimes you have to take a step back and look carefully at what you are doing (many logic errors were not realized until after the box was built, such as the fact that the display does not say “Gabi e la usa”, or the fact that the LED is on the Arduino side instead of the Raspberry Pi)
The button was really fun to make
6. References