ANTI-THEFT SYSTEM
Home security is undeniably one of the most important things for homeowners. It deters crimes and prevents property damage or theft. Although, home security systems nowadays could get very expensive (granted they are very advanced and integrated). And so, a cost-effective alternative was designed. This device is able to detect breaches, sound an alarm, and send this information to the user's smartphone via text message and push notifications. Moreover, this device could be primed wirelessly from virtually anywhere, as long as there is a network connection. While currently available services could cost up to $200 with an additional monthly subscription fee, this device could realistically be sold for a tenth of that price with no monthly fees.

Block Diagram
This diagram shows a schematic form of the arrangement of the circuit components and their communication pathways. The main elements are the ultrasonic sensor, LED, and loudspeaker.
They are connected to the ESP32 microcontroller, where it will read data, publish data, and connect to a designated wifi provider, allowing it to communicate with Adafruit, an MQTT broker.
ELECTRONICS

CIRCUIT DESIGN AND COMPONENTS
Microcontroller: ESP32
Ultrasonic Sensor: HC-SR04
Operational Amplifier
Loudspeaker
LED
100 Ohm Resistor
10k Ohm Resistor 3x
2.2k Ohm Resistor
Jumper Wires
HOW IT WORKS
The main component of this circuit design is the HC-SR04 ultrasonic sensor. It is programmed to detect distances at a given rate. If it detects a breach, the loudspeaker will play a tune that of a siren, indefinitely. The user will then receive a notification on their smartphone about this breach.
The LED is another supporting component that will act as an indicator of whether the device is armed or disarmed. If it blinks on and off, the device is armed, and if it doesn't, the device is disarmed.

I/O
To ensure communication between the device and the internet, a booting program was flashed onto the ESP32 which will connect it to a predetermined Wi-fi source as soon as it is powered on, specified within the code.
It will allow the ESP32 to set up an MQTT connection to Adafruit through the internet, and this is already configured within the program

INPUT
The HC-SR04 ultrasonic sensor can detect distances from 2 cm to up to 4 meters. For this system, the sensor is programmed to detect distances every 0.2 seconds and relays it to the ESP32. If that reading is less than 50 cm, the ESP32 will send a message to the Adafruit IO feed through the internet and print an entry on its feed.
OUTPUT
Using IFTTT and connecting it to Adafruit, outputs can be easily implemented by creating 2 applets. The first is an applet to receive text messages and push notifications if it reads a new entry on the Adafruit feed, and warns the user of a breach.
The second applet, which is technically not a part of I/O but is integral, is designed to allow remote arming and disarming of the device.
Simply said, IFTTT is what allows this device to communicate with smartphones!

COMMUNICATION

An MQTT protocol using Adafruit IO's MQTT broker is used for communication and it is implemented within the code. A feed was set up on a new Adafruit server to where the ESP32 will send messages to. This feed is also used when arming and disarming the device.
To the left is a snapshot of a section in our code where the Adafruit connection from the ESP32 is set up.
COMPUTATION
This is the backbone of the whole system. This code is based on the skeleton codes from previous lab sessions and they have been combined, modified, and used appropriately. Additionally, appropriate import codes are included since the HC-SR04 ultrasonic sensor and PWM for the LED are used.
This program is heavily based on the use of timers. The 1st timer (Timer=0) is used for the PWM, the 2nd timer (Timer=1) is for the loudspeaker and the LED, the 3rd timer (Timer=2) is to check the distance from the ultrasonic every 0.2 seconds, and the 4th timer (Timer=3) is for checking messages from MQTT every second.

IMPORT CODES
TIMERS
