Google Assistant Controlled Raspberry Pi GPIO With IFTTT and Particle.io

Control your device using Raspberry Pi and Google Assistant.

Introduction

Instead controlling your device through app clicked, now you can try with your voice. This tutorial require Android smartphone with Google Assistant (sorry iPhone and Siri). To program Raspberry Pi, you need to use Particle Web IDE. Please refer to the previous tutorial (link provided below) to get started with Particle IoT platform.

Video

This video will show you how to control GPIO on Raspberry Pi through Google Assistant.

Sample Program

This is sample program for Raspberry Pi using Particle Web IDE.

/*
Program with Particle Web IDE
Board (tested with):
– Raspberry Pi Zero WH
– Raspberry Pi 3 Model A+
*/
const int led1 = D1; // D1 is refer to GPIO17
const int led8 = D2; // D2 is refer to GPIO27
const int buzzer = D8;
bool led1State = LOW; // a virtual boolean variable
bool led8State = LOW; // a virtual boolean variable
bool led8PrevState = LOW;
long prevMillis = 0;
int interval = 500;
void setup()
{
pinMode(led1, OUTPUT); // led1 pin is set as output
pinMode(led8, OUTPUT); // led8 pin is set as output
pinMode(buzzer, OUTPUT);
digitalWrite(led8, LOW);
// Subscribe to events published by IFTTT using Particle.subscribe
Particle.subscribe("Light_On_Event", lightOnHandler); // Turning on function declaration
Particle.subscribe("Light_Off_Event", lightOffHandler); // Turning off function declaration
beep(2, 70);
}
void loop()
{
if (millis() – prevMillis > interval) {
led1State = !led1State;
digitalWrite(led1, led1State);
prevMillis = millis();
}
if (led8State != led8PrevState) {
led8PrevState = led8State;
digitalWrite(led8, led8State);
beep(1, 70);
}
}
// Our events are called when IFTTT applets are triggered
void lightOffHandler(const char *event, const char *data)
{
led8State = LOW;
}
void lightOnHandler(const char *event, const char *data)
{
led8State = HIGH;
}
void beep(int times, int delayMs)
{
do {
digitalWrite(buzzer, HIGH);
delay(delayMs);
digitalWrite(buzzer, LOW);
delay(delayMs);
} while (–times);
}

Thank You

References:

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

2 thoughts on “Google Assistant Controlled Raspberry Pi GPIO With IFTTT and Particle.io”

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

Getting Started with Robotic Operating System (ROS) and JetRacer AI Kit
Barrier Gate with micro:bit and MakeCode
Play MP3 File on Maker Pi Pico Using CircuitPython
Remote Jetson Nano using SSH with Visual Studio Code
3.3V Serial LCD with Raspberry Pi Pico via SPI or I2C
Tutorials of Cytron Technologies Scroll to Top