This is a project that will completely automate your lighting needs. This system uses a Light Dependent Resistor (LDR) whose resistance changes according to the light intensity of the surroundings. The data from the LDR is collected and sent to the Bolt Cloud by the Bolt Wifi Module. The data is then analysed and the light is turned on if the value received is below the preset threshold. It will also send an SMS to the registered phone number if such an incident occurs.
The system will automatically turn off the light when the light intensity increases above the threshold and an SMS regarding the same will also be sent.
The bonus feature of this project is that this system is that it can detect any anomaly in the light intensity of the surroundings. The system is designed in such a way that if the light intensity in the surroundings increases or decreases suddenly, the system will detect it as an anomaly and send an SMS regarding the same.
The connections for the LDR are given below :
- Connect one leg of the LDR to the 3V3 pin of the Bolt Wifi module
- Connect the other leg of the LDR to the A0 pin of the Bolt Wifi module
- Connect one leg of the 10k resistor to the GND pin of the Bolt Wifi module
- Connect the other leg of the 10k resistor to the A0 pin of the Bolt Wifi module
In the above image, the White, Grey and Purple connectors are connected to A0, 3V3 and GND pins respectively
The connections for the LED are given below :
- Connect the longer pin (anode) of the LED to the digital pin 1 of the Bolt Wifi module
- Connect the shorter pin (cathode) of the LED to the digital pin 2 of the Bolt Wifi module
STEP 1 : Setting up VMware Workstation with Ubuntu server
In order to setup VMware, click on the link below and download the required version:
Also download the ISO file for the Ubuntu server:
After downloading these files, set up the system with the help of the following video:
STEP 2 : Getting the API key and Device ID of the Bolt Wifi module
After creating an account on the Bolt Cloud, you can access your API key and Device ID from the API tab and the Devices tab respectively of your Bolt Cloud dashboard. Copy both the API key and Device ID of your Bolt device and store it somewhere securely.
STEP 3 : Setting up the Bolt Python library
In order to interact with our Bolt Wifi module, we have to install the Bolt python library in our Ubuntu server. For this, first log in to your Ubuntu server and type in the following code :
sudo apt-get -y update
This will update all the packages in your Ubuntu server.
sudo apt install python3-pip
Install pip3 using the above command,
sudo pip3 install boltiot
The above code will install the Bolt python library on your Ubuntu server.
STEP 4 : Creating an account on Twilio
In order to send SMS when the light intensity crosses the threshold, we will be using Twilio. So we have to create a free account on Twilio for the same.
Given below is the link for creating an account on Twilio:
Refer the following video for any clarification on how to create your Twilio account:Before Coding
Before writing the main code, we have to save the credentials such as the API key, Device ID, Twilio SSID, etc. in a separate python file. This file is then included in the main code. Given below is an example of the same :
Algorithm For Coding
SSID = 'XXXXXXXXXXXXXXXX' #Replace the X with the SSID found on your Twilio dashboard
AUTH_TOKEN = 'XXXXXXXXXXXXXX' #Replace X with auth token from your Twilio dashboard
TO_NUMBER = 'XXXXXXXXXX' #Replace X with the registered phone number
FROM_NUMBER = 'XXXXXXXXX' #Replace X with your Twilio phone number
DEVICE_ID = 'BOLTXXXXXX' #Replace this with your Bolt Device ID
API_KEY = 'XXXXXXXXXXXXXX' #Replace X with the API key of your Bolt Device
- Fetch the latest value of the LDR sensor
- Compute the Z-score for anomaly detection
- Check whether the sensor value is beyond the upper and lower bound calculated using the Z-score. If yes, send an SMS saying that an anomaly was detected.
- If it was not an anomaly, check whether the sensor value is below the threshold. If yes, turn on the LED and send an SMS regarding the same.
- Otherwise check whether the sensor value is above the threshold. If yes, turn off the LED and send an SMS regarding the same.
- Wait for 10 seconds and repeat all the steps.
This technique consists of subtracting the mean of the column from each value in a column, and then dividing the result by the standard deviation of the column.The result of standardization is that the features will be re-scaled so that they’ll have the properties of a standard normal distribution. In summary, the Z-Score (also called the standard score) represents the number of standard deviations with which the value of an observation point or data differ than the mean value of what is observed. The formula to calculate the Z-Score is given below:
where Mn represents the Mean and r represents the frame size
where Zn represents the Z-Score, C is the multiplication factor and r is the frame size