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!