Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:proiecte:2022:smart_home_security_system [2023/01/19 23:08]
cornelia.alecu1003 [Display]
iothings:proiecte:2022:smart_home_security_system [2023/01/20 00:43] (current)
cornelia.alecu1003 [6. References]
Line 1: Line 1:
 ====== Smart Home Security System ====== ====== Smart Home Security System ======
-Author: **Gabriela Alecu** +Author ​     : **Gabriela Alecu** ​\\ 
- +Master ​     : **AAC2** \\ 
-Master: **AAC2**+Code + demo : **[[https://​github.com/​Gabriela1003/​IoT|Gabriela_IoT]]**
  
 ====== 1. Overview ====== ====== 1. Overview ======
Line 21: Line 21:
 ====== 3. Arduino ====== ====== 3. Arduino ======
 ===== Display ===== ===== 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 [[https://github.com/arduino-libraries/TFT|TFTdisplay]].+  *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 [[https://docs.arduino.cc/library-examples/tft-library/​TFTDisplayText|TFTdisplay]]. 
 + 
 +[[https://​www.elektor.com/​2-2-spi-tft-display-module-ili9341-240x320|{{ :​iothings:​proiecte:​2022:​display_gabi_a.png?​150 }}]] 
 +  *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. 
 +<code C > 
 +// 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);​ 
 +</​code>​ 
 +{{ :​iothings:​proiecte:​2022:​nimeni_gabi_a.jpeg?​200 |}} 
 +===== 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. 
 +<code C > 
 +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); 
 +  } 
 +
 +</​code>​ 
 +{{ :​iothings:​proiecte:​2022:​led_aprins_gabi_a.jpeg?​200 |}} 
 +===== Button ===== 
 +  *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"​. 
 +<code C> 
 +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 
 +
 +</​code>​ 
 + 
 +{{ :​iothings:​proiecte:​2022:​buton_gabi_a.jpeg?​200 |}} 
 + 
 +====== 3. Raspberry Pi ====== 
 + The raspberry pi has been configured using [[https://​www.tomshardware.com/​how-to/​raspberry-pi-facial-recognition|Facial recognition guide]],  
 +and it uses code provided by this [[https://​github.com/​carolinedunn/​facial_recognition|git repository]],​ that uses the OpenCV library for the facial detection. 
 +{{ :​iothings:​proiecte:​2022:​camera_gabi_a.jpeg?​250 |}} 
 + 
 +===== 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. 
 +<code C> 
 +#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'​)) 
 +</​code>​ 
 + 
 +====== 4. The box ====== 
 +The box has been designed in Fusion 360, sliced using Prusa Slicer and printed on a Prusa Mini. 
 +{{:​iothings:​proiecte:​2022:​bot_gabi_a.png |Bottom }} 
 +{{ :​iothings:​proiecte:​2022:​top_gabi_a.png |Top }} 
 +{{ :​iothings:​proiecte:​2022:​but_gabi_a.png |Button}}
  
-[[https://​www.elektor.com/2-2-spi-tft-display-module-ili9341-240x320|{{:​iothings:​proiecte:2022:​display_gabi_a.png?150 }}]]+====== 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 ====== 
 +  - https://​www.tomshardware.com/how-to/​raspberry-pi-facial-recognition 
 +  ​https://​docs.arduino.cc/​library-examples/​tft-library/​TFTDisplayText 
 +  - https://github.com/​carolinedunn/​facial_recognition
iothings/proiecte/2022/smart_home_security_system.1674162536.txt.gz · Last modified: 2023/01/19 23:08 by cornelia.alecu1003
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0