Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!

Control Hardware Using Generative Voice AI

Low-Code | Control hardware through natural conversation with a generative voice AI and the XIAO ESP32S3.

BeginnerFull instructions provided1 hour479
Control Hardware Using Generative Voice AI

Things used in this project

Story

Read more

Schematics

Wiring Diagram – XIAO ESP32S3 with Grove Shield and Buzzer Module

This schematic shows how to connect a Grove-compatible buzzer (U3) to the XIAO ESP32S3 (U1) using the Grove Shield (U2). The buzzer is connected to digital pin D1 (GPIO2) via a Grove cable. This setup enables control of the buzzer through Firebase commands triggered by natural language inputs from a conversational agent, as explained in the project.

Code

Firebase-Controlled Hardware via AI Agent on XIAO ESP32S3

C/C++
This code connects the XIAO ESP32S3 to Wi-Fi and Firebase Realtime Database, allowing it to receive commands from a generative voice AI agent. You can use it to control any digital hardware (like a buzzer, LED, or relay) via natural conversation with the AI. The voice agent writes a value to Firebase, which the ESP32 reads and acts upon.
#include <WiFi.h>
#include <Firebase_ESP_Client.h>

/* 1. Define the WiFi credentials */
#define WIFI_SSID "YOUR WIFI_SSID."
#define WIFI_PASSWORD "YOUR PASSWORD"

/* 2. Define the API Key */
#define API_KEY "YOUR API KEY"

/* 3. Define the RTDB URL */
#define DATABASE_URL "YOUR DATABASE_URL" 

/* 4. Define the user Email and password that alreadey registerd or added in your project */
#define USER_EMAIL "EMAIL"
#define USER_PASSWORD "PASSWORD_EMAIL"

// Define Firebase Data object
FirebaseData fbdo;

FirebaseAuth auth;
FirebaseConfig config;

unsigned long sendDataPrevMillis = 0;

const int BuzzerPin = 1;

void setup()
{
  pinMode(BuzzerPin, OUTPUT);
  digitalWrite(BuzzerPin, LOW);

  Serial.begin(115200);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(300);
  }
  Serial.println();
  Serial.print("Connected with IP: ");
  Serial.println(WiFi.localIP());
  Serial.println();

  /* Assign the api key (required) */
  config.api_key = API_KEY;

  /* Assign the user sign in credentials */
  auth.user.email = USER_EMAIL;
  auth.user.password = USER_PASSWORD;

  /* Assign the RTDB URL (required) */
  config.database_url = DATABASE_URL;

  // Comment or pass false value when WiFi reconnection will control by your code or third party library e.g. WiFiManager
  Firebase.reconnectNetwork(true);

  // Since v4.4.x, BearSSL engine was used, the SSL buffer need to be set.
  // Large data transmission may require larger RX buffer, otherwise connection issue or data read time out can be occurred.
  fbdo.setBSSLBufferSize(4096 /* Rx buffer size in bytes from 512 - 16384 */, 1024 /* Tx buffer size in bytes from 512 - 16384 */);

  // Limit the size of response payload to be collected in FirebaseData
  fbdo.setResponseSize(2048);

  Firebase.begin(&config, &auth);

  Firebase.setDoubleDigits(5);

  config.timeout.serverResponse = 10 * 1000;
}

void loop()
{
  // Firebase.ready() should be called repeatedly to handle authentication tasks.
  if (Firebase.ready() && (millis() - sendDataPrevMillis > 1000 || sendDataPrevMillis == 0))
  {
    sendDataPrevMillis = millis();

  int buzzerIdState;
   if(Firebase.RTDB.getInt(&fbdo, "/buzzer/id/state", &buzzerIdState)){
    digitalWrite(BuzzerPin, BuzzerIdState);
   }else{
    Serial.println(fbdo.errorReason().c_str());
   }
  }
}

Credits

Gabriel Alejandro Giraldo Santiago
15 projects • 88 followers
Seeed Ranger, AI and Computer Vision expert for key industries. Mentor and speaker on AI, startups, and no-code. Maker enthusiast.
Contact
Gabotrix For Makers
1 project • 1 follower
Gabotrix for Makers es un programa diseñado para empoderar a creadores con herramientas de Visión Artificial y prototipado avanzado.
Contact

Comments

Please log in or sign up to comment.