Introduction :
This is an IoT-enabled Led light with Multiple color-changing features. which can be controlled by google assistant. RGB Led is used as an IoT light of this project. Which is controlled by a Raspberry Pi on the edge. Adafruit.io is working as a cloud between IFTTT application which is further connected to Google Assistant for controlling.
Hardware Description :
RGB Led: It is a light-emitting diode having three basic colors like Red, Green, Blue. These three colors in different combinations can be used to create any color.
Raspberry Pi: Raspberry Pi is a microprocessor with a running Raspbian operating system. It has 40 pins out of which 26 are General purpose pins. Python can be used to program the circuits. It can connect to Adafruit.io easily using MQTT or HTTP protocols.
Adafruit.IO:
It is an IoT cloud platform that is very easy to integrate with hardware and with online applications. It has so many features to control the edged device from a remote location and very effective for small and large-scale IoT devices.
IFTTT :
If This Then That is a web-based service that allows users to create chains of conditional statements triggered by changes that occur within other web services such as Gmail, Facebook, Telegram, Instagram, or google assistant. IFTTT is simple to use. You download the mobile app to create a free account and you’re up and running with automation in minutes.
Creating different colors using RGB Led:
A total of 7 colors can be creating using different combinations of Red, Green and Blue.
- Red : Give logic ‘1’ to Red pin of RGB and logic ‘0’ to others.
- Green : Give logic ‘1’ to Green pin of RGB and logic ‘0’ to others.
- Blue : Give logic ‘1’ to Blue pin of RGB and logic ‘0’ to others.
- Yellow : Give logic ‘1’ to Red and Green pin of RGB and logic ‘0’ to others.
- Purple : Give logic ‘1’ to Red and Blue pin of RGB and logic ‘0’ to others.
- Cyan : Give logic ‘1’ to Green and Blue pin of RGB and logic ‘0’ to others.
- White : Give logic ‘1; to all the pins of RGB.
Working of IoT light :
Preparing Adafruit.IO
- Open Adafruit.IO and sign in to your Account or register a new account.
- Create a new Dashboard and name it whatever you want.
- Create a new Block from the ‘+’ icon on the top right and add a new text block onto the dashboard.
- Attach this block to a feed or group (create one if not already created) on to which you want to send data from IFTTT and subscribe to that feed from Raspberry Pi.
Connecting Google assistant to Adafruit Io using IFTTT :
- Install the IFTTT application from Playstore and sign in.
- Go to create one.
- Open the ‘if’ block and search for google assistant.
- Type the phrase you using which, you want to trigger Adafruit from Google assistant.
- Type additional phrases to trigger and response you want from google assistant.
- Open ‘then’ block and search for Adafruit.IO
- Select send data to Adafruit.
- Choose the feed you want to send data to.
- write the data you want to send.
- Create a different block for every color.
Blog on Connecting IFTTT with Raspberry Pi
Python Code :
import sys, time
from Adafruit_IO import *
import RPi.GPIO as GPIO
redPin = 2
greenPin = 3
bluePin = 4
def blink(pin):
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.HIGH)
def turnOff(pin):
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)
def default():
redPin = 2
greenPin = 3
bluePin = 4
GPIO.setmode(GPIO.BCM)
GPIO.setup(redPin,GPIO.OUT)
GPIO.setup(greenPin,GPIO.OUT)
GPIO.setup(bluePin,GPIO.OUT)
GPIO.output(redPin, GPIO.LOW)
GPIO.output(greenPin, GPIO.LOW)
GPIO.output(bluePin, GPIO.LOW)
def redOn():
default()
blink(redPin)
def greenOn():
default()
blink(greenPin)
def blueOn():
default()
blink(bluePin)
def yellowOn():
default()
blink(redPin)
blink(greenPin)
def cyanOn():
default()
blink(greenPin)
blink(bluePin)
def magentaOn():
default()
blink(redPin)
blink(bluePin)
def whiteOn():
default()
blink(redPin)
blink(greenPin)
blink(bluePin)
def redOff():
turnOff(redPin)
def greenOff():
turnOff(greenPin)
def blueOff():
turnOff(bluePin)
def yellowOff():
turnOff(redPin)
turnOff(greenPin)
def cyanOff():
turnOff(greenPin)
turnOff(bluePin)
def magentaOff():
turnOff(redPin)
turnOff(bluePin)
def whiteOff():
turnOff(redPin)
turnOff(greenPin)
turnOff(bluePin)
while True:
aio = Client("Brownboy333","aio_aHCq59YIUcI10mefiqlEcbZtMrJk")
cmd = aio.receive("txt").value
print(cmd)
if (cmd == "red on"):
redOn()
print("red On")
elif cmd == "red off":
redOff()
elif cmd == "green on":
greenOn()
print("green ON")
elif cmd == "green off":
greenOff()
elif cmd == "blue on":
blueOn()
elif cmd == "blue off":
blueOff()
elif cmd == "yellow on":
yellowOn()
elif cmd == "yellow off":
yellowOff()
elif cmd == "cyan on":
cyanOn()
elif cmd == "cyan off":
cyanOff()
elif cmd == "magenta on":
magentaOn()
elif cmd == "magenta off":
magentaOff()
elif cmd == "white on":
whiteOn()
elif cmd == "white off":
whiteOff()
else:
print("Not a valid command.")