AI & Agents

How to Build a Smart Medication Reminder with OpenClaw on Raspberry Pi

Most DIY Raspberry Pi pill dispensers run on fixed timers. This guide adds an OpenClaw agent that tracks adherence patterns, adjusts reminder timing to the user's routine, confirms dispensing via a Pi Camera, and alerts caregivers through Telegram or WhatsApp when doses are missed.

Fast.io Editorial Team 17 min read
AI agent managing automated workflows and notifications from a cloud workspace

Why Fixed-Timer Pill Dispensers Fall Short

Medication non-adherence causes roughly 125,000 deaths annually in the United States and contributes to $100 billion in avoidable healthcare costs. The scope of the problem is staggering: more than half of patients with chronic conditions either stop taking their medications or fail to follow prescribed schedules over time.

DIY Raspberry Pi pill dispensers have been a popular maker project for years. The standard build is well-documented: wire a servo motor to a rotating pill compartment, write a Python cron job that fires at set times, and attach a buzzer or LED for alerts. Dozens of Instructables and Hackster projects cover this exact pattern. The hardware works. The logic does not adapt.

A fixed-timer dispenser buzzes at 8 AM whether you took your morning dose at 7:30 or slept through it entirely. It cannot tell if pills actually dropped into the collection tray, so a jammed compartment goes unnoticed until someone checks. It has no memory of yesterday's adherence, no concept of early or late doses, and no way to tell anyone that a dose was missed. For someone managing their own medications, this might be acceptable. For a caregiver managing a parent's regimen from another city, it provides zero visibility.

Commercial smart dispensers from Hero Health, MedMinder, and Livi address some of these gaps with cellular connectivity, lockable compartments, and caregiver notification apps. They typically charge $30 or more in monthly subscription fees on top of the hardware. They are closed systems. You cannot modify the reminder logic, add a sensor, or work alongside your preferred messaging platform.

An OpenClaw agent running on a Raspberry Pi gives you the same servo-driven dispensing hardware as a basic DIY build, plus an AI reasoning layer that makes decisions based on context. The agent tracks when each dose was actually taken, learns whether the user tends to take medication early or late, adjusts reminder intervals accordingly, verifies dispensing with a camera, and sends alerts to family members through messaging channels the caregiver already uses. The component cost beyond the Pi stays under $40.

Feature Fixed-Timer Dispenser OpenClaw Smart Dispenser
Scheduled reminders Yes, fixed times Yes, adaptive to routine
Adherence tracking None Per-dose logging with history
Dispensing verification None Camera confirmation
Missed-dose alerts Local buzzer only Telegram, WhatsApp, or Discord
Caregiver visibility None Real-time notifications
Dose adjustment Manual reprogramming Agent updates from natural language
Multi-medication support One schedule per timer Multiple schedules with context
Cost beyond Pi ~$20-35 in parts ~$30-40 in parts

Hardware You Need Beyond the Pi

The hardware for this build is straightforward. You need five components beyond the Raspberry Pi itself, plus a few consumables.

Raspberry Pi 4 or 5 (4 GB minimum, 8 GB recommended): The Pi only runs the OpenClaw gateway. All LLM inference happens in the cloud via API, so even a Pi 4 with 4 GB handles the workload comfortably. A Pi 5 with 8 GB provides more headroom if you want to run additional services. The official OpenClaw docs recommend a USB SSD instead of a microSD card for daily use, since OpenClaw performs frequent small reads and writes to its SQLite database and log files.

Servo motor ($8-12): A standard positional servo like the SG90 or MG90S works well for rotating a pill carousel. Unlike pet feeder builds that use continuous-rotation servos, a positional servo lets you rotate to specific angles, which matters when each compartment holds a different medication. The SG90 is inexpensive, runs on 5V, and delivers enough torque for a plastic pill carousel.

Weekly pill organizer ($5-8): A standard 7-day pill organizer with individual compartments becomes the physical dispenser. Mount it on a lazy Susan bearing or 3D-print a rotating platform. The servo rotates the platform to position each day's compartment over a dispensing slot. For multi-dose schedules (morning and evening), use a 14-compartment organizer or two 7-day units.

Pi Camera Module ($12-25): The Camera Module 3 connects via the Pi's CSI ribbon cable. Position it to see the dispensing slot. After the servo rotates a compartment into position, the agent captures a frame to verify that pills are visible. This catches jams, empty compartments, and confirms the correct compartment was selected.

Piezo buzzer or small speaker ($2-5): An audible reminder that medication is ready. The buzzer connects to a GPIO pin and is triggered by the agent before or after dispensing. For something more capable, a small USB speaker with eSpeak text-to-speech can announce which medication is due.

