Skip to content

About

Conversational AI chatbot on ESP32 using Google Gemini API

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

ESP32 Gemini AI Chatbot

Platform Language API License

A conversational AI chatbot running on ESP32, powered by the Google Gemini API.
Communicates entirely through the Arduino Serial Monitor — no display or touchscreen required.
Maintains conversation history across 10 exchanges before auto-resetting to preserve memory.


How It Works

Serial Monitor → ESP32 → Gemini API → Response → Serial Monitor
  1. ESP32 connects to WiFi (credentials entered at runtime — not hardcoded)
  2. User types a question in Serial Monitor
  3. ESP32 sends the question + conversation history to Gemini API over HTTPS
  4. Gemini response is parsed, cleaned, and printed back
  5. Token usage is displayed after every reply

Hardware

Component Details
ESP32 Board Any variant (DevKit, NodeMCU)
USB Cable For power and code upload
PC / Laptop Arduino IDE + Serial Monitor

Dependencies

Library Source
WiFi Built-in (ESP32 core)
HTTPClient Built-in (ESP32 core)
WiFiClientSecure Built-in (ESP32 core)
ArduinoJson Arduino Library Manager

Install ArduinoJson by Benoit Blanchon via Library Manager (Sketch → Include Library → Manage Libraries)


API Key Setup

  1. Visit Google AI Studio
  2. Generate a Gemini API key
  3. Open the .ino file and paste your key:
const char* key = "YOUR_API_KEY_HERE";

⚠️ Never commit your API key to GitHub.
The key field is intentionally left blank ("") in this repository.
See Key Safety below.


Configuration

All tunable parameters are at the top of the .ino file:

Parameter Default Description
key "" Your Gemini API key
maxOutputTokens 2000 Maximum length of Gemini's reply
temperature 0.7 Response creativity (0.0 strict → 1.0 creative)

WiFi credentials (SSID + password) are entered at runtime via Serial Monitor — they are never stored in the code.


Serial Monitor Settings

Getting these wrong is the most common reason input is never received.

Setting Value
Baud Rate 115200
Line Ending Newline

Key Safety

  • The key field in both versions is left as "" — safe to clone and share
  • Never paste your key and push to GitHub — it will be exposed publicly
  • If you accidentally commit a key: revoke it immediately at Google AI Studio and generate a new one
  • For future projects consider using a secrets.h file — already covered in .gitignore here

V1 vs V2 (Key Differences)

Feature v1 v2
Comment Style Basic (// ---) Box-style (//==== headers)
User Label Your Question Asked: You : Your Question Asked: You :
Reply Label Your Answer: Gemini : Your Answer: Gemini :
Token Display Plain text Clean structured output
Formatting Raw API output Markdown cleaned
Markdown Handling ❌ No cleaning ✅ Removes ** * # `
Newline Handling ❌ Not processed ✅ Converts \n to real line breaks
History Reset Message Simple text Clear “History is RESET” message
Memory Reset After 10 Qs After 10 Qs (better handling)

→ API testing reference: POSTMAN_GUIDE.md

Known Limitations

  • SSL certificate verification is disabled (setInsecure()) — acceptable for embedded hobby projects
  • Conversation history is stored as a raw String — resets every 10 exchanges to prevent memory overflow
  • No persistent storage — history is lost on reset or power cycle

License

MIT License — free to use, modify, and distribute with attribution.

About

Conversational AI chatbot on ESP32 using Google Gemini API

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages