Electronic components for an ESP32-S3 AI chatbot project laid out on a table

How to Make an AI Chatbot with ESP32-S3: Voice Assistant Guide (2026)

Build a talking AI chatbot with an ESP32-S3, INMP441 microphone and MAX98357A amplifier: wiring diagram, free XiaoZhi firmware, Arduino code and parts price in Pakistan.

Quick answer: You can build a talking AI chatbot with an ESP32-S3 N16R8 board, an INMP441 microphone, a MAX98357A amplifier and a small speaker. Wire them on a breadboard, flash the free open-source XiaoZhi firmware (no coding needed), connect it to your Wi-Fi and start talking. The whole build takes about an hour and the parts cost roughly Rs 4,500–5,000 in Pakistan.

This guide walks you through two ways to do it:

  • Option A – Voice AI assistant (beginner friendly): a pocket “smart speaker” that listens, thinks with a large language model and talks back. No programming.
  • Option B – Your own text chatbot in Arduino IDE: about 80 lines of code that send your questions to an AI API and print the answers. Great for learning how it all works.

Contents

  1. Why the ESP32-S3 is the right chip for an AI chatbot
  2. Parts list and price in Pakistan
  3. Step 1: Wiring diagram
  4. Step 2: Flash the XiaoZhi firmware
  5. Step 3: Connect to Wi-Fi and activate
  6. Step 4: Talk to it and customise it
  7. Option B: Arduino IDE text chatbot (full code)
  8. Troubleshooting
  9. FAQ

Why the ESP32-S3 is the right chip for an AI chatbot

The AI model itself does not run on the ESP32-S3. A large language model needs gigabytes of memory, so the chip does the “ears and mouth” work and a server does the thinking. The ESP32-S3 is very good at that job:

  • Dual-core 240 MHz with AI (vector) instructions, so it can run an offline wake word with Espressif’s ESP-SR library.
  • 8 MB PSRAM on the N16R8 version for audio buffers, plus 16 MB flash for the firmware, fonts and emoji.
  • Two I²S audio interfaces: one for the digital microphone, one for the amplifier.
  • Wi-Fi and Bluetooth LE built in, to stream your voice to the AI server and play the reply.

An original ESP32 or an ESP32-C3 can run simpler versions, but the S3 with PSRAM gives the smoothest result. If you are still choosing a board, read our ESP32 vs ESP32-S3 vs ESP32-P4 comparison.

Smart speaker voice assistant – the kind of device you can build with an ESP32-S3
The goal: a smart-speaker style assistant you built yourself. Photo: Joas van der Eerden / Unsplash

How it works

  1. You press the button (or say the wake word) and speak.
  2. The INMP441 microphone sends digital audio to the ESP32-S3 over I²S.
  3. The ESP32-S3 compresses it (Opus) and streams it over Wi-Fi to the AI server.
  4. The server turns speech into text, asks a large language model (such as Qwen or DeepSeek) for an answer and turns the answer back into speech.
  5. The ESP32-S3 plays the reply through the MAX98357A amplifier and shows the text and an emoji on the OLED.

The firmware we use is XiaoZhi ESP32, a popular open-source project (MIT licence) with ready-made builds for many boards, including a breadboard version for exactly the parts below.

Parts list and price in Pakistan

Prices below update automatically from our store. All parts are tested before dispatch and available with Cash on Delivery across Pakistan.

PartWhat it doesPrice
ESP32-S3 DevKitC-1 N16R8The brain: Wi-Fi, audio, displayRs 1,499
INMP441 I2S microphoneDigital mic that hears your voiceRs 650
MAX98357A I2S amplifier3 W class-D amp that drives the speakerRs 650
0.96″ OLED 128×64 (SSD1306) or 0.91″ OLED 128×32Shows status, the chat text and emoji (optional)Rs 430
MB102 830-point breadboardSolder-free buildingRs 260
Tactile push buttonsVolume up and volume down (optional)Rs 535
Small speaker, 3 W, 4–8 ΩPlays the AI’s voice–
Male-to-male jumper wires + USB-C data cableConnections and power/flashing–
Total: roughly Rs 4,500–5,000 for everything.

