This shows you the differences between two versions of the page.
iothings:proiecte:2022sric:home_security_system [2023/06/01 23:36] robert.delicostea [Software Design] |
iothings:proiecte:2022sric:home_security_system [2023/06/02 00:52] (current) robert.delicostea |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Home security System ====== | + | ====== Home Security System ====== |
* Student: Delicostea Robert-Alexandru | * Student: Delicostea Robert-Alexandru | ||
Line 35: | Line 35: | ||
The code for the system is written in Android IDE and the Blynk app. Blynk is an IoT platform for iOS or Android smartphones that is used to control Arduino, Raspberry Pi and NodeMCU via the Internet. This application is used to create a graphical interface or human machine interface (HMI) by compiling and providing the appropriate address on the available widgets. | The code for the system is written in Android IDE and the Blynk app. Blynk is an IoT platform for iOS or Android smartphones that is used to control Arduino, Raspberry Pi and NodeMCU via the Internet. This application is used to create a graphical interface or human machine interface (HMI) by compiling and providing the appropriate address on the available widgets. | ||
+ | |||
+ | {{:iothings:proiecte:2022sric:blynk_browser.png?700|}} | ||
=== Arduino Code === | === Arduino Code === | ||
Line 73: | Line 75: | ||
</code> | </code> | ||
+ | |||
+ | In the measureDistance function the condition is that if everyone goes closer than 10 cm the buzzer will start ringing with a notification on the Blynk app appearing if the password is introduced wromng 3 times, The distance is also updated on the Blynk widget Gauge. | ||
+ | |||
+ | <code> | ||
+ | Blynk.virtualWrite(distancePin, distance); | ||
+ | |||
+ | Serial.print("Distance: "); | ||
+ | Serial.print(distance); | ||
+ | Serial.println(" cm"); | ||
+ | |||
+ | if (distance < 10) { | ||
+ | activateBuzzer(7000); | ||
+ | | ||
+ | | ||
+ | Serial.print(attempts); | ||
+ | if(attempts == 3){ | ||
+ | Blynk.logEvent("button_pushed", String("Password introduced incorrectly 3 times!")); | ||
+ | attempts = 0; | ||
+ | } | ||
+ | | ||
+ | delay(5000); | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | {{:iothings:proiecte:2022sric:correct_password.jpeg?150|}} | ||
+ | {{:iothings:proiecte:2022sric:gauge.jpeg?150|}} | ||
+ | {{:iothings:proiecte:2022sric:incorrect_pasword.jpeg?150|}} | ||
+ | {{:iothings:proiecte:2022sric:correct_password.jpeg?150|}} | ||
+ | |||
+ | In the activateBuzzer function the number of times the button needs to pressed is set and the owner sees it on the Blynk app and in the handleButton the buzzer is stopped if the number is reached | ||
+ | |||
+ | <code> | ||
+ | passNumber = random(3, 10); | ||
+ | Blynk.logEvent("button_pushed", String("Buzzer activated, password is press button ") + passNumber + String(" times")); | ||
+ | </code> | ||
+ | |||
+ | <code> | ||
+ | // Check if the button state has been stable for the debounce delay | ||
+ | if (millis() - lastDebounceTime >= debounceDelay) { | ||
+ | // Update the button state only if it has changed | ||
+ | if (reading != buttonState) { | ||
+ | buttonState = reading; | ||
+ | |||
+ | // If the button is pressed (LOW) and the buzzer is active, increase the press count | ||
+ | if (buttonState == LOW && buzzerActive) { | ||
+ | buttonPressCount++; | ||
+ | Serial.println(buttonPressCount); | ||
+ | |||
+ | |||
+ | // If the button has been pressed passNumber or more times, stop the buzzer | ||
+ | if (buttonPressCount >= passNumber) { | ||
+ | Serial.println("hereeeee"); | ||
+ | digitalWrite(buzzerPin, LOW); | ||
+ | buzzerActive = false; | ||
+ | buttonPressCount = 0; | ||
+ | return true; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ==== Demo ==== | ||
+ | [[https://drive.google.com/file/d/1RYqV6uQVkARoj2Cm0B9M-EyMoeUGO6nH/view?usp=sharing|Demo of Application]] | ||
+ | |||
+ | [[https://github.com/alex99delicostea/Iot_security_system|Full code]] | ||
+ | |||
+ | ===== References ===== | ||
+ | * https://docs.blynk.io/en/ | ||
+ | * https://randomnerdtutorials.com/esp32-hc-sr04-ultrasonic-arduino/ | ||
+ | * https://esp32io.com/tutorials/esp32-piezo-buzzer | ||
+ | * https://app.diagrams.net/ | ||
+ | * https://www.circuito.io/ |