Akshansh Malik
Published © GPL3+

Control Devices Using Google Assistant

Learn to control an LED's intensity using LDR and controlling buzzer with Google Assistant and IFTTT.

IntermediateFull instructions provided3 hours2,376
Control Devices Using Google Assistant

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
LED (generic)
LED (generic)
×1
Buzzer
Buzzer
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×1

Software apps and online services

Maker service
IFTTT Maker service
Assistant SDK
Google Assistant SDK

Story

Read more

Schematics

Circuit Diagram

Code

Complete Code

Python
"""impoting libraries
    conf to import api_key and device_id written in conf.py
    Bolt for connecting to our bolt module using api_key and device_id
"""
import conf
from boltiot import Bolt
import json, time 


mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)

def intensity(pin, value):
	mybolt.analogWrite(pin, value)

def convert(sensor_value):
	led_intensity= 255-(sensor_value*255/1024)
	return led_intensity


while True: 
    print ("Reading Sensor Value")
    response_ldr = mybolt.analogRead('A0')
    data = json.loads(response)    
    print("Sensor value is: " + str(data['value'])) 
    try: 
        sensor_value = int(data['value'])
        print("Calculating Light Intensity for LED")
        led_valued=convert(sensor_value)
        led_value= int(led_valued) 
        print(led_value)                         
        intensity('1',led_value)             
        
    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(15)

Credits

Akshansh Malik

Akshansh Malik

1 project • 3 followers

Comments