Want it ready-made? The ESP32-S3 N16R8 1.9-inch LCD AI chatbot board (Rs 3,800) and the mini ESP32-S3 XiaoZhi AI robot board have the mic, amplifier and screen already on board, so you can skip the wiring step.

Step 1: Wiring diagram

This pinout matches the XiaoZhi bread-compact-wifi firmware, so you don’t need to change any code. Keep the ESP32-S3 unplugged from USB while you wire.

ESP32-S3 AI chatbot wiring diagram: INMP441 microphone, MAX98357A amplifier, SSD1306 OLED and buttons on ESP32-S3 DevKitC-1 N16R8
ESP32-S3 AI chatbot wiring (tap to enlarge).
Module pinESP32-S3 pinNotes
INMP441 microphone
VDD3V33.3 V only
GNDGND
L/RGNDSelects the left channel
WSGPIO 4Word select
SCKGPIO 5Bit clock
SDGPIO 6Audio data out
MAX98357A amplifier
VIN5V (or 3V3)5 V is louder
GNDGND
DINGPIO 7Audio data in
BCLKGPIO 15Bit clock
LRCGPIO 16Left/right clock
SD, GAINnot connectedDefault: on, 9 dB gain
+ / −SpeakerNever connect the speaker to GND
OLED (SSD1306, I²C)
SDAGPIO 41
SCL (SCK)GPIO 42
VCC / GND3V3 / GND
Buttons (other leg to GND)
Talk / wakeGPIO 0The on-board BOOT button already does this
Volume +GPIO 40Long press = maximum volume
Volume −GPIO 39Long press = mute
Microcontroller board wired to modules on a breadboard with jumper wires
Keep wires short and tidy on the breadboard; long loose I²S wires pick up noise. Photo: Vishnu Mohanan / Unsplash

Wiring tips:

  • The DevKitC-1 is wide. Place it across the middle gap of the breadboard so each side has free holes, or use two breadboards side by side.
  • Most INMP441 and MAX98357A modules come with loose header pins. Solder them first; pressing loose pins into a breadboard gives crackling or silent audio.
  • On a 4-leg tactile button, the two legs on the same side are already connected. Put the button across the breadboard’s centre gap so it actually switches.
  • Do not use GPIO 35, 36 or 37 on N16R8 boards: they are connected to the PSRAM.

Step 2: Flash the XiaoZhi firmware (no coding)

  1. Open the XiaoZhi releases page and download the latest bread-compact-wifi build. If there are versions for different OLED sizes, pick the one that matches yours (128×64 for 0.96″, 128×32 for 0.91″). Unzip it to get merged-binary.bin.
  2. Plug the ESP32-S3 into your PC with a data USB-C cable, using the port marked UART (or COM). Many cheap cables only charge, so try another cable if no port appears.
  3. Flash it using one of these methods:

Windows (graphical tool): download Espressif’s Flash Download Tool. Choose ChipType ESP32-S3, WorkMode Develop, LoadMode UART. Add merged-binary.bin at address 0x0, tick it, select your COM port and click START.

Any computer (command line): install Python, then run:

pip install esptool
esptool --chip esp32s3 write-flash 0x0 merged-binary.bin

(Older esptool versions use esptool.py --chip esp32s3 write_flash 0x0 merged-binary.bin.) If the tool can’t connect, hold the BOOT button, tap RST, release BOOT and try again.

Step 3: Connect to Wi-Fi and activate

  1. Press RST. The board starts in Wi-Fi setup mode and creates a hotspot named Xiaozhi-XXXXXX.
  2. Connect your phone to that hotspot. A setup page opens; if it doesn’t, open 192.168.4.1 in your browser.
  3. Choose your home Wi-Fi and enter the password. It must be a 2.4 GHz network; the ESP32-S3 can’t join 5 GHz. On dual-band PTCL, Nayatel or StormFiber routers, use the 2.4 GHz name, or turn on your phone hotspot as 2.4 GHz.
  4. Once online, the chatbot speaks and shows a 6-digit code.
  5. On a computer, sign up at xiaozhi.me, open the console, create an agent, click Add device and enter the 6-digit code. Your device now appears in the device list.

Step 4: Talk to it and customise it

Press the BOOT button (or say the wake word) and ask anything: “Explain Ohm’s law simply”, “Tell me a joke”, “What should I build with an ultrasonic sensor?”. The default wake word is Chinese (“Nǐ hǎo Xiǎozhì”), so the button is easiest at first.

