Google Assistant Controlled Raspberry Pi GPIO With IFTTT and Adafruit IO

"Hey Google! Turn on the relay" using Raspberry Pi.


We have shared a tutorial of Google Assistant and Raspberry Pi last year using IFTTT and Particle IO. But Particle IO no longer supports the Raspberry Pi, so the previous tutorial is obsolete. For this tutorial, we will try to update using IFTTT and Adafruit IO platforms.


This video shows how to control relay using Raspberry Pi and Adafruit IO.

This video shows how to link between Google Assistant and Adafruit IO using IFTTT.

Hardware Preparation

This is the list of items used in the video.

Sample Program

This is python3 sample program to control relay module connected to Raspberry Pi using Adafruit IO. Please install following libraries:

sudo pip3 install adafruit-blinka
sudo pip3 install adafruit-io

# References:
# –
# –
# Hardware
# – Raspberry Pi 4 Model B
# [2GB]
# [4GB]
# [8GB]
# – Grove Base Kit for Raspberry Pi
# Install
# – sudo pip3 install adafruit-blinka
# – sudo pip3 install adafruit-io
# Update:
# 28 Feb 2021
# Import standard python modules.
import sys
# Import blinka python modules.
import board
import digitalio
# This example uses the MQTTClient instead of the REST client
from Adafruit_IO import MQTTClient
# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!
# Set to your Adafruit IO username.
# (go to to find your username)
# Set to the ID of the feed to subscribe to for updates.
FEED_ID = 'digital'
relay = digitalio.DigitalInOut(board.D5)
relay.direction = digitalio.Direction.OUTPUT
# Define callback functions which will be called when certain events happen.
def connected(client):
"""Connected function will be called when the client is connected to
Adafruit IO.This is a good place to subscribe to feed changes. The client
parameter passed to this function is the Adafruit IO MQTT client so you
can make calls against it easily.
# Subscribe to changes on a feed named Counter.
print('Subscribing to Feed {0}'.format(FEED_ID))
print('Waiting for feed data…')
def disconnected(client):
"""Disconnected function will be called when the client disconnects."""
def message(client, feed_id, payload):
"""Message function will be called when a subscribed feed has a new value.
The feed_id parameter identifies the feed, and the payload parameter has
the new value.
print('Feed {0} received new value: {1}'.format(feed_id, payload))
if payload == "OFF":
print("Turn off relay!")
relay.value = False
elif payload == "ON":
print("Turn on relay!")
relay.value = True
# Create an MQTT client instance.
# Setup the callback functions defined above.
client.on_connect = connected
client.on_disconnect = disconnected
client.on_message = message
# Connect to the Adafruit IO server.
# The first option is to run a thread in the background so you can continue
# doing things in your program.

Thank You


Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

Is it possible to program Maker UNO with Python?
Camera and DSI Driver on the Latest Raspberry Pi Bullseye OS
Remote Control ZOOM:BIT using Grove 8266 WiFi and Blynk
Icon Case with Heatsinks & Fan Stressberry Test
Low Profile Aluminum Case Stressberry Test
Tutorials of Cytron Technologies Scroll to Top