Table of Contents

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

3. Arduino

Display

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

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);
  }
}

Button

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

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 “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.
  3. 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:
    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
			ser.write(oldName.encode('utf-8'))
	else:
		if oldName != names[0]:
			oldName = names[0]
			ser.write(oldName.encode('utf-8'))

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

6. References