Akash Auti
Published

Controlling Lights using LDR Sensor and BOLT wifi module

This project can be used in a place where you need to control the lights.

IntermediateFull instructions provided2 hours748
Controlling Lights using LDR Sensor and BOLT wifi module

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×1
LED (generic)
LED (generic)
×1

Story

Read more

Schematics

Connection on the bread board

Remember the color of wire connected on the bolt module .
1) Connect the blue wire to 3.3v of the bolt module and to ldr(to the small leg of the ldr)
2) Connect the red wire to A0 and other leg of the LDR
3) Connect the ground by a brown wire and then to the resistor on the bread board. As in the picture shown below.
4) Now connect the green wire to "1"on the bolt module and connect leds by using the 330ohm resistor .
5) The purple wire is just the jumper wire which i have used to as a ground connected wire the ground of the bolt

AND THAT'S IT YOUR PROJECT IS READY

EMAIL

This is the email you receive from MAILGUN when the light intensity in the room crosses your max or min value

Circuit connection

Connections on the bolt module

Just remember the colors of the wires connected and connect as per that color.

Code

MAIN CODE

Python
#write this in email_conf.py file
MAILGUN_API_KEY = 'This is the private API key which you can find on your Mailgun Dashboard' 
SANDBOX_URL= 'You can find this on your Mailgun Dashboard' 
SENDER_EMAIL = 'This would be test@your SANDBOX_URL'
RECIPIENT_EMAIL = 'Enter your Email ID Here'
API_KEY = 'This is your Bolt Cloud account API key'
DEVICE_ID = 'This is the ID of your Bolt device'

#this is your main code 
import email_conf
from boltiot import Email, Bolt
import json, time

minimum_limit = 500
maximum_limit = 1000  


mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID)
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)


while True: 
    print ("Reading sensor value...")
    response = mybolt.analogRead('A0') 
    data = json.loads(response) 
    print("Sensor value is: " + str(data['value']))
    try: 
        sensor_value = int(data['value']) 
        if sensor_value > maximum_limit :
            print("Making request to MAILGUN to send an EMIAL..")
            response = mailer.send_emial("Alert ", "Lights are ON..")
            response = mybolt.digitalWrite('1','LOW')
            response_text = json.loads(response.text)
            print("Response received from MAILUGun is: " + str(response_text['message']))
        elif sensor_value < minimum_value :
            print("Making request to MAILGUN to send an EMAIL...")
            response = mailer.send_email("Alert","The lights are OFF")
            response = mybolt.digitalWrite('1','HIGH')
            response_text = json.loads(response.text)
            print("Response received from MAILUGun is: " + str(response_text['message']))
    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(10)

Credits

Akash Auti

Akash Auti

2 projects • 0 followers

Comments