亿迅智能制造网
工业4.0先进制造技术信息网站!
首页 | 制造技术 | 制造设备 | 工业物联网 | 工业材料 | 设备保养维修 | 工业编程 |
home  MfgRobots >> 亿迅智能制造网 >  >> Manufacturing Technology >> 制造工艺

Google Assistant 声控 Arduino:IFTTT + Webhook + ESP8266 完整教程

硬件准备

模块型号/数量
主控Arduino UNO R3
Wi-Fi 模块ESP-01 (ESP8266, 1MB Flash)
电源USB 供电或 5V 1A 适配器
外设示例LED、继电器模块、PWM 调光、舵机等

软件与云服务

整体架构

语音指令 → Google Assistant → IFTTT Applet (Webhook) → HTTP Server (存 JSON) → ESP8266 轮询 GET → 串口发给 Arduino → 执行动作

步骤 1:创建 IFTTT Applet

  1. IFTTT 网站 Create → If This → Google Assistant → "Say a phrase with a number ingredient"
  2. 短语示例:Set PWM of pin 9 to #、PWM 9 to #(# 代表数字参数)
  3. 回复语:The PWM is updated to $($ 为参数回显)
  4. Then That → Webhooks → Make a web request
    • URL:https://your-server/api/Home/GetAllApp
    • Method:POST
    • Content-Type:application/json
    • Body:{"Number": "{{NumberField}}"}

步骤 2:服务端存储 JSON(示例为 ASP.NET Core)

[HttpPost]
public IActionResult GetAllApp([FromBody] JObject data) {
    // 解析 data["Number"] 存入数据库
    // 返回 200 OK
}

也可用 PHP、Node.js、Python Flask 等任意后端,仅需提供 GET /api/Home/GetAllApp 返回最新指令 JSON。

步骤 3:ESP8266 代码(轮询服务器 → 串口透传)

#include 
#include 
#include 

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASS";
const char* server = "https://your-server/api/Home/GetAllApp";

void setup() {
  Serial.begin(115200);  // 与 Arduino 通讯
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) delay(500);
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    http.begin(server);
    int code = http.GET();
    if (code > 0) {
      String payload = http.getString();  // 如 {"Number":255}
      Serial.println(payload);            // 透传给 Arduino
    }
    http.end();
  }
  delay(3000);  // 3 秒轮询一次
}

步骤 4:Arduino 代码(解析串口 JSON → 执行 PWM/IO)

#include 

String input;
bool complete = false;

void setup() {
  Serial.begin(9600);
  pinMode(9, OUTPUT);  // PWM 输出示例
  input.reserve(200);
}

void loop() {
  if (complete) {
    DynamicJsonDocument doc(256);
    deserializeJson(doc, input);
    int pin = doc["Pin"] | 9;       // 默认 9
    int val = doc["Number"] | 0;    // 0~255
    analogWrite(pin, val);
    input = ""; complete = false;
  }
}

void serialEvent() {
  while (Serial.available()) {
    char c = Serial.read();
    input += c;
    if (c == '\n') complete = true;
  }
}

扩展玩法

接线图

Google Assistant 声控 Arduino:IFTTT + Webhook + ESP8266 完整教程


🗣️ 核心价值:零成本接入 Google 语音生态,无需公网 IP、无需复杂网络编程,适合智能家居原型、教学演示、无障碍交互项目。

制造工艺

  1. 集成二维码、RFID与体温验证的门禁控制系统
  2. 基于 Arduino、1Sheeld 与红外控制的万能安卓遥控器
  3. 智能存钱罐:Arduino Nano 控制硬币识别器实现余额显示
  4. Arduino + HC-05 蓝牙控制 LED:MIT App Inventor 手机 App 开发全攻略
  5. Arduino Nano + 摇杆控制双步进电机:Visuino 图形化教程
  6. Arduino + MPU6050 姿态控制舵机:SG90 与 MG996R 精准跟随实战
  7. 语音控制家电:Google Assistant + 蓝牙 + Arduino UNO
  8. u-blox LEA-6H GPS 模块:Arduino 与 Python 集成指南
  9. 在 Arduino Due 上实现语音识别与语音合成 - BitVoicer Server 方案
  10. ThimbleKrox:基于 Arduino Micro 与 MPU-6050 的指戴式鼠标控制器
  11. 基于 Arduino 与 Google Sheets 的实时 RFID 考勤系统
  12. 智能水泄漏检测与电磁阀控制系统