In the xiaozhi.me console, open Configure role to change:

  • Name and personality: for example “You are Chacha, a patient electronics teacher. Answer in short, simple sentences.”
  • Language and voice: English works well. You can ask it to reply in Urdu or Roman Urdu; quality depends on the model and voice you pick, so test a few.
  • AI model: choose from the models offered in the console.

Save and restart the device to apply the changes. Advanced users can also run their own server (Python, Java and Go versions are linked from the project page) and use MCP tools to let the chatbot control LEDs, relays or servos.

Option B: Build a text AI chatbot in Arduino IDE

Want to understand what happens under the hood? This sketch connects the ESP32-S3 to Wi-Fi, sends what you type in the Serial Monitor to an AI chat API and prints the reply. It also remembers the last few messages, so you can have a real conversation. It works with any OpenAI-compatible API (OpenAI, Groq, OpenRouter and others).

Setup:

  1. In Arduino IDE, install the esp32 by Espressif Systems board package (Boards Manager) and the ArduinoJson library by Benoit Blanchon, version 7 (Library Manager).
  2. Select board ESP32S3 Dev Module, then set Flash Size 16MB and PSRAM OPI PSRAM. If you plug into the USB port marked USB (not UART), also set USB CDC On Boot: Enabled.
  3. Get an API key from your AI provider, and set a spending limit on it.
  4. Fill in your Wi-Fi name, password, API URL, key and a model name from your provider’s model list, then upload.
  5. Open Serial Monitor at 115200 baud with line ending set to New Line, type a question and press Enter.
// ESP32-S3 AI text chatbot – robochacha.pk
// Type a question in the Serial Monitor; the reply comes from an AI chat API.
// Needs: "esp32" board package by Espressif + ArduinoJson v7 library.

#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>

// ---- Fill these in ----
const char* WIFI_SSID = "YOUR_WIFI_NAME";      // 2.4 GHz network
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const char* API_URL   = "https://api.openai.com/v1/chat/completions";  // any OpenAI-compatible endpoint
const char* API_KEY   = "YOUR_API_KEY";
const char* MODEL     = "YOUR_MODEL_NAME";     // copy a model name from your provider's model list
// -----------------------

JsonDocument history;   // conversation memory
JsonArray messages;

void addMessage(const char* role, const String& text) {
  JsonObject m = messages.add<JsonObject>();
  m["role"] = role;
  m["content"] = text;
  while (messages.size() > 9) {   // keep the system prompt + last 8 messages
    messages.remove(1);
  }
}

String askAI(const String& question) {
  addMessage("user", question);

  JsonDocument request;
  request["model"] = MODEL;
  request["max_tokens"] = 300;
  request["messages"] = messages;
  String body;
  serializeJson(request, body);

  WiFiClientSecure client;
  client.setInsecure();            // testing only – see the note below the code
  HTTPClient http;
  http.setTimeout(30000);
  http.begin(client, API_URL);
  http.addHeader("Content-Type", "application/json");
  http.addHeader("Authorization", String("Bearer ") + API_KEY);

  int status = http.POST(body);
  String payload = http.getString();
  http.end();

  if (status != 200) {
    messages.remove(messages.size() - 1);   // forget the failed question
    return "Error " + String(status) + ": " + payload.substring(0, 200);
  }

  JsonDocument filter;
  filter["choices"][0]["message"]["content"] = true;
  JsonDocument response;
  DeserializationError err = deserializeJson(response, payload, DeserializationOption::Filter(filter));
  if (err) {
    messages.remove(messages.size() - 1);
    return String("Could not read reply: ") + err.c_str();
  }

  String reply = response["choices"][0]["message"]["content"].as<String>();
  reply.trim();
  addMessage("assistant", reply);
  return reply;
}

void setup() {
  Serial.begin(115200);
  delay(1000);

  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("Connected, IP: " + WiFi.localIP().toString());

  messages = history["messages"].to<JsonArray>();
  addMessage("system", "You are Chacha, a friendly electronics helper. Answer in 2-3 short sentences.");

  Serial.println("Type a question and press Enter.");
}

