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 connection between the Raspberry Pi and the Arduino Uno is established via a USB cable, since both have USB interfaces.
  • The webcam was connected to the Raspberry pi via the supplied USB port.
  • 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.
  • The LED is connected between digital pin 6 and ground. When the LED is opened, the voltage on this pin rises to 5 V. A 220Ohm resistor has been added in series with the LED.

3. Arduino


  • 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
// 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


  • 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"){
   //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)
if (buttonState == LOW) {
else {
  digitalWrite(LED_PIN, LOW);   // turn the LED off by making the voltage LOW

3. Raspberry Pi

The raspberry pi has been configured using Facial recognition guide, and it uses code provided by this git repository, that uses the OpenCV library for the facial detection.

Flow of the project

  1. Create Dataset folders containing photos of the people that need to be later detected by the project.
  2. Run the “” 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.
  3. Run the 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:
    1. If a person is recognised and known - send the name of the person via the serial connection
    2. 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
    3. 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
		if oldName != names[0]:
			oldName = names[0]

4. The box

The box has been designed in Fusion 360, sliced using Prusa Slicer and printed on a Prusa Mini. Bottom Top Button

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

iothings/proiecte/2022/smart_home_security_system.txt · Last modified: 2023/01/20 00:43 by cornelia.alecu1003
CC Attribution-Share Alike 3.0 Unported Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0