Hello everyone, welcome and in this tutorial, I will show you how to integrate Alexa and Google Home to Control LEDs. Follow the below steps to help you get it done.
Hardware Requirements:
- Breadboard
- NodeMCU-Esp8266.
- 3 x LEDs (Red, Green, Yellow).
- USB micro-B cable.
- Jumper wires.
- PC/Laptop
Software Requirements:
- Sinric Pro
- Alexa
- Google Home
Connection/Circuit Diagram:
- Connect Esp8266 to the breadboard as shown above.
- Connect 3 LEDs, Green, Red and Yellow to the breadboard.
- Connect the GND pin from Esp8266 to the GND rail of the breadboard.
- Connect the pins D1(GPIO 5), D2(GPIO 4), and D3(GPIO 0) to Green, Yellow, and Red respectively.
- Connect the negative terminals of the LEDs to the GND rail from the breadboard.
NOTE: Make sure there is a close and firm connection when connecting the negative terminals of the LEDs to the GND rail from the breadboard.
1.Open your browser and type sinric pro or else click on the link Sinric Pro - Connect Amazon Alexa, Google Home with esp8266, esp32, raspberry pi, RP2040
2.The below will be displayed on the screen, click on sign up to create an account.
4. After that then you can log in to your account. Click on Devices>Add device.
Give names for the devices, Green LED, Red LED and Yellow LED. Write anything of your choice in the description, leave everything that comes next as default, and continue clicking next until the device is created. Then you can check it in the dashboard. Repeating the same for Red and Yellow LEDs. The maximum number of devices you can create for a user using free service is three.
5. Next, click the Devices to show you the list of devices you created.
6. The next thing, open Arduino IDE, click on the below options in the screenshot. File>Examples>Sinric Pro>Relay>Muti-relay_advance.
Copy the below code:
#define ENABLE_DEBUG
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <SinricPro.h>
#include <SinricProSwitch.h>
#define RELAYPIN_1 D1
#define RELAYPIN_2 D2
#define RELAYPIN_3 D3
/*****************
* Configuration *
*****************/
struct RelayInfo {
String deviceId;
String name;
int pin;
};
std::vector<RelayInfo> relays = {
{"XXXXXXXXXXXXXXXXXXX", "Relay 1", RELAYPIN_1},
{"XXXXXXXXXXXXXXXXXXX", "Relay 2", RELAYPIN_2},
{"XXXXXXXXXXXXXXXXXXX", "Relay 3", RELAYPIN_3}};
#define WIFI_SSID "XXXXXX"
#define WIFI_PASS "XXXXXX"
// Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
#define APP_KEY "XXXXXXXXXXXXXXXX"
// Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
#define APP_SECRET "XXXXXXXXXXXXXXXXXXXXXX"
#define BAUD_RATE 9600 // Change baudrate to your need
bool onPowerState(const String &deviceId, bool &state) {
for (auto &relay : relays) { // for each relay configuration
if (deviceId == relay.deviceId) { // check if deviceId matches
Serial.printf("Device %s turned %s\r\n", relay.name.c_str(), state ? "on" : "off"); // print relay name and state to serial
digitalWrite(relay.pin, state); // set state to digital pin / gpio
return true; // return with success true
}
}
return false; // if no relay configuration was found, return false
}
void setupRelayPins() {
for (auto &relay : relays) { // for each relay configuration
pinMode(relay.pin, OUTPUT); // set pinMode to OUTPUT
}
}
void setupWiFi() {
Serial.printf("\r\n[Wifi]: Connecting");
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
Serial.printf(".");
delay(250);
}
Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str());
}
void setupSinricPro() {
for (auto &relay : relays) { // for each relay configuration
SinricProSwitch &mySwitch = SinricPro[relay.deviceId]; // create a new device with deviceId from relay configuration
mySwitch.onPowerState(onPowerState); // attach onPowerState callback to the new device
}
SinricPro.onConnected([]() { Serial.printf("Connected to SinricPro\r\n"); });
SinricPro.onDisconnected([]() { Serial.printf("Disconnected from SinricPro\r\n"); });
SinricPro.begin(APP_KEY, APP_SECRET);
}
void setup() {
Serial.begin(BAUD_RATE);
setupRelayPins();
setupWiFi();
setupSinricPro();
}
void loop() {
SinricPro.handle();
}
std::vector<RelayInfo> relays = {
{"XXXXXXXXXXXXXXXXXXXXXXXX", "Relay 1", RELAYPIN_1},
{"XXXXXXXXXXXXXXXXXXXXXXXX", "Relay 2", RELAYPIN_2},
{"XXXXXXXXXXXXXXXXXXXXXXXX", "Relay 3", RELAYPIN_3}};
After that type your WIFI SSD and Password.
#define WIFI_SSID "XXXXXXX"
#define WIFI_PASS "XXXXXXX"
Next, go to credentials and copy APP KEY and APP SECRET.
#define APP_KEY "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
#define APP_SECRET "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
9. Go back to Arduino IDE and connect the USB from esp8266 to your PC then click>Tools>Board>Esp8266>NodeMCU 1.0(Esp-12E Module). In case you don't find the board install by clicking board manager, then type esp8266 in the search box.
If the connection between Esp8266 and Wi-Fi is successful, a connection is established with Sinric Pro and it will display 3 devices online on the dashboard as shown below.
of Androids, it's already installed.
11. After that then open the Alexa app and link it with Sinric Pro. Click>More>Skills and Games.
12. Click on the search icon, type Sinric Pro. And it will be shown as the first one. Simply click on it and link it with Alexa.
13. You can link Google Home with Sinric Pro. Open Google Home >Create a new home and give it a name for example My Smart Home Assistant. Add a Device>Works with Google, type Sinric Pro in the search bar and then link it with Google. You can either use Alexa or Google Assistant to command.
Finding: A unique feature of Google Assistant over Alexa, you can command all the LEDs to be turned on/off at once.
Check the video for more:
0 Comments