This shows you the differences between two versions of the page.
iothings:proiecte:2021:safedepositbox [2022/01/26 20:02] diana.predescu |
iothings:proiecte:2021:safedepositbox [2022/01/27 21:47] (current) diana.predescu [References] |
||
---|---|---|---|
Line 30: | Line 30: | ||
The electrical schematic of the circuit and the breadboard implementation can be found below: | The electrical schematic of the circuit and the breadboard implementation can be found below: | ||
+ | {{ :iothings:proiecte:2021:safedeposit_electric.jpg?600 |}} | ||
+ | {{ :iothings:proiecte:2021:safedeposit_pcb.jpg?600 |}} | ||
+ | ====== Software description ====== | ||
+ | The application was developed using Arduino IDE. | ||
+ | To facilitate the software development the following libraries were used: | ||
+ | * **WiFi.h** and **WiFiClient.h** for Wi-Fi connection. Now, the Wi-Fi network credentials are hardcoded into the application. Using these libraries, the MCU can connect to the network. We save the IP assigned for the Web Client application. | ||
+ | * **ESPAsyncWebServer.h** to facilitate the web server handlers based on HTTP requests. | ||
+ | * **ESP32Servo.h**, offering methods to control the servo motor. | ||
+ | |||
+ | Since we will display constantly the sensors values in the Web page, I chose to create the HTML page using AJAX (Asynchronous JavaScript and XML) which allows me to update only the values coming from the sensors in the background. This eliminates the flickering when refreshing the whole Web page. | ||
+ | |||
+ | {{ :iothings:proiecte:2021:safedeposit_web.jpg?400 |}} | ||
+ | |||
+ | The Arduino application is structured into 2 parts. The setup part where all the initializations are made, a code that is executed only once at the beginning of the application, and the loop, which will listen to the client’s requests and will act accordingly to the handlers. | ||
+ | |||
+ | -//**setup()**//: the following points are approached | ||
+ | * Wi-Fi configuration and connection. | ||
+ | * Calibration of the accelerometer – we measure 16 times and do the average value to find the offset for every axis (initial values for the start position). From the Z-axis we substract the sensitivity based on the sensor datasheet. | ||
+ | * Servo motor configuration – frequency, minimum and maximum position based on the datasheet. | ||
+ | * Attaching an interrupt on the pin coming from the optic sensor, in “RISING” mode. Every time the obstacle is removed from the LED light front, simulating the door opening, the signal goes from 0 to 1 and the interrupt is called, verifying if the door was opened as well. If yes, the box status is ok. If the optic sensor is triggered and the door was not opened previously, the status is changed to “Check the box” and the user must reset the system. | ||
+ | * Attaching Handlers on the HTTP_GET requests from Web page. We have 4 handlers corresponding to Web page creation, get accelerometer values, close/open door, get the system status. | ||
+ | -//**loop()**//: in this function we only listen to the client side and call the corresponding handlers. | ||
+ | * After connecting to the IP address, the HTML page is created. Every 2 second, the accelerometer does a measurement and answers to the HTTP request with the corresponding values, values which will be updated in the box. Moreover, at every measurement, we check the measured value with the initial one, if we detect a rate of velocity change beyond the interval set, we alert the user by updating the system status. The status is updated every 2 seconds in the page. Furthermore, the application offers 3 buttons. One for “Open” door, which will load the appropriate value onto the control pin of the servomotor (from 0 to 180 degree), one for “Close” door which does the same as the previous only from 180 to 0 degree, and one for “Reset” that will reset the system. This can be used for further development of blocking the safe box if it is broken into. | ||
+ | * The system status that needs to alert the user can be updated from 2 use cases: | ||
+ | - The optic sensor is triggered without opening the door; | ||
+ | - When the accelerometer detects a bigger change in the velocity; | ||
+ | |||
+ | Below is the flow diagram of the system. | ||
+ | |||
+ | {{ :iothings:proiecte:2021:safedeposit_flowchart.jpg?600 |}} | ||
+ | |||
+ | ====== Issues and solutions ====== | ||
+ | |||
+ | Issues found and possible solutions: | ||
+ | |||
+ | * Updating sensor values without the user needed to refresh the page manually -> solved by using AJAX based server. | ||
+ | * Sometimes when the servo motor is working the accelerometer gives inaccurate values -> Not solved. Assuming it might be linked to the power consumption. One possible option might be to connect the servo motor to external power supply. | ||
+ | * Not a secure environment. The application hardcodes the network credentials. -> Not solved | ||
+ | |||
+ | ====== Conclusions ====== | ||
+ | |||
+ | The project can be considered a starting point or at least a part of the “Smart House” and “Smart appliances” concept, concept which is supposed to ease the user life and give a feeling of being safe and being in control. It also gives a brief view into how a MCU can interact with different external modules. The idea behind the project was to integrate into the IoT world that nowadays is everywhere, something that can benefit a wide interval of people, without limit of age, something that can be used on a daily basis. | ||
+ | |||
+ | ====== References ====== | ||
+ | - [[https://www.studiopieters.nl/esp32-pinout/]] | ||
+ | - [[https://circuits4you.com/2018/11/20/web-server-on-esp32-how-to-update-and-display-sensor-values/]] | ||
+ | - [[https://community.nxp.com/t5/Sensors-Knowledge-Base/FXLN8371Q-Bare-metal-example-project/ta-p/1115769]] | ||
+ | - [[https://randomnerdtutorials.com/esp32-async-web-server-espasyncwebserver-library/]] | ||
+ | - [[https://plnkr.co/edit/7DyTmdRdWSIRxx7ESLNv?p=preview&preview]] | ||
+ | - [[https://lastminuteengineers.com/handling-esp32-gpio-interrupts-tutorial/]] | ||
+ | - [[https://opencircuit.shop/product/TCST2103-Optical-end-stop-switch]] | ||
+ | - [[https://www.sigmanortec.ro/servomotor-sg90-360-continuu?gclid=Cj0KCQiA_8OPBhDtARIsAKQu0gYUbu3QN9EktVsSClm3-2gf7LAs8kbGUps8t_yb5ecG-BYjeJB7BwgaAvcyEALw_wcB]] | ||
+ | |||
+ | Materials: https://gitlab.com/dianaalexandra5/safe-deposit-box | ||
+ | |||
+ | | ||
+ | |||