An AI-driven IoT healthcare solution that bridges the gap between medication adherence and remote clinical supervision through real-time monitoring, intelligent reminders, and caregiver connectivity.
- Overview
- Features
- System Architecture
- Tech Stack
- Installation
- Usage
- Project Structure
- API Endpoints
- Team
- Future Enhancements
Medication non-adherence affects nearly 50% of chronic disease patients globally, leading to treatment failures and preventable hospitalizations. The Smart Medicine Box addresses this critical healthcare challenge by combining:
- IoT Hardware: ESP32-based device with push buttons, LCD display, and buzzer
- Cloud Infrastructure: Firebase Realtime Database for secure data synchronization
- AI Analytics: Grok-powered intelligent log analysis and conversational insights
- Web Portal: Next.js caregiver dashboard for remote monitoring and communication
- โ 100% data synchronization accuracy
- โ 100% successful reminder delivery (4-second latency)
- โ 7 seconds average AI response time
- โ 99% system reliability in experimental testing
- ๐ Automated Medication Reminders: Visual (LCD) + audio (buzzer) alerts at scheduled times
- โ Medicine Intake Confirmation: One-button confirmation with timestamp logging
- ๐ Emergency Alert System: Instant emergency notification to caregivers
- ๐ฌ Real-time Messaging: Receive messages from caregivers on the device screen
- ๐ Event Logging: Automatic cloud logging of all interactions
- ๐ฑ Multi-Device Dashboard: Monitor multiple patients from a single interface
- ๐ Visual Analytics: Interactive charts showing adherence trends and patterns
- โฐ Remote Reminder Scheduling: Configure medication schedules with custom repeat cycles
- ๐ฌ Communication: Send messages directly to patient devices
- ๐ค AI Assistant: Automated log summaries and conversational query interface
- ๐ Secure Authentication: Google OAuth with whitelisted access control
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CLOUD LAYER โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Firebase Realtime Database โ โ
โ โ โข /devices โข /events โข /messages โ โ
โ โ โข /reminders โข /allowedDoctors โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โฒ โฒ
โ โ
โโโโโโโโโโดโโโโโโโโโ โโโโโโโโโโดโโโโโโโโโโโ
โ ESP32 DEVICE โ โ WEB APPLICATION โ
โโโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโโโค
โ โข 16ร2 LCD โ โ โข Next.js 15.5.2 โ
โ โข Push Buttons โ โ โข Material-UI v6 โ
โ โข Piezo Buzzer โ โ โข Recharts โ
โ โข Wi-Fi Module โ โ โข AI Integration โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
- Microcontroller: ESP32 DevKit v1
- Display: 16ร2 LCD with I2C backpack
- Audio: Piezo buzzer (2-4 kHz)
- IDE: Arduino IDE 2.3.6
- Libraries:
- Firebase ESP32 Client
- LiquidCrystal I2C
- WiFi.h
- time.h (NTP sync)
- Framework: Next.js 15.5.2 (React 19.1.0)
- Styling: Material-UI v7.3.2, Tailwind CSS 4.1.14
- Database: Firebase Realtime Database 12.4.0
- Charts: Recharts 3.1.2
- Carousel: Swiper 11.2.10
- Backend: Firebase (Authentication, Realtime Database)
- AI Model: Grok 4.1 Fast (via OpenRouter API)
- Deployment: Vercel (Web), Firebase Hosting (Database)
- Node.js 20.x or higher
- Arduino IDE 2.x
- Firebase project with Realtime Database enabled
- OpenRouter API key
# Install Arduino ESP32 board support
# Tools โ Board โ Boards Manager โ Search "esp32" โ Install
# Install required libraries via Library Manager:
# - Firebase ESP32 Client by Mobizt
# - LiquidCrystal I2C by Frank de Brabander- Create a Firebase project at console.firebase.google.com
- Enable Realtime Database
- Set database rules:
{
"rules": {
"devices": {
"$deviceId": {
".read": "auth != null",
".write": "auth != null"
}
},
"events": {
"$deviceId": {
".read": "auth != null",
".write": "auth != null"
}
},
"messages": {
"$deviceId": {
".read": "auth != null",
".write": "auth != null"
}
},
"reminders": {
"$deviceId": {
".read": "auth != null",
".write": "auth != null"
}
},
"allowedDoctors": {
".read": "auth != null"
}
}
}- Add authorized caregivers to
/allowedDoctorspath (replace.with,in email)
- Open Arduino sketch
- Update Wi-Fi credentials:
#define WIFI_SSID "your-wifi-ssid"
#define WIFI_PASSWORD "your-wifi-password"- Update Firebase credentials:
#define API_KEY "your-firebase-api-key"
#define DATABASE_URL "your-database-url" // e.g., https://project-id.firebaseio.com- Upload to ESP32
# Clone repository
git clone https://github.com/yourusername/smart-medicine-box.git
cd smart-medicine-box
# Install dependencies
npm install
# Create .env.local file
cp .env.example .env.localEdit .env.local:
OPENROUTER_API_KEY3=your_openrouter_api_key
NEXT_PUBLIC_FIREBASE_API_KEY=your_firebase_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_DATABASE_URL=https://your-project.firebaseio.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your-sender-id
NEXT_PUBLIC_FIREBASE_APP_ID=your-app-id
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=G-XXXXXXXXXX# Development mode
npm run dev
# Production build
npm run build
npm startOpen http://localhost:3000 in your browser.
- Login: Access
/loginand authenticate with Google - Dashboard: View all registered devices
- Select Patient: Choose a device to monitor
- View Logs: See complete event history with timestamps
- Analyze Data: View charts and AI-generated summaries
- Send Messages: Communicate directly with the patient
- Set Reminders: Schedule medication alerts with custom repeat cycles
- Power On: Connect the Smart Medicine Box to power
- Wait for Connection: LCD shows "Smart Medicine Box" โ Wi-Fi connected
- Take Medicine: Press left button when taking medication
- Emergency: Press right button for urgent caregiver notification
- Follow Reminders: Respond to buzzer alerts and LCD messages
smart-medicine-box/
โโโ arduino/
โ โโโ smart_medicine_box.ino # ESP32 firmware
โโโ src/
โ โโโ app/
โ โ โโโ api/
โ โ โ โโโ ai-chat/route.ts # Conversational AI endpoint
โ โ โ โโโ ai-summary/route.ts # Log summarization endpoint
โ โ โโโ analyse/page.tsx # Analytics dashboard
โ โ โโโ dashboard/page.tsx # Caregiver dashboard
โ โ โโโ login/page.tsx # Authentication page
โ โ โโโ logs/page.tsx # Event history viewer
โ โ โโโ messages/page.tsx # Messaging interface
โ โ โโโ reminders/page.tsx # Reminder scheduler
โ โ โโโ layout.tsx # Root layout
โ โ โโโ page.tsx # Landing page
โ โโโ components/
โ โ โโโ analyse/
โ โ โโโ AnalyseChat.tsx # AI chat component
โ โโโ lib/
โ โโโ firebase.ts # Firebase configuration
โ โโโ theme.ts # Material-UI theme
โโโ .env.example # Environment template
โโโ firebase.json # Firebase config
โโโ next.config.ts # Next.js config
โโโ package.json # Dependencies
โโโ README.md # This file
Generates automated adherence summaries from patient logs.
Request:
{
"timeRange": "Week",
"medicineTaken": 42,
"emergencies": 3,
"dailyBreakdown": [...],
"reminders": [...]
}Response:
{
"summary": "Patient showed 85% adherence this week with 3 emergency alerts..."
}Conversational AI for querying patient data.
Request:
{
"messages": [
{"role": "user", "content": "How many doses were missed this week?"}
],
"stats": {...}
}Response:
{
"reply": "Based on the logs, the patient missed 6 doses this week..."
}- SMS/Email notifications (Twilio/SendGrid integration)
- Mobile application (React Native)
- Battery backup system for power outages
- Automated pill dispensing mechanism
- Weight sensors for pill counting
- Fall detection and activity monitoring
- Firebase for cloud infrastructure and real-time database
- OpenRouter for AI model access
- Material-UI and Next.js communities for excellent documentation
โญ Star this repository if you find it helpful!