I do appreciate one's own privacy and their own personal things too!
Use Bolt IoT kit and 3rd party services (mailgun and twilio) to maintain your own privacy by building smart Iot project based on light intensity value. when someone turn ON/OFF your room's light, Bolt module take light intensity value through LDR sensor and when anomaly (sudden increment or decrement in light intensity) detect It will immediately send an SMS, email and will produce sound of buzzer with the help of Z-score analysis. Make sure that your Bolt WiFi Module is connected to Bolt Cloud and the green LED onBolt Moduleis Glowing.
If the entire room is dark then It will record the values of light intensity and when someone will turn ON the lights then we will notify via SMS, Email alert that "Someone turned on the lights" along with that It'll also produce sound of buzzer.
2. EXPLANATIONIn this section we will learn how to build the entire project.
2.1 Hardware ConnectionConnect one terminal of LDR sensor to 3.3v and othe one to 'A0'.
Connect one terminal of buzzer to pin '0' and other one to GND.
Connect one terminal of Resistor(10kohm) to 'A0' and othe one to GND.
Create a configurations file for this project, using the command sudo nano conf.py
write these lines in conf.py editor and after writing all the values save the file by Ctrl+X.
- To get your API key and Device Id:
Connect your Bolt Cloud with Bolt device then the following screen will appear:
It shows the device is online after connecting bolt device with Bolt cloud.
You can get your API KEY here. You can set the FRAME_SIZE to 10 and the MUL_FACTOR to 3 for now. Once done, you can save the configurations file by pressing 'CTRL+x'
2.3 Setting up software- Setup Twilio Account
Twilio is a third-party SMS functionality provider. It is a cloud communications platform as a service (PaaS) company. Twilio allows software developers to programmatically make and receive phone calls and also send and receive text messages using its web service APIs.
Create an account on Twilio:
Step 1: Open https://www.twilio.com/ in browser.
Step 2: Click on Get a Free API Key
button to sign up.
Step 3: Fill all the necessary details that are asking.
Step 4: Go to dashboard and get your data.
That's it. We have successfully created the account on Twilio. Now, we are all set to use Twilio service with Bolt Python library to create our own SMS Alert system.
- Similarly, You can create your mailgun account to get email alert.
Step 1: Open https://www.mailgun.com/ in browser.
Step 2: Click on Sign Up
button.
Step 3: Fill all the necessary details in SIGN UP form. Make sure you are unchecking the payment option. Below is the screenshot of filled sign up form.
Step 4: You will get a verification mail having a link. Click on that link to verify your mail.
Step 5: To verify they will ask for phone number. Choose India as an option in the dropdown and then enter your phone number.
Step 6: After verification, scroll down to Sandbox Domain
section. Click on Add Recipient
button.
Step 7: Click on Invite New Recipient
button.
Step 8: Enter the Receipient Email ID. In this case enter your Email ID.
Step 9: After adding Email ID a new sandbox will be generated. Click on the ID of the newly generated sandbox. Refer below image for the same.
Step 10: The new screen will have all the necessary credentials that you want for sending an email. Copy all this credentials and save in the notepad.
For detection of sudden change in light intensity i.e.anomaly we use Z-score analysis. Z-score analysis is a machine learning algorithm to detect anomaly. For small amount of data we can simply use graphical analysis to detect an anomaly but In case of huge amount of data it is difficult to plot graph and detect anomaly that's why we need to use some machine algorithm.
In the above formula the input is represented as 'Vi', 'r' denotes the frame size and 'C' is the multiplication factor. First of all we calculate the mean (Mn) of the input values (for every new input, the mean is calculated again). The variation of each input value (from the mean) is given as (Vi - Mn)^2. Now Z-score (Zn) is calculated by the formula that is presented above. The bounds are represented as 'Tn' and the upper bound is calculated as (Vi + Zn) and the lower bound is calculated as (Vi - Zn).
The frame size and multiplication factor are determined using trial-and-error method.
After writing the code, run code by using sudo python3 'filename'.py. The code will initially print the following lines. After about 100 seconds (10 seconds delay with a frame size of 10), the system will start printing the light intensity values as per the following image.
As we can see that after sudden increment in light intensity value we'll get an SMS and Email alert also buzzer will start producing sound because of anomaly detection.
You can go anywhere and get update of your room but make sure that your Bolt WiFi Module is connected to Bolt Cloud and the green LED on Bolt Module is Glowing So, that you'll get SMS/Email alert.
2.5 Code explanantionThe code that I have written below is the main code to detect anomaly:
After connecting bolt device to bolt cloud, when we run our code then It will first take sensor value from 'A0' pin. Initially it starts print the value of light intensity and wait till 10 values because Z-score analysis can be implement after having sufficient amount of data after that It will compute the z-score, upper and lower threshold bounds for normal and anomalous readings. The next part is checking if the sensor value is lying in the range of normal values, If it is not in the range then, send the SMS, Email and produce sound of buzzer as an alert. It will wait for 10 seconds as we have mentioned time.sleep(10) and continue from starting.
3. RECEIVING EMAIL AND SMS ALERTEmail Alert
SMS Alert
Comments