Hello everyone, this is a basic project to send security alert messages to your phone number whenever someone opens your home's locker. The Bolt IoT WiFi Module is the heart of this project. Basically, this project is based upon the basics of Machine Learning algorithm, known as the Z-score Analysis. It is like whenever an anomaly is detected in the readings recorded by the Light Dependent Resistor (LDR) sensor, a quick SMS request is done and an SMS is received on your phone number. A LDR is basically a sensor which records the light intensity value. It sends the value to the Bolt Cloud, and the required output is shown depending upon the program running behind. In this project I have also connected a buzzer to the Bolt WiFi Module to give it a more realistic approach. As soon as an anomaly in the data is detected, an SMS alert would be sent as well as the buzzer would start ringing for a few seconds.
Click here to watch the video.3. HOW TO START?
3.1 Create an account on Bolt Cloud
Go to this page and create an account. Then add your Bolt WiFi module to the Bolt cloud.
3.2 Enable your API Key in the APIs section
Enable and copy your API key and keep it privately in a file.
Also store your device ID safely.
3.3 Create a free trial account on Twilio
Twilio is a third party service used to send SMS. It is a cloud communication platform as a service (PaaS) company. Twilio allows software developers to make and receive text messages using its web service APIs. Go to this page to create a free trial account on Twilio.
3.4 Copy and save the AccountSID and AUTH TOKEN
3.5 You need to have a VPS (Virtual Private Server)
- You can download a virtual machine software such as VMware Workstation or VirtualBox. Then you can download the latest version of Ubuntu Server and then work on it by hosting it on the virtual machine.
- You can purchase a cloud server from any of the cloud service company on the internet and download the Ubuntu OS.
If you have Windows:
You can SSH into your Ubuntu Server using PuTTY using the IP address provided by the cloud service company.
If you have Linux/Mac OS:
Then SSH into your cloud server by just opening your terminal.
- After logging into your cloud server, download the latest Python libraries and the Bolt Python libraries as you will use it for writing your code.
4.1 Connecting the LDR to the Bolt WiFi module
- Connect the LDR in series with a 10k-ohms resistor. Connect one any one leg of the LDR into the A0 pin (analog pin) and the other leg into the voltage pin (3.3V pin).
- Now connect the resistor's any one leg into the A0 pin and the other leg into the GND pin (ground pin).
- Make sure that the legs going into the 3.3V pin and the GND pin of the LDR and the resistor respectively, shall not touch each other. If it does then the circuit will get short circuited.
4.2 Connecting the buzzer to the Bolt WiFi module
- The longer leg of the buzzer is the positive leg and the other is the negative leg.
- Connect the positive leg of the buzzer into GPIO pin 1 and the negative into the GPIO pin 2 using the male to female jumper wires.
NOTE: Here we have connected both the legs of the buzzer into GPIO pins. As the usual way is connecting the negative leg to the ground. So here in the code we will write digitalWrite(1, 'HIGH') and digitalWrite(2, 'LOW'), so that the buzzer rings.
4.3 The complete circuit would look like this:
NOTE:Don't power on the device before you properly connect the whole circuit.5. CONCEPT BEHIND THE CODE
The concept is basically the basics of Machine Learning, it is known as Anomaly Detection. An anomaly is a deviation from the expected value. It is something other than ordinary. Here we have done the anomaly detection using a method known as Z-score analysis. It is basically calculating a boundary for the data, which when crossed it can be called as an anomaly. The boundary is calculated using the previous recorded data points and by using some formulas from the statistics of the data collected.
Here are some formulas which are used in the code to calculate the Z-score:
Here Mn is mean of the data, Zn is the Z-score and Tn is boundary/threshold values. You can tune the multiplication factor to get the desired results. Frame size is the no. of data points to be collected in the beginning.6. OUTPUT
When the sensor gets the light intensity data, it sends it to the analog pin, and it is further sent to the Bolt Cloud. Our code accesses the data from the Bolt Cloud using the cloud API and converts the data into JSON data communication format.
Then the data is passed into the algorithm and the required output is shown. When the locker is opened, a sudden increase in light intensity occurs which is observed by the sensor and thus an SMS request to Twilio is done. I have also used a buzzer which will start ringing when the locker is opened or when an anomaly is detected.
Here are the outputs: