The Light Monitoring System is such a useful IoT tool which helps to calculate the actual intensity of light in room and convert it in a manner so that the intensity of LED can be set according to the required intensity. And the fun thing about this is that it also text's a message to the user and tells them that weather it is too dark in room or there isn't and light required, it sets the LED intensity automatically as per requirement.
So without wasting any time let's move to the further steps to create such a device for ourselves.
Step 1 :
The most first thing is connection. So I"ll tell you step by step how to do connections.
1. Connect the 3V to one of the leg of LM35 sensor with the use of jumper wires.
2. Connect the A0 to another leg of LM35 sensor with the use of jumper wires.
3. Connect the GND to the negative terminal (shorter leg) of the LED.
4. Connect the positive terminal (longer leg) of the LED to the one leg of 10K resistor and the another leg of 10k resistor to the Pin no. 1 of the Bolt IoT board.
5. Connect a 220K resistor in between negative terminal of LED and A0 PIN.
STEP 2 :
Go to google.com and search for twilio and create a free account this will help to get the text message about the condition of LED and intensity inside the room.
STEP 3 :
Now moving to the coding part of the System.
1. Create a python file (.py).
2. Name that python file "conf.py"
3. Copy the below code and save it.
4. Change "SID", "AUTH_TOKEN", etc. according to your own.
SID = 'Your_Twilio_SID' AUTH_TOKEN = 'You_Can_Find_in_your_twilio_control_panel' FROM_NUMBER = 'YOUR_TWILIO_NUMBER' TO_NUMBER = '+91YOUR_PHONE_NUMBER' API_KEY = 'BOLT_API_KEY' DEVICE_ID = 'BOLT_DEVICE_ID' FRAME_SIZE = 5 MUL_FACTOR = 3
4. Now create an another python (.py) file and name it "light_monitoring_system"
5. Copy the below code and save it.
import conf from boltiot import Sms, Bolt import json, time, requests mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID) """creating a function to set the value of LED automatically(0-255) """ sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER) """creating a function to send a message when LDR crosses threshold""" def set_intensity(pin, value): mybolt.analogWrite(pin, value) """create a function to calculate Required LED Intensity corresponding to the LDR sensor value subtract from 255? - if LDR value=1024(sufficient light)-led will be off(0) if LDR value=0(no light)-led will be on(255) intermediate value of LDR will corresponds to a specific LED intensity value(0-255) """ def converter(sensor_value): led_intensity= 255-(sensor_value*255/1024) return led_intensity while True: print ("Reading Sensor Value") response = mybolt.analogRead('A0') # Read the LDR Sensor Value from A0 Pin data = json.loads(response) # Convert value in Json format print("Sensor value is: " + str(data['value'])) # Print the value try: sensor_value = int(data['value']) print("Calculating required Light Intensity for LED") led_value_float=converter(sensor_value) # convert ldr sensor value in required led_value= int(led_value_float) # led value in float and then typecast print(led_value) # float into int type set_intensity('1',led_value) # this will make LED to glow # with calculated intensity value sensor_value = int(data['value']) if sensor_value > 1024 : print("Making request to Twilio to send a SMS") response = sms.send_sms("It's too much bright in here. Switching the light's off. The Current Intensity of light is " +str(sensor_value)) print("Response received from Twilio is: " + str(response)) print("Status of SMS at Twilio is :" + str(response.status)) elif sensor_value < 255 : print("Making request to Twilio to send a SMS") response = sms.send_sms("It's too much dark in here. Switching the light's on. The Current Intensity of light is " +str(sensor_value)) print("Response received from Twilio is: " +str(response)) print("Status of SMS at Twilio is :" + str(response.status)) # in case of any error encountered except Exception as e: print ("Error occured: Below are the details") print (e) time.sleep(3)
STEP 4 :
Connect the Bolt IoT device using USB and power it on.
BOOM MAGIC !!
Here is a image of the message from Twilio.