2023 Group 7 – SecuroBag
Chosen Project Brief
“Being able to check on the security of your home, family members and belongings while away and in various locations around the world is of interest to you not only from the security perspective but also to ensure safety and peace of mind. The camera is the most component device that is used nowadays to ensure you capture any abnormalities or intruders but recently radio signals, voice and also heat have been used to complement or replace the camera. For this project, we encourage you to start thinking of a simple, low-effective home security system with the camera not being the centre of it. You could use microphones, infra-red sensors and also wireless shields to be able to detect movements, presence and also changes in the home environment from a distance through a website or phone app. Remember to be creative but also realistic considering the time available and budget.“
Project Overview
Team Members:
- Run Lin Liu
- Justin Smith
- Yesh Chandiramani
Product Description:
In today’s bustling and chaotic world, our attention is constantly pulled in multiple directions, making us more susceptible to theft. The hustle and bustle of crowded places, coupled with attention-grabbing stimuli, has created an environment where unsuspecting individuals become easy targets for thieves. Recognizing this growing concern, we introduce SecuroBag – the innovative backpack equipped with a built-in alarm system designed to not only protect your belongings but also alert you and those nearby of potential criminal activity.
SecuroBag addresses two primary issues: the prevention of pickpocketing (the unauthorized removal of items from an unattended bag) and bag theft (theft of the entire bag). The key to its effectiveness lies in two crucial components: a smart zipper that senses when the bag is opened and a Bluetooth module that notifies the user when the bag is taken out of their immediate vicinity.
Operating SecuroBag is simple yet highly secure. With just a touch of an RFID tag, a user can easily arm and disarm their bag. When armed, any attempt to open the bag without authorization triggers a loud alarm, immediately deterring thieves and preventing further action. Additionally, through Bluetooth technology, SecuroBag sends real-time notifications to the user when the bag has moved away from their immediate surroundings. This feature empowers users to confront and thwart potential thieves, ensuring the safety of their valuables at all times.
Project Planning
Project Planning Chart
Project Task List
Design Process
Ask (Nov 13 – Nov 15)
In the design process that we embarked on, we started the asking phase by asking each other what problems we have faced in our day-to-day lives. As we shared a list of our problems, there was one mutual problem among us: when we are alone in a cafe or library, we take all our belongings with us to avoid leaving them unattended and end up losing our seats. This problem has bothered all of us for years, and this was an opportunity for us to devise a solution together.
Research (Nov 15 – Nov 20)
After settling on the problem and deciding that university students like us would be our intended audience, we decided to dissect all the pain points and concerns generated by leaving our bags unattended while we were in the bathroom. We came up with the following list:
- someone stealing your entire bag
- someone stealing items from your bag (noticeable and unnoticeable)
- someone opening your bag to slip something inside
We discussed these pain points and concerns among ourselves and friends who have experienced these problems. We realized that we don’t have to make the bag impossible to steal from but need to have some protective measures in place to deter people from tampering with the bag. This insight and listing out the pain points and concerns helped us better understand the problem and our solution.
Imagine (Nov 21 – Nov 22)
With the pain points and concerns in mind, we imagined and discussed some potential solutions. One solution was to create a bag with a GPS tracker (like an Apple air tag) and make the zipper impossible to open by anyone besides the backpack owner. This was the most obvious solution, but it would have been too complex for us to build. The other solution we arrived at was to add an alarm to the bag’s zipper, and it would go off when the zipper was unzipped. This solution fits our needs almost perfectly because it would allow us to know if someone has stolen and/or slipped something from/into the bag, and the alarm would draw the attention of bystanders, causing the thief to be caught in the act. Unfortunately, having an alarm on the bag would not help if the entire bag is stolen, so we came up with the solution of keeping track of when the bag was last in range of the owner and relying on bystanders and security cameras to assist with finding the thief who stole the bag. By stitching the idea of keeping the bag in range and an alarm for the zipper, we settled on an idea for our solution that met the needs of our intended audience.
Storyboards of the Idea
Plan (Nov 22 – Nov 24)
Now that we had a potential solution in mind, we had to plan out how to check if the bag was out of the range of the owner and trigger an alarm when the zipper became unzipped.
Checking if the bag was out of range of the owner
Before we could consider what hardware components could solve our problem, we needed to define what out-of-range means and what assumptions we could make to assist us in prototyping our solution rapidly. Since the problem originated with going to the bathroom in a cafe or library, we decided that our maximum distance in the range had to be more than 20 meters but less than 100 meters. Also, our intended users are university students, so we can assume that they almost always have their phones with them. We hypothesized that a Bluetooth connection between the bag and the owner’s phone would fit our requirements. To validate our hypothesis, one of us wore a pair of Bluetooth earphones connected to a phone that was playing music and went into the bathroom of a local cafe. Despite being 60 meters away, the music continued playing, which meant a Bluetooth connection would suffice for our solution’s use case.
Trigger an alarm when the zipper is unzipped
To implement this idea, we had to break the concept into two components: detecting the zipper’s state and sounding the alarm. To sound the alarm, we decided to use a piezo buzzer because that is a readily available component in our experimenter’s kit. All that was left was to figure out how to detect the zipper’s state. Since the zipper of the backpack we were going to use is metallic, we decided to use that to our advantage and create a circuit that would close when the zipper is unzipped. To make a circuit that closes when the zipper is unzipped, we had to find an area of the zipper track that the zip would pass through when unzipping the bag. Since the zipper track was connected to a nylon material and that circuit must be robust, we decided that sowing conductive thread to the end of the zipper track would be best suited for accomplishing the task.
RFID Authentication
After developing the technical solutions needed to bring our idea to life, we realized that we didn’t have a way to identify if the bag was armed and should sound the alarm when the zipper was unzipped or disarmed and function like a normal bag. After discussing the problem, our initial solution was to use the Bluetooth connection to send arm and disarm commands to the bag’s microcontroller. This solution would have worked fine, but it is not the most convenient or intuitive to our target users, university students, because this process mapped to arming/disarming a house’s security system, and that is not a standard mapping for university students. Therefore, we decided to map the arming/disarming process to the locking/unlocking of one’s car, a process a university student would be much more familiar with. To achieve the mapping of unlocking/locking one’s car, we decided that hovering an authorized RFID token over an RFID reader would accomplish the job.
Prototype Plan
The plan for the prototype was broken down into three distinct components that each team member would be responsible for building:
- Bluetooth Connectivity (Yesh)
- RFID Authentication (Justin)
- Zipper Alarm (Run Lin)
Create (Nov 27 – Dec 6)
Lo-Fi Prototypes (Nov 27 – Dec 1)
Bluetooth Connectivity:
The Lo-Fi prototype for Bluetooth Connectivity was to get the HC05 Bluetooth Module to spawn up an interface named SecuroBag, and read messages sent from the phone to the Arduino. The messages that were sent from the phone were done by using the Android Bluetooth Serial Terminal app. The purpose of this prototype was to identify how to create a Bluetooth connection and communicate between the phone and Arduino. This prototype was a success!
The code running on the Arduino is as follows:
#include <SoftwareSerial.h>
// Set up a Serial interface to between the Arduino and HC05 Bluetooth Module using Pins 2 & 3 for Receiving and Transmitting data
SoftwareSerial myBluetooth (2,3);
void setup() {
// put your setup code here, to run once:
// Start the Serial Monitor in the Arduino IDE with a 9600 Baud Rate
Serial.begin(9600);
// Start the Serial interface between the Arduino and HC05 Bluetooth module on the 9600 Baud Rate
myBluetooth.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
// Check if there is data being sent from the Bluetooth Module to the Arduino (Bluetooth Module got the data from the Phone its connected to)
if (myBluetooth.available()) {
// Read the available data as a String
String data = myUart.readString();
// Print the data to the Serial Monitor in the Arduino IDE
Serial.println(data);
}
}
RFID Authentication
The LoFi prototype for the RFID Authentication component was setting up a basic circuit that read an RFID tag and dumped the information about the RFID tag to the Serial Monitor in the Arduino IDE The Arduino code used for this prototype was provided by the MFRC522 Library’s example code. The purpose of this prototype was to identify how the RFID reader should be set up and the experience of reading the RFID tag.
This prototype was particularly tough to get working because we had issues with the wiring and connectivity between the RFID Reader component and Arduino pins. Thankfully, our persistence prevailed, and Justin was able to successfully prototype the RFID Authentication.
Zipper Alarm
The LoFi prototype for the Zipper Alarm was to create a circuit using conductive thread sown to an old pencil case’s zipper track that lights up an LED when the zipper is being unzipped. The purpose of this prototype was to identify how to use the conductive thread on a zipper track to check the state of the zipper and the experience of zipping/unzipping the pencil case with the conductive thread sewn on the zipper track. This prototype was also successfully built!
The code for the prototype:
int ledPin = 9;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
// Light up when the circuit is closed (aka when the zip is being unzipped)
digitalWrite(ledPin, HIGH);
}
HiFi Prototype Design Decisions (Dec 1 – Dec 6)
Using the experience from our LoFi prototypes, we implemented our respective components into one Arduino and the backpack.
External View of the Prototype:
We wanted the prototype to resemble to look of an ordinary bag. We did not entirely achieve this because the Alarm and State LED dangles on the outside of the bag, which is a bit odd. However, we needed to have the Alarm and State LED dangle on the outside of the bag because we needed the visual and audio feedback to be clear to the user. The current external view of the prototype looks more or less like an ordinary bag, which is good enough for a prototype.
Wiring Inside the Bag:
The wiring is mostly contained within the backpack, and the Arduino is powered by a 5V power bank that is in the backpack (second image). The only pieces that are sticking out are the Alarm and State LED (last image).
RFID Reader:
The RFID reader is taped close to the zipper track on the inside of the backpack, which allows the user to easily wave their RFID token to arm or disarm the bag. Since the RFID reader is not perceived at first glance by the user, we intentionally placed a piece of tape on the outside of the bag to signify this hidden affordance. The feedback from the interaction the user may have with the RFID reader is conveyed through sounds produced by the piezo buzzer (the Alarm). We have programmed the buzzer to have three distinct sounds: arming/disarming error, arming success, and disarming success. The error sound starts from a high pitch and progresses to a lower pitch, which maps to the user’s conceptual model of error sounds from games like Mario. Similarly, the success sounds maintain a high pitch and map to the user’s conceptual model of success sounds from games.
Bluetooth Connectivity:
The connection state of Bluetooth has no visible feedback except if the user checks their phone. To combat this, we rely on the piezo buzzer (the Alarm) to play a sound to relay the feedback on the connection state of the Bluetooth module. This fits the conceptual model that a university student may already have when they connect their phone to a Bluetooth audio device.
State LED:
The state LED helps indicate to the user if the bag is currently armed (on) or disarmed (off). The feedback from the LED is crucial for the user because they can quickly understand if their interaction with the bag was successful or not. Moreover, we deliberately used a red LED because people have a mapping of the color red with danger. We want to leverage the idea of danger to deter people from tampering with the user’s bag.
Conductive Thread:
As seen in the first image on the last row, the conductive thread is sewn onto the end of the zipper track. We picked a darkish green color to blend into the dark color of the bag but still be visible to the user upon careful inspection so that they know what position the zipper needs to be in for the bag to be armed.
HiFi Prototype Logic
Since the HiFi prototype has three individual components that need to be operating together, we decided to implement the logic for the prototype through the lens of a Finite State Machine (FSM). The FSM perspective allowed us to easily integrate all the individual components and constrain the available actions with the prototype. By constraining the available actions, we are able to minimize human error.
Our process of devising the state machine logic was as follows:
- Identify all possible states for the prototype
- At each state, think about all possible actions that can occur for the state and decide if those actions are necessary
- For all necessary actions, draw an error from the start state to the end state and label the action and its effects on the prototype
- After all the actions for all the states have been outlined, go through different scenarios of using the prototype and operate the logic using the state machine diagram
Final State Machine Diagram:
An example of minimizing human error by limiting the actions to only the necessary actions is only allowing the bag to be armed when the Bluetooth connection to the owner’s device is established because the Bluetooth connection is core to the thesis of our prototype— having theft detection mechanisms in place will deter people from tampering with one’s bag.
Testing (Dec 7 – Dec 8)
Our testing methodology for the HiFi prototype involved comprehensive run-throughs of the bag’s workflow in accordance with the state machine diagram. These workflows were designed to validate the prototype’s efficacy in safeguarding users’ belongings.
Testing Evaluation
The primary emphasis was placed on the alarm system, with the objective of ensuring it is activated only when necessary. The goal was to prevent any unwarranted alarms that could potentially induce panic without cause. Through repeated simulations, we meticulously verified that the alarm functioned precisely as intended, activating only in response to genuine security threats. This meticulous approach aimed to eliminate any possibility of false alarms, thereby providing users with a reliable and stress-free experience. The video above demonstrated the capabilities of the HiFi Prototype and everything we set out to achieve with respect to functionality was successful!
Known Shortcomings & Improvements (Dec 9 – Dec 10)
The primary drawback we identified pertains to the out-of-range notification, where Bluetooth disconnection was found to be less reliable in preventing unwarranted alarms. After careful consideration, we opted not to trigger the alarm solely based on Bluetooth disconnectivity, recognizing its limitations in ensuring accurate alerts.
To address this concern and enhance the reliability of the out-of-range notification, several viable solutions were explored. One option involves upgrading to a more advanced Bluetooth chip to improve signal stability. Additionally, integrating a GPS module directly into the bag emerged as a potential solution, allowing for precise distance detection from the user. Another consideration involved implementing an accelerometer to discern the movement of the bag, providing an additional layer of context to the notification system.
Ultimately, a combination of these solutions could be explored to create a robust and comprehensive approach to the out-of-range notification feature. By adopting such enhancements, we aim to deliver a more dependable and effective SecuroBag, ensuring users receive accurate notifications without compromising on the reliability of the alarm system.
Maker Manual
Tools & Supplies
In the creation of our backpack, the tools and supplies used were:
- Arduino & Breadboard
- Resistors
- Wires
- Piezo Buzzer
- Red LED
- RC522 RFID Reader & Tag
- HC05 Bluetooth Transmitter
- Conductive Thread
- Soldering Iron
- Wire Strippers
- Backpack
- Android smartphone & Serial Bluetooth Terminal App
Circuit Layout
Build Section
The backpack consists of 7 main physical components. The zipper sensor, the Alarm, the State LED, the RFID reader, a Bluetooth module, an Arduino microcontroller for logic, and, of course, the backpack itself. Execution of each component is as follows:
Smart Zipper
The smart zipper aims to detect if a bag has been opened. We do this by creating two contact points using conductive thread to detect if a zipper is in a certain position. The contact points act as a switch for the Arduino, closing a circuit with the zipper when the bag is closed.
The Alarm and State LED
The Alarm:
The alarm is composed of a piezo speaker that sits outside of the bag. When ringing, the piezo speaker sounds intermittently, alerting people nearby to the theft taking place. The piezo also serves to provide audio feedback when connecting the Bluetooth module of the bag and when arming the bag.
The State LED:
The State LED is connected to the Arduino and runs to the outside of the backpack using copper wires. We currently leave a small gap in the zipper for the LED and speaker. A more elegant solution would be to create a small hole in the bag for the LED and speaker to be put through and sewn into place, but as we are using one of our own bags for prototyping, we will use the zipper gap workaround to avoid permanent damage to the bag.
RFID Authorization
For authorization, the RFID reader is placed near the top of the bag for ease of access. This allows the user to easily tap to arm and disarm the bag. For added security, the RFID reader is housed inside the bag to prevent any potential thieves from tampering with the reader.
Bluetooth Connectivity
The Bluetooth module allows the user to connect their smartphone to the bag and monitor its whereabouts. This module is connected directly to the Arduino’s breadboard. Similar to the RFID reader, the module is placed within the bag.
Putting it All Together
Connecting the digital components together is the Arduino and breadboard, secured to the bottom of the backpack.
The backpack houses everything needed to secure itself.
Code
Sound.ino
const int piezoPin = 5;
const int tempo = 200;
void Sound_Setup() {
pinMode(piezoPin, OUTPUT);
digitalWrite(piezoPin, HIGH);
}
// Sound that is played with there is an error with arming/disarming
void Sound_Error(){
char notes[]="gbba";
for (int i = 0; i < 6; i++) {
_playNote(notes[i], 800);
delay(tempo);
}
}
// Sound that is played when the bag is successfully disarmed
void Sound_DisarmSucc(){
char notes[]="fga";
for (int i = 0; i < 6; i++) {
_playNote(notes[i], 800);
delay(tempo);
}
}
// Sound that is played when the bag is successfully armed
void Sound_ArmingSucc(){
char notes[]="edc";
for (int i = 0; i < 6; i++) {
_playNote(notes[i], 800);
delay(tempo);
}
}
// Sound that is played to signify that Bluetooth is connected
void Sound_BTConnected(){
char notes[]="ecd";
for (int i = 0; i < 6; i++) {
_playNote(notes[i], 800);
delay(tempo);
}
}
// Sound that is played to signify that Bluetooth is disconnected
void Sound_BTDisconnected(){
char notes[]="dce";
for (int i = 0; i < 6; i++) {
_playNote(notes[i], 800);
delay(tempo);
}
}
// The alarm sound to signal that the bag's security has been breached
void Sound_Alarm(){
char notes[]="aa";
for (int i = 0; i < 6; i++) {
_playNote(notes[i], 800);
delay(tempo);
}
delay(tempo);
for (int i = 0; i < 6; i++) {
_playNote(notes[i], 800);
delay(tempo);
}
}
// Private helper function to play a note
void _playNote(char note, int duration) {
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C',};
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
// play the tone corresponding to the note name
for (int i = 0; i < 8; i++) {
if (names[i] == note) {
tone(piezoPin, tones[i], duration);
}
}
}
Zipper.ino
const int zipperPin = 4;
const int ledPin = 8;
void Zipper_Setup() {
pinMode(zipperPin, INPUT);
pinMode(ledPin, OUTPUT);
Zipper_SetLEDTo(LOW);
}
bool Zipper_IsClosed() {
// Zipper circuit is open, which means zipper is closed
return digitalRead(zipperPin) == LOW;
}
void Zipper_SetLEDTo(int highOrLow) {
// Write the given value to the LED pin
digitalWrite(ledPin, highOrLow);
}
RFID.ino
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void RFID_Setup() {
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
}
RFIDResult RFID_Check() {
// Look for new cards
if (!mfrc522.PICC_IsNewCardPresent()) {
return NOSCAN;
}
// Select one of the cards
if (!mfrc522.PICC_ReadCardSerial()) {
return NOSCAN;
}
// Get RFID content
String content = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
content.toUpperCase();
//change here the UID of the card/cards that you want to give access
if (content.substring(1) == "A3 E7 00 0D" || content.substring(1) == "04 8E 55 1A 4B 3F 80")
{
// Serial.println("Access granted.");
// Serial.println();
return AUTH;
} else {
return UNAUTH;
}
}
BT.ino
#include <SoftwareSerial.h>
#define BT_RX 2
#define BT_TX 3
const int BT_BAUD_RATE = 9600;
const int BT_STATE_PIN = 6;
// Create Bluetooth Serial Interface using port 2 for receiving data and port 3 for transmitting data
SoftwareSerial btSerial(BT_RX, BT_TX);
// Bluetooth connection state
int connState = 0;
// Begin Bluetooth Serial Interface with a 9600 Baud Rate
void BT_Setup() {
// Start interface at 9600 baud rate
btSerial.begin(BT_BAUD_RATE);
Serial.println("Bluetooth is running");
// Print bluetooth connection state
pinMode(BT_STATE_PIN, INPUT);
}
// Send message to device through bluetooth
void BT_SendMsg(String msg) {
btSerial.println(msg);
}
// Read message from device through bluetooth
String BT_ReadMsg() {
if (btSerial.available()) {
String msg = btSerial.readString();
msg.trim();
return msg;
}
return "";
}
// Check if bluetooth module is connected
bool BT_IsConnected() {
int currState = digitalRead(BT_STATE_PIN);
if (currState != connState) {
connState = currState;
_printConnectState();
}
return connState;
}
// Private helper function to print BT connection state
void _printConnectState() {
if (connState == 1) {
Serial.println("Bluetooth Connected");
} else {
Serial.println("Bluetooth Disconnected");
}
}
Main.ino (uses the functions from all the other sketches)
// SecuroBag State Machine States (refer to diagram)
enum State {
DisarmedBTDisconnected,
DisarmedBTConnected,
ArmedBTConnected,
ArmedBTDisconnected,
Alarm,
};
// Status of RFID module
enum RFIDResult {
AUTH,
UNAUTH,
NOSCAN
};
// Keep track of State Machine's current state
State currState = DisarmedBTDisconnected;
// Track how many unauthorized RFID scans occurred during armed state
int errCount = 0;
// State Machine initilization process
void initStateMachine() {
currState = DisarmedBTDisconnected;
errCount = 0;
}
void setup() {
Serial.begin(9600);
// Setup bluetooth module
BT_Setup();
// Setup RFID module
RFID_Setup();
// Setup Zipper circuit
Zipper_Setup();
// Setup Sound modules
Sound_Setup();
// Initialize state machine
initStateMachine();
// Ready for action!
Serial.println("SecuroBag is ready");
// DEBUG: Print current state
printState();
}
void loop() {
// DEBUG: log state
State prevState = currState;
// Get status of RFID module
RFIDResult scanResult = RFID_Check();
// Execute actions based on the current state of the State Machine
switch (currState) {
case DisarmedBTDisconnected:
// Reset error count
errCount = 0;
// Check if any RFID is being scanned
if (scanResult != NOSCAN) {
Serial.println("Play Arming Error Sound");
Sound_Error();
}
// Check if Bluetooth is connected
else if (BT_IsConnected()) {
currState = DisarmedBTConnected;
Serial.println("Play Bluetooth Connected Sound");
Sound_BTConnected();
// Send connected message to device via BT
BT_SendMsg("Connected to SecuroBag");
}
break;
case DisarmedBTConnected:
// Reset error count
errCount = 0;
// Recheck if RFID is scanned
scanResult = RFID_Check();
// Check if bag is trying to be armed
if (scanResult == UNAUTH || (scanResult == AUTH && !Zipper_IsClosed())) {
if (scanResult == UNAUTH) {
Serial.println("unauth");
} else {
Serial.println("zipper not closed");
}
Serial.println("Play Arming Error Sound");
Sound_Error();
}
// Bag is successfully armed
else if (Zipper_IsClosed() && (scanResult == AUTH || BT_ReadMsg() == "arm")) {
currState = ArmedBTConnected;
Serial.println("Play Armed Sound && Turn On LED");
Sound_ArmingSucc();
Zipper_SetLEDTo(HIGH);
// Send msg to device through BT about state change
BT_SendMsg(stateToString());
}
// Check if Bluetooth disconnected
else if (!BT_IsConnected()) {
currState = DisarmedBTDisconnected;
Serial.println("Play Bluetooth Disconnected Sound");
Sound_BTDisconnected();
}
break;
case ArmedBTConnected:
// Check if bag is trying to be disarmed
if (scanResult == UNAUTH) {
Serial.println("Play Disarming Error Sound");
Sound_Error();
errCount++;
}
// Bag is successfully disarmed
else if (scanResult == AUTH || BT_ReadMsg() == "disarm") {
currState = DisarmedBTConnected;
Serial.println("Play Disarmed Sound");
Sound_DisarmSucc();
Zipper_SetLEDTo(LOW);
// Send msg to device through BT about state change
BT_SendMsg(stateToString());
}
// Check if Bluetooth disconnected
else if (!BT_IsConnected()) {
currState = ArmedBTDisconnected;
Serial.println("Play Bluetooth Disconnected Sound");
Sound_BTDisconnected();
}
// Always check if zipper is not closed or error count == 3
if (!Zipper_IsClosed() || errCount == 3) {
currState = Alarm;
// Send msg to device through BT about state change
BT_SendMsg(stateToString());
}
break;
case ArmedBTDisconnected:
// Check if bag is trying to be disarmed
if (scanResult == UNAUTH) {
Serial.println("Play Disarming Error Sound");
Sound_Error();
errCount++;
}
// Bag is successfully disarmed
else if (scanResult == AUTH) {
Serial.println("Play Disarmed Sound");
Sound_DisarmSucc();
Zipper_SetLEDTo(LOW);
}
// Always check if zipper is not closed or error count == 3
if (!Zipper_IsClosed() || errCount == 3) {
currState = Alarm;
}
break;
case Alarm:
// Make sure sound has on and off intervals to do other checks
Serial.println("Play Alarm Sound");
Sound_Alarm();
// Recheck if RFID is scanned
scanResult = RFID_Check();
// Bag has been successfully disarmed
if (scanResult == AUTH || BT_ReadMsg() == "disarm") {
Zipper_SetLEDTo(LOW);
if (BT_IsConnected()) {
currState = DisarmedBTConnected;
// Send msg to device through BT about state change
BT_SendMsg(stateToString());
} else {
currState = DisarmedBTDisconnected;
}
Sound_DisarmSucc();
delay(500);
}
break;
}
// DEBUG: print state changes
if (prevState != currState) {
Serial.print("State changed to: ");
printState();
}
}
// Helper function to create message to be sent through BT about SecuroBag state
String stateToString() {
switch (currState) {
case DisarmedBTDisconnected:
case DisarmedBTConnected:
return "Status: Disarmed";
case ArmedBTConnected:
case ArmedBTDisconnected:
return "Status: Armed";
case Alarm:
return "Status: Bag has been breached!";
}
}
// DEBUG: Print SecuroBag State Machine states for debugging purposes
void printState() {
switch (currState) {
case DisarmedBTDisconnected:
Serial.println("Disarmed, Bluetooth Disconnected");
break;
case DisarmedBTConnected:
Serial.println("Disarmed, Bluetooth Connected");
break;
case ArmedBTConnected:
Serial.println("Armed, Bluetooth Connected");
break;
case ArmedBTDisconnected:
Serial.println("Armed, Bluetooth Disconnected");
break;
case Alarm:
Serial.println("ALARM");
break;
}
}
You must be logged in to post a comment.