A project that brings the power of Google's Gemini AI to your ESP8266 microcontroller. Ask questions through the serial monitor and get AI-generated responses directly on your device!
MicroGemini leverages the ESP8266 WiFi capabilities to connect to Google's Gemini API, allowing you to interact with a powerful AI model using minimal hardware. This project demonstrates how even resource-constrained devices can harness the power of cloud-based AI services.
- NodeMCU ESP8266 board
- USB cable for power and communication
- Computer with serial monitor capability
- PlatformIO (or Arduino IDE with proper ESP8266 support)
- Libraries:
- ESP8266WiFi
- ESP8266HTTPClient
- WiFiClientSecure
- ArduinoJson (v7.4.1 or newer)
- Visit the Google AI Studio
- Create or sign in to your Google account
- Create an API key from the "Get API Key" option
Create a credentials.h file in the include directory with the following content:
#ifndef CREDENTIALS_H
#define CREDENTIALS_H
// WiFi credentials
#define WIFI_SSID "your_wifi_ssid"
#define WIFI_PASSWORD "your_wifi_password"
// Google Gemini API key
#define API_KEY "your_gemini_api_key"
#endifReplace:
your_wifi_ssidwith your WiFi network nameyour_wifi_passwordwith your WiFi passwordyour_gemini_api_keywith the API key you obtained from Google AI Studio
- Open the project in PlatformIO
- Build the project
- Upload to your NodeMCU board
- Open the serial monitor (set to 115200 baud)
- Type your question in the serial monitor and press Enter
- Wait for the Gemini API to process your question
- View the AI's response in the serial monitor
- The ESP8266 connects to your local WiFi network
- When you enter a question in the serial monitor, the device:
- Formats your question into a JSON payload
- Sends a secure HTTPS request to the Gemini API
- Receives and parses the JSON response
- Displays the AI-generated answer
ESP8266 has limited RAM, which can cause issues when dealing with large JSON responses from the API.
Solution: Used ArduinoJson's dynamic memory allocation and efficient parsing to handle responses without overflowing the available memory.
The ESP8266 has limited HTTPS capabilities, making secure connections challenging.
Solution: Implemented a workaround using client.setInsecure() to establish connections to the API endpoint.
Parsing complex JSON structures with nested objects and arrays required careful handling.
Solution: Leveraged the ArduinoJson library to elegantly navigate and extract the required information from the response.
- Minimal Hardware Requirements: Achieves AI interaction with just an ESP8266 board
- Real-time Responses: Get answers to your questions in seconds
- Energy Efficient: Low power consumption compared to running a full computer
- Expandable: Can be integrated into other IoT projects
- Educational: Demonstrates IoT, API integration, and AI concepts in a single project
- Add support for multi-turn conversations
- Implement a web interface for interaction
- Add voice input/output capabilities
- Optimize for battery-powered operation
This project is open source and available under the MIT License.
Created with ❤️ by Charan


