A prototype voice-activated medication management system designed to help patients adhere to their medication schedules. This project integrates a Raspberry Pi with a ReSpeaker 4-Mics Pi HAT, an Arduino-controlled smart pillbox, and Google Cloud AI services to provide a seamless assistive experience.
The development of this project was supported by Google Gemini 3.
The IoT Medication Manager combines:
- Voice Assistant: Reminds patients to take medication and understands natural language responses using Google Gemini 2.5 Flash.
- Smart Pillbox: Detects physical compartment openings via an Arduino interface to automatically log medication intake.
- Caregiver Dashboard: A real-time web interface for caregivers to monitor patient status and receive alerts.
The system follows a hybrid architecture combining local embedded control with cloud-based AI.
graph TD
subgraph "Hardware Layer"
Arduino[Arduino Pillbox] -- Serial (USB) --> RPi[Raspberry Pi 4]
ReSpeaker[ReSpeaker 4-Mics HAT] -- GPIO/SPI --> RPi
Mic[Microphone Array] -- Audio Input --> ReSpeaker
Speaker[Speaker] -- Audio Output --> ReSpeaker
LEDs[APA102 LEDs] -- SPI --> ReSpeaker
end
subgraph "Application Layer (Flask)"
VoiceThread[Voice Assistant Thread]
PillboxThread[Pillbox Monitor Thread]
WebApp[Flask Web Server]
SocketIO[Socket.IO Server]
DB[(SQLite Database)]
end
subgraph "Google Cloud Services"
STT[Speech-to-Text API]
TTS[Text-to-Speech API]
Gemini["Vertex AI (Gemini 2.5)"]
end
subgraph "Frontend"
Dashboard[Caregiver Dashboard]
Calendar[Patient Calendar]
end
%% Connections
RPi --> VoiceThread
RPi --> PillboxThread
VoiceThread -- Audio Stream --> ReSpeaker
ReSpeaker -- Audio Data --> VoiceThread
VoiceThread -- LED Control --> LEDs
VoiceThread -- Audio --> STT
STT -- Text --> Gemini
Gemini -- Intent --> VoiceThread
VoiceThread -- Text --> TTS
TTS -- Audio --> Speaker
PillboxThread -- Events --> DB
VoiceThread -- Logs --> DB
WebApp -- Reads/Writes --> DB
WebApp -- Updates --> SocketIO
SocketIO -- Real-time Data --> Dashboard
- Raspberry Pi 4 (or 3B+)
- ReSpeaker 4-Mics Pi HAT (for Audio Input & LED feedback)
- Arduino Uno/Nano (for Pillbox sensor control)
- Speaker (3.5mm jack connected to ReSpeaker HAT)
- Magnetic Reed Switches (for detecting pillbox compartment status)
- Python 3.11+
- Google Cloud Platform Account with enabled APIs:
- Cloud Speech-to-Text API
- Cloud Text-to-Speech API
- Vertex AI API
Follow these steps to set up the system from scratch.
git clone https://github.com/jovalie/IoT-Medication-Manager.git
cd IoT-Medication-ManagerInstall the necessary system libraries for audio and GPIO control.
sudo apt-get update
sudo apt-get install portaudio19-dev python3-pyaudio libatlas-base-devCreate and activate a virtual environment.
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt- Create a Service Account in the Google Cloud Console.
- Grant the service account the Vertex AI User role.
- Download the JSON key file.
- Rename it to
google_credentials.jsonand place it in the project root directory.
- Mount the ReSpeaker 4-Mics Pi HAT onto the Raspberry Pi GPIO pins.
- Connect the Speaker to the HAT's 3.5mm audio jack.
- Connect the Arduino to the Raspberry Pi via USB.
- Ensure the Arduino is running the
pill_box.inosketch. - Verify the serial port is
/dev/ttyACM0(or updateSERIAL_PORTinapp.py).
- Ensure the Arduino is running the
The smart pillbox uses an Arduino to monitor 7 compartments (Monday-Sunday) using magnetic reed switches.
- Pin Configuration:
- Pins 2-8: Reed Switches (Input Pullup) for Mon-Sun.
- Pin 13: Status LED (Lights up when a box is open).
- Logic:
- The loop checks the state of all 7 switches continuously.
- When a compartment is opened (Magnet moves away -> Switch HIGH), it sends a serial message:
OPENEVENT:<Day>(e.g.,OPENEVENT:Mon). - This message is intercepted by the Python application (
monitor_pillboxthread) to log the medication intake. - It also tracks the duration the box remains open to validate "real" usage vs accidental triggers (though the primary trigger for the app is the initial open event).
To start the full system (Voice Assistant + Web Server + Pillbox Monitor):
python3 app.py- Web Dashboard: Access at
http://<RPi_IP_Address>:8080/caregiver - Voice Assistant: Follow the console prompts. Press ENTER to start the demo flow for each patient.
If you don't have the specific hardware (ReSpeaker/Arduino) and want to test the logic/web interface on a laptop:
python3 app.py --no-pi- Uses your computer's default microphone/speaker.
- Simulates LED behavior in the console.
- Skips Arduino serial connection.
The system is pre-configured with 4 personas to demonstrate different capabilities:
- Student Hamad: Takes medication immediately via the pillbox (No voice interaction needed).
- Athlete Joan: Asks for a delay ("5 more minutes"), then takes medication via the pillbox.
- Uncle Sam: Misses medication completely (Demonstrates silence detection, retries, and alerts).
- Grandpa Albert: Delays repeatedly until max retries are reached, triggering a caregiver alert.
app.py: Main application entry point (Flask + Voice Logic).pill_box.ino: Arduino sketch for the smart pillbox.interfaces/: Hardware interface modules (LEDs, etc.).templates/: HTML templates for the web dashboard.SYSTEM_DESIGN.md: Detailed system architecture documentation.
