Open the Box 📦
Hello friend! The repo you are currently looking at is/was the project for FCUP's Embedded Systems course. In this project our objective is to create a box that can only open by entering a specific code through physical actions. To do this we combined three different systems, them being:
- Arduino
- Raspberry Pi
- Android App
The idea was to make the box only open with a certain code created by the user via Android App, then the box is locked and the only way to get to open it is to type in the exact same code also in the Android App.
Components Used
- Arduino Mega 2560
- Raspberry Pi 4 (Server)
- 1602 LCD Keypad Shield For Arduino
- Light Sensor
- ICM20948
- SD Card 16GBs
- 3 Leds
- Servo Motor (Lock)
- Módulo Buzzer Passivo 5V (Sound Output)
- Connections (Wires, resistors, etc.)
What is each component used for
- Arduino -> This is the "brain" behind the physical actions of the box, its functions are locking and unlocking the door by checking if the codes being tried are correct, controll the Buzzer, the Motor and the Leds
- Raspberry Pi -> This is basically the Server that connects the Android App to the Arduino
- Keypad -> Used to code if you need to
- Light Sensor -> Used for for luminosity
- Accelerometer ->
- SD Card -> Used to have Raspberry Pi OS
- 3 Leds -> Used to send informations relative to the box
- Motor -> Used to lock or unlock the box
- Buzzer -> Used for the alarm
- Connections -> Literally just connections
How it Works
Android App
The android application is used for sending the configuration to the box. This app also lets the user unlock/lock the box, check status (and failed attempts) and disable the alarm. For this, the application connects to the server through MQTT and communicates that way.
Server
As mentioned above, the server consists of a Raspberry Pi 4. This device is running a docker instance that contains a MQTT server. This server is used for receiving commands from the smartphone application and transmitting this information to the box (Arduino Mega 2560) through a serial connection.
The Box
The box has four different states:
- open_and_configured: Means that the box contains the code list and is open.
- closed_and_configured: Means that the box contains the code list and is closed, waiting for the code sequence.
- waiting_config: The box is open and is waiting for the configuration.
- alarming: Means that the box is on alarm mode.
The box starts in the mode waiting_config. Here, the LEDs are blinking (starting on RED, through yellow and finally green). This mode is checking the Serial port for any packets that contain information related to the config (or any other that applies, for that matter). When the packet is received, it is parsed and saved. After this, the state is set to open_and_configured if it was waiting for the configuration, otherwise it remains the same state as the last one. Now, we can lock the box. In this mode, the box is still waiting for commands and blinking the GREEN LED, meaning that it is ready to be locked (through the phone). After being locked, the state is set to closed_and_configured. Here, we also read packets (in case we want to unlock the box or change the configuration). But, we can also start the code sequence by pressing the '*' key on the keypad that is located in the back of the box. The box ignores any commands unless '*' is pressed. When and if the user presses the '*' key, the sequence begins. For each action, the LEDs will change colors just like a 'race' semaphore would. The countdown begins by setting the RED LED first, then the YELLOW and finally the GREEN one. Now, the user can input the sequences. For each action, the box will alert if the user did it right by sounding the buzzer in a high frequency and lighting the GREEN LED for a bit, and if the user did it wrong it won't do any of those actions. All reports are sent to the smartphone application as well (when a user hits or misses the action). Keep in mind that these actions are time-limited and score-based, meaning that simply hitting a value for one second is not enough, try to perform the action for several seconds straight for maximum accuracy. Moving on, if the user misses a code three consecutive times in a span of five minutes, the state of the box will be set to alarm, where the owner can reset it by accessing the smartphone application and pressing the respective button. If the user hits all the actions correctly - the box will unlock, the GREEN LED will blink and a sound will be emitted for a short period of time.
Contributors
- Daniel Resende (202204702)
- Hugo Sales (201704178)
- João Lopes (201805078)