Wiring summary:

  • Servo VCC (red wire) to Pi 5V (physical pin 2)
  • Servo GND (brown wire) to Pi GND (physical pin 6)
  • Servo signal (orange wire) to GPIO 12 (physical pin 32)
  • Buzzer positive lead to GPIO 18 (physical pin 12)
  • Buzzer negative lead to Pi GND (physical pin 14)
  • Pi Camera ribbon cable to CSI port

Total component cost beyond the Pi: $27-50. If you have a 3D printer, you can print a custom pill carousel and dispensing chute. Thingiverse has several parametric pill dispenser designs that accept standard servo mounts. Without a 3D printer, a pill organizer on a lazy Susan bearing, secured with hot glue and a servo horn adapter, works well enough for a prototype.

One important safety note: this build is a reminder and dispensing aid, not a medical device. It should complement, not replace, proper medical guidance. Always consult a healthcare provider about medication management, especially for elderly users or complex regimens.

Layered architecture diagram showing connected hardware components

Installing OpenClaw and Writing the Hardware Scripts

With the hardware wired, set up the software. OpenClaw installs on Raspberry Pi OS (64-bit, Bookworm or later) and connects to cloud-hosted LLM APIs for inference.

Pi preparation: Start with a fresh Raspberry Pi OS Lite image. Enable the camera interface and I2C through raspi-config. For a headless setup, enable SSH during imaging. Update the system packages and install Node.js, which the OpenClaw gateway requires.

OpenClaw setup: The official Raspberry Pi installation guide at docs.openclaw.ai/install/raspberry-pi walks through the full process: system updates, Node.js installation, running the OpenClaw installer, and completing the onboarding wizard for API keys and channel configuration. The gateway persists state in ~/.openclaw/ and survives reboots, so the agent stays running on your Pi as an always-on service.

Messaging channels: During onboarding, configure at least one messaging channel. Telegram is the most straightforward option for this build because it has an official Bot API designed for automation, allows the agent to message you proactively (important for missed-dose alerts), and is free with no per-message costs. WhatsApp works through the Baileys library if that is the caregiver's preferred platform. Both channels are documented in the OpenClaw channel setup guides.

Servo control script: Create a Python script that the agent calls as a system command. The script accepts a compartment number (0-6 for a 7-day organizer) and rotates the servo to the corresponding angle. For an SG90, each compartment maps to roughly a 25-degree increment across the servo's 180-degree range. The script sets the GPIO pin to output a PWM signal, holds the position for a moment, then returns. The agent never touches GPIO registers directly. It calls this script with an argument and evaluates the result.

Camera verification script: A second script captures a frame from the Pi Camera and saves it as a JPEG. The agent runs this script after dispensing, then analyzes the image to determine whether pills are visible in the dispensing slot. If the compartment appears empty (already taken or jammed), the agent logs the result and can skip the buzzer or escalate to a caregiver alert.

Buzzer script: A simple script that toggles a GPIO pin to produce a tone. The agent calls this when a dose is due. For a USB speaker setup, the script can call eSpeak with a message like "Time for your morning medication."

The OpenClaw agent orchestrates these scripts based on its scheduling and reasoning logic. It decides when to dispense, calls the servo script, verifies with the camera, sounds the buzzer, and logs the outcome. Each script handles one hardware interaction and returns a status. The agent handles the decision-making.

AI-powered audit log showing automated task decisions and timestamps
Fastio features

Store Medication Adherence Logs Where Caregivers Can Search Them

Upload daily adherence reports to a Fast.io workspace. Intelligence Mode auto-indexes every log for AI-powered search, so caregivers can ask questions about medication history and get cited answers. Free for agents: 50 GB storage, 5,000 credits per month, no credit card.

Building Adaptive Reminder Logic with OpenClaw Scheduling

OpenClaw's built-in cron scheduler is the foundation for medication reminders. Unlike a system-level cron job that runs a shell script at a fixed time, OpenClaw's cron spawns a subagent with full access to the agent's context, memory, and tools. This means the scheduled task can reason about the situation before taking action.

Setting up medication schedules: The cron system supports standard cron expressions, interval-based scheduling, and one-shot reminders. A twice-daily medication schedule uses two cron entries. Each cron job spawns a subagent with instructions like "check if the morning dose has been taken, and if not, dispense compartment 3 and alert the user." The subagent has access to the agent's memory of previous doses, so it knows whether today's morning dose already happened.

Adaptive timing from adherence patterns: This is where the AI layer outperforms a fixed timer. After a week of operation, the agent has data on when the user actually confirms each dose. If the user consistently takes their morning medication at 7:45 AM rather than the scheduled 8:00 AM, the agent can adjust the reminder to 7:40 AM. If evening doses tend to happen after dinner around 7:30 PM rather than the scheduled 6:00 PM, the agent shifts accordingly. The agent builds a model of the user's actual routine rather than enforcing an arbitrary schedule.

Escalating reminders for missed doses: When a scheduled dose goes unconfirmed for a configurable window (say 30 minutes), the agent escalates. The first step is a repeat buzzer alert. If still unconfirmed after another interval, the agent sends a message to the caregiver's Telegram or WhatsApp channel: "Morning dose not confirmed as of 8:30 AM. Last confirmed dose was yesterday at 8:02 AM." The caregiver can respond through the same channel, asking the agent to check the camera, retry dispensing, or acknowledge the miss.

Multi-medication scheduling: For users taking different medications at different times, the agent tracks each medication independently. Morning blood pressure medication, midday supplements, and evening prescriptions each get their own schedule, compartment mapping, and adherence history. The agent knows which compartment corresponds to which medication and can provide specific alerts: "Evening atorvastatin not taken" rather than a generic "dose missed."

Natural language schedule changes: When a doctor adjusts a dosage or timing, the caregiver tells the agent in plain language through Telegram: "Change the evening medication to 7 PM instead of 6 PM" or "Add a noon dose on weekdays only." The agent updates its cron schedule without anyone editing a config file. OpenClaw's cron system supports timezone-aware scheduling, so reminders fire at the correct local time even after daylight saving changes.

Caregiver Alerts and Adherence Reporting

For caregivers managing a parent's or relative's medication remotely, visibility into adherence is the most valuable feature. The OpenClaw agent can provide this through the same messaging channels used for reminders.

Real-time missed-dose notifications: When a dose goes unconfirmed past the escalation window, the caregiver receives a message with context: the medication name, scheduled time, how long it has been since the dose was due, and the last confirmed dose timestamp. The caregiver can ask follow-up questions through the chat: "Show me the camera" triggers the camera script and returns a photo of the dispensing area. "What was the adherence this week?" returns a summary from the agent's logs.

Daily and weekly adherence summaries: Using OpenClaw's cron scheduler, a daily summary job runs each evening and sends the caregiver a report: doses taken on time, doses taken late, and any doses missed entirely. A weekly summary adds trend data: adherence percentage, average delay per dose, and whether the pattern is improving or declining. These summaries transform raw dose-by-dose data into something a busy caregiver can scan in ten seconds.

Logging dose data for review: Every dispensing event, confirmation, and alert gets logged with a timestamp. For users who want this data accessible beyond the Pi, Fast.io provides a workspace where the agent can upload daily adherence logs. With Intelligence Mode enabled, the workspace auto-indexes these logs for semantic search. A caregiver could ask the workspace's AI chat, "How many doses were missed last month?" and get a cited answer drawn from the uploaded records. The free agent plan includes 50 GB of storage, 5,000 monthly credits, and 5 workspaces with no credit card required, which is more than enough for years of text-based adherence data.

Alternatively, adherence logs can be stored locally on the Pi, pushed to a Google Sheet via API, or sent to any cloud storage the caregiver prefers. The choice depends on who needs access and how they want to consume the data.

Multi-caregiver support: OpenClaw supports multiple messaging channels simultaneously. The patient can receive reminders on a bedside speaker, a primary caregiver gets alerts on Telegram, and a secondary caregiver receives weekly summaries on WhatsApp. Each channel operates independently, so configuring a new caregiver does not disrupt existing notifications.

For caregivers who want structured, searchable records with built-in AI chat, a Fast.io workspace acts as the long-term archive. The agent uploads log files on a schedule, and the workspace's Intelligence layer makes them queryable. This is especially useful when multiple family members share caregiving duties and need a single source of truth for medication history.

Audit log showing timestamped agent actions and notifications

Safety Considerations and Practical Limitations

A Raspberry Pi medication dispenser is a helpful reminder tool, not a regulated medical device. Understanding its boundaries matters, especially when building for someone else.

This is a reminder, not a prescriber. The agent tracks when doses are taken and reminds the user. It does not make clinical decisions about what to take or how much. Medication schedules should always be set based on a healthcare provider's instructions. The agent enforces the schedule it is given, nothing more.

Physical dispensing has failure modes. Pills can jam in compartments. A servo can stall. The Pi can lose power. Camera-based verification catches some of these failures, but it is not foolproof. For high-risk medications where a missed dose has serious consequences, this system should supplement, not replace, human oversight. A caregiver receiving Telegram alerts about a missed dose still needs to follow up with a phone call or visit.

Privacy and data handling. Medication adherence data is sensitive health information. OpenClaw running on a Pi keeps processing local, with only LLM API calls leaving the device. Camera images stay on the Pi unless you configure the agent to upload them. If you store adherence logs in a cloud workspace, choose a provider with appropriate security controls. Fast.io provides granular permissions at the org, workspace, folder, and file level, audit trails for all access, and does not require a credit card for the free plan, which reduces data exposure risk compared to services that require payment information at signup.

Reliability for always-on operation. A Pi running 24/7 needs a reliable power source. Consider a UPS HAT or battery backup to keep the Pi running through brief power outages. Use a USB SSD rather than a microSD card to avoid storage wear from OpenClaw's continuous database writes. Set up the OpenClaw gateway as a systemd service so it restarts automatically after a reboot.

Regulatory context. In the United States, FDA classification of medication dispensers depends on the claims made and the level of automation. A reminder device that buzzes at set times is generally not regulated. A device that controls access to medications or makes dosing decisions could fall under FDA oversight. This build stays on the reminder side of that line: it presents pills and alerts the user, but does not lock medications away or adjust dosages without explicit human instruction.

When to consider a commercial solution instead. If the user needs tamper-resistant locked compartments, cellular connectivity without home Wi-Fi, or a device with regulatory clearance, commercial options from Hero Health or MedMinder are worth evaluating despite the subscription costs. The DIY approach excels when you want customizable logic, integration with your preferred messaging platform, no ongoing fees, and full control over the data.

Frequently Asked Questions

How do I build a smart pill dispenser with Raspberry Pi?

Wire a positional servo motor (like the SG90) to a rotating pill organizer mounted on a platform. Connect the servo's signal wire to a GPIO pin on the Pi, add a Pi Camera for dispensing verification, and install OpenClaw as the AI agent that manages scheduling, dispensing commands, and notifications. The total component cost beyond the Pi is typically $27 to $50. OpenClaw handles the reminder logic and caregiver alerts through Telegram or WhatsApp.

Can AI improve medication adherence?

Yes. AI-powered reminder systems can adapt to a patient's actual routine rather than enforcing fixed schedules. An OpenClaw agent on a Raspberry Pi tracks when doses are actually taken, adjusts reminder timing based on observed patterns, verifies dispensing with a camera, and escalates to caregivers when doses are missed. This adaptive approach addresses the most common reasons for non-adherence: forgetting, inconvenient timing, and lack of accountability.

What is the best automatic pill dispenser for elderly users?

It depends on the level of oversight needed. Commercial dispensers from Hero Health and MedMinder offer locked compartments and cellular connectivity but require monthly subscriptions of $30 to $60. A Raspberry Pi dispenser with OpenClaw costs less in the long run, provides customizable reminder logic, and sends caregiver alerts through familiar messaging apps. For elderly users, the DIY option works best when a tech-capable family member can set it up and a caregiver monitors the alerts.

How does OpenClaw handle scheduled reminders?

OpenClaw has a built-in cron scheduler that supports cron expressions, interval-based repeats, and one-shot reminders. Each scheduled job spawns a subagent with access to the full tool ecosystem, meaning it can reason about context (has the dose been taken already?), execute hardware scripts (trigger the servo), and send messages through configured channels (Telegram, WhatsApp, Discord). Jobs persist across reboots and support timezone-aware scheduling.

How much does it cost to build a Raspberry Pi pill dispenser?

The core components beyond the Raspberry Pi cost roughly $27 to $50: a servo motor ($8-12), a pill organizer ($5-8), a Pi Camera Module ($12-25), and a piezo buzzer ($2-5). A Raspberry Pi 4 with 4 GB starts around $55. OpenClaw is free to install and run. LLM API costs for cloud inference (required for the AI reasoning layer) are typically a few dollars per month for a medication reminder workload.

Is a DIY pill dispenser safe for someone with dementia?

A DIY dispenser works as a reminder and dispensing aid but lacks the tamper-resistant locked compartments found in commercial medical dispensers. For someone with dementia who might take extra doses, a locked commercial dispenser is safer. The DIY approach is better suited for users who are cognitively capable but forgetful, or situations where a caregiver checks in regularly via the messaging alerts.

Related Resources

Fastio features

Store Medication Adherence Logs Where Caregivers Can Search Them

Upload daily adherence reports to a Fast.io workspace. Intelligence Mode auto-indexes every log for AI-powered search, so caregivers can ask questions about medication history and get cited answers. Free for agents: 50 GB storage, 5,000 credits per month, no credit card.