Published © Apache-2.0

Control ESP by Google Assistant

Very easy way to send commands to your ESP from Google Assistant.

BeginnerProtip30 minutes8,664
Control ESP by Google Assistant

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
LED (generic)
LED (generic)
×1
Resistor 100 ohm
Resistor 100 ohm
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

RemoteMe.org cloud
RemoteMe.org cloud

Story

Read more

Schematics

Schematic

Code

Arduino code

Arduino
Dont forget to modify token and your wifi
#define WIFI_NAME "YOUR WIFI"
#define WIFI_PASSWORD "WIFI passwrod"
#define DEVICE_ID 1
#define DEVICE_NAME "ESP"
#define TOKEN "Your token"


#include <RemoteMe.h>
#include <RemoteMeSocketConnector.h>
#include <ESP8266WiFi.h>
#include <Servo.h>

uint8_t LEDpin = D5;
Servo myservo;  // create servo object to control a servo
RemoteMe& remoteMe = RemoteMe::getInstance(TOKEN, DEVICE_ID);

//*************** CODE FOR CONFORTABLE VARIABLE SET *********************

inline void setRELAY_01(boolean b) {remoteMe.getVariables()->setBoolean("RELAY_01", b); }
inline void setServo(int32_t i) {remoteMe.getVariables()->setInteger("servo", i); }

//*************** IMPLEMENT FUNCTIONS BELOW *********************


void onRELAY_01Change(boolean b) {
    digitalWrite(LEDpin,b?HIGH:LOW);
}

void onServoChange(int32_t i) {
     myservo.write(i);
}




void setup() {
    Serial.begin(9600);

    WiFi.begin(WIFI_NAME, WIFI_PASSWORD);

    while (WiFi.status() != WL_CONNECTED) {
        delay(100);
    }

    remoteMe.getVariables()->observeBoolean("RELAY_01" ,onRELAY_01Change);
    remoteMe.getVariables()->observeInteger("servo" ,onServoChange);

    remoteMe.setConnector(new RemoteMeSocketConnector());

    remoteMe.sendRegisterDeviceMessage(DEVICE_NAME);

    myservo.attach(D1);
    pinMode(LEDpin, OUTPUT);
    digitalWrite(LEDpin, LOW);
}


void loop() {
    remoteMe.loop();
}

Credits

Comments