void loop() {
  if (!Serial.available()) return;

  String question = Serial.readStringUntil('\n');
  question.trim();
  if (question.length() == 0) return;

  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Wi-Fi lost, reconnecting...");
    WiFi.reconnect();
    return;
  }

  Serial.println("You: " + question);
  Serial.println("Thinking...");
  Serial.println("AI:  " + askAI(question));
  Serial.println();
}

Important: an API key stored in firmware can be read by anyone who has the board. For a personal project that’s fine with a spending limit. For a product, send requests through your own small server and keep the key there. setInsecure() also skips certificate checks; for anything beyond testing, load your API provider’s root certificate with client.setCACert().

Next steps: show the reply on an OLED or 1.54″ TFT, add a button that sends preset questions, or combine it with the INMP441 and a speech-to-text API to make your own voice version.

Troubleshooting

ProblemFix
No COM port appearsUse a data cable, try the other USB-C port, and install the CH343/CP210x USB driver if Windows asks.
Flashing fails or stopsHold BOOT, tap RST, release BOOT, then flash again. Lower the baud rate to 460800.
Hotspot appears but Wi-Fi won’t connectUse a 2.4 GHz network and check the password. After three failed tries the board goes back to setup mode.
It hears nothingCheck WS/SCK/SD on GPIO 4/5/6 and that L/R is tied to GND. Re-seat or solder the mic header.
No sound, or very quietCheck DIN/BCLK/LRC on GPIO 7/15/16, power the amp from 5V, and connect the speaker only to + and −.
Crackling or noiseShorten the I²S wires, power from a good 5V 2A USB adapter or power bank, and keep the speaker away from the mic.
OLED stays blankCheck SDA = GPIO 41 and SCL = GPIO 42, and flash the build that matches your OLED size.
Board keeps restarting while talkingThe USB port can’t supply enough current. Use a 5V 2A adapter or power bank.

Make it portable

The simplest way is a small USB power bank: it survives load-shedding and you can carry the chatbot around. For a built-in battery, use a 3.7V LiPo cell with a 5V boost and charging module feeding the board’s 5V pin. Never connect a raw 3.7 V battery straight to the 5V pin without a proper module, and always use a protected cell.

Project ideas

  • Study buddy for physics and maths questions at your desk.
  • Voice-controlled lights using a relay module and MCP tools.
  • Talking robot: put it in a robot car chassis and give it a personality.
  • Final-year or school project: an “AI receptionist” that answers visitors’ questions about your department.

FAQ

Can the ESP32-S3 run ChatGPT or an AI model offline?

No. Large language models are far too big for a microcontroller. The ESP32-S3 records and plays audio, detects the wake word offline, and sends your voice or text to an AI server over Wi-Fi. That’s why it needs an internet connection.

Is XiaoZhi free to use?

The firmware is open source under the MIT licence. Personal users can register on the official xiaozhi.me server and use a basic AI model free of charge. You can also host your own server and connect it to any AI provider.

Can I use a normal ESP32 or ESP32-C3 instead?

XiaoZhi supports several Espressif chips, but the ESP32-S3 with 8 MB PSRAM (N16R8) gives the best audio, wake-word and display performance. For the Arduino text chatbot in Option B, any ESP32 board with Wi-Fi works.

Does it understand Urdu?

The language models behind it can read and write Urdu, and you can ask the assistant to answer in Urdu or Roman Urdu. Speech recognition and voices are strongest in English and Chinese, so test with your own voice before relying on Urdu.

How much does an ESP32-S3 AI chatbot cost in Pakistan?

About Rs 4,500–5,000 for the breadboard version in this guide, or Rs 3,800 for the ready-made ESP32-S3 1.9-inch LCD AI chatbot board.


Ready to build? Get the ESP32-S3 N16R8, INMP441 and MAX98357A from Robochacha.pk with Cash on Delivery anywhere in Pakistan, or visit our Hall Road, Lahore shop. Stuck on a step? Message us on WhatsApp and we’ll help. Browse more ESP32 boards.

Robochacha.pk · Hall Road, Lahore

Need parts for this project?

ESP32, Arduino, Raspberry Pi, sensors and tools in stock, delivered across Pakistan with Cash on Delivery.

Leave a Reply

Your email address will not be published. Required fields are marked *