Safe Deposit Box
Diana-Alexandra Predescu - ACES 2021
Project description
The purpose of this project is to simulate a safe deposit box that can be remotely controlled through a Web server. This application can easily be integrated into the concept of smart house. For this project I will only focus on the remotely controlled part.
In this project, the box can only be opened/closed with buttons from a Web server, after connecting to Wi-fi. With the help of two sensors, the application can figure out when something isn’t right and change the status of the box in the Web server. If the door is broken without opening it from the Web page, or it detects accelerated movement the system alerts the user with a status message in the Web server. All the above was possible by interfacing ESP 32 microcontroller to the external modules.
Hardware description
The modules used to achieve the functionality mentioned above are:
FXLN8371 Accelerometer: the module measures the rate of change of the velocity of an object in G-forces(g). The FXLN8371Q offers an analog interface, which measures acceleration from the variation between ground and power supply voltage. The voltage level from the output pins can be converted with an ADC to a binary value to be interpreted by the processor. In order to offer accuracy, the accelerometer had to be calibrated first. It is connected to the 3.3V power supply coming from MCU, XOUT to GPIO34, YOUT to GPIO35 and ZOUT to GPIO32.
The electrical schematic of the circuit and the breadboard implementation can be found below:
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.
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.
Below is the flow diagram of the system.
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