9sdkqM2mm

Smart Pillbox Based on AIR32 Microcontroller

 
Overview
Project Description:
        With the development of technology and the increasing demands for quality of life, people are pursuing health more and more, and are paying more and more attention to medication safety and drug health issues. Incorrect medication use often causes various adverse reactions, and in severe cases, can even be life-threatening. At the same time, the increase in average life expectancy has led to a year-on-year increase in the number of elderly people. Population aging is a problem faced by countries all over the world. As people age, they are prone to various chronic diseases or need to supplement various trace elements, thus requiring continuous medication.
       In real life, the elderly often forget medications due to memory decline or even loss, inevitably leading to missed doses. In today's society, children of the elderly are often unable to remind them to take their medication on time due to work or other reasons.
Therefore, designing a smart pillbox to help the elderly reduce the problem of incorrect or accidental medication use is of great significance for protecting the health of the elderly and reducing the burden on their children.
This project designs a microcontroller-based smart pillbox system that can detect in real time whether the user has opened the pillbox and taken the medication within the set time, and can remind the user to take the medication on time via an alarm clock.
In addition, the smart pillbox can connect to the user's mobile application via a Wi-Fi module, allowing real-time monitoring of medication use and storage through a WeChat mini-program. This helps patients better manage and control their medication, reduce health risks, and improve treatment effectiveness, enabling patients to obtain maximum therapeutic benefits in the best way.
 
The open-source license is
GPL 3.0 
    , the General Public License of GNU. Any project using products under the GPL license must also adopt the GPL license, meaning it must be open-source and free.
    The GPL's premise is the free and open-source use of code, including referencing, modifying, and derivative code, but it does not allow modified or derived code to be released and sold as closed-source commercial software.
    The most significant characteristics of the GPL are "viral dissemination" and "disallowing closed-source commercial release." Linux, which we are familiar with, uses the GPL license. 
 
Project-related functions:
 
The project mainly includes embedded hardware and software design and WeChat mini-program design.
 
Project attributes:
This project is being publicly disclosed for the first time and is my original work. The project has not won any awards in other competitions.
 
Project progress :
The project is currently fully completed.
 
Design principle
: Local medication reminder:
The main function of the smart pillbox is to remind patients to take their medication on time and in the correct dosage. Therefore, the smart pillbox needs to be able to remind patients to take their medication even when offline, and it needs to provide clear audio and visual reminders.
Therefore, this design selects a 32-bit microcontroller as the system controller, and implements the entire system's functions through C language programming. To determine the local medication time, a DS1302 clock chip is selected to provide time information for the smart pillbox, and a buzzer and LED are selected to implement the audio and visual reminder function.
When the microcontroller reads the current time via the SPI protocol and detects that the set medication time has arrived, it can drive the buzzer and LED to remind the patient to take their medication. As for
uploading medication data,
network connectivity is a basic requirement for the smart pillbox. To allow children who are not with their parents to check their parents' medication status in real time, a Wi-Fi connection is used.
Medication data is uploaded to a cloud server via the MQTT protocol, allowing guardians to remotely view medication information.
Regarding the terminal viewing device, after comparing an app and a WeChat mini-program, a WeChat mini-program was chosen. The reasons are as follows:
1. WeChat mini-programs do not require installation and can be used immediately.
2. WeChat mini-programs rely on WeChat, which is an essential software on almost everyone's mobile phone. For smart pillboxes,
displaying
information such as medication time, dosage, and type is crucial.
Detailed information allows users to understand the stored medications without opening the box, enabling elderly users to easily track dosage and type by observing the screen, avoiding unnecessary reminders.
This design uses an OLED screen for displaying this information. OLEDs offer advantages such as vibrant colors, high sensitivity, low power consumption, and high resolution. Furthermore, their self-emissive nature ensures clear visibility of the displayed medication information, whether at night or in strong sunlight. The smart pillbox also features a function to detect the
remaining
medication quantity, allowing users to monitor their medication intake and replenish medication as needed.
Since fingers can block infrared light when taking medication, this design uses an infrared sensor to detect remaining medication. When the infrared sensor detects a medication removal action at the designated time, it indicates that medication has been taken, and the internal program reduces the remaining quantity. After powering on, the
 
system first initializes all hardware components. Upon successful initialization, the ESP01S connects to the network to obtain the current time and writes it to the corresponding register of the DS1302. Then, the ESP01S connects to the cloud server of the Alibaba Cloud IoT platform. The smart pillbox screen displays the actual time. Users can then set medication times using buttons or a mini-program. Three alarms can be set. If the set medication time is reached, a buzzer sounds, the corresponding pillbox prompts to open, and medication information appears on the screen. If medication is not taken on time, an SMS notification is sent to the guardian. Medication information is also uploaded to the cloud for remote viewing via a WeChat mini-program. Information display functions: Hour display function: Drug quantity display function: Minute display function: Drug quantity display function: Time parsing function: void cJSON_Time_Parse(void){ char *data_pt; char *day_string; char *moon_string; char *year_string; char *hour_string; char *minute_string; char *second_string; // data_pt = strstr((const char *)Time_buff, (const char *)"sysTime1"); // Find the address of the time result // data_pt = strstr((const char *)Time_buff, (const char *)"datetime_1"); // Find the address of the time result UsartPrintf(USART_DEBUG, "Time%s ",Time_buff);
 

 




 

 

 

 
 

 
 

 
 

 
 

 



    if (data_pt != NULL) { hour_string = data_pt + 24; // Hour address minute_string = data_pt + 27; // Minute address second_string = data_pt + 30; // Second address strncpy(dest,hour_string,2); hour_return = atoi(dest); strncpy(dest,minute_string,2); min_return = atoi(dest); UsartPrintf(USART_DEBUG, "Time %d:%d
", hour_return, min_return );
        UsartPrintf(USART_DEBUG, "Time acquired and processed successfully
");
    } else {
        UsartPrintf(USART_DEBUG, "Time acquisition failed
"); }}

// Get year function (the string starting with the year is too long, so a different method is used) // Input value is the address of the year // Return value is an integer four-digit decimal int Get_Year(char *y){
    int year_return; char *year_temp; char year[5] = {0}; char i;//The year needs to be extracted once, otherwise it cannot be read year_temp = y;
    for(i = 0; i { year[i] = *year_temp; year_temp ++; }
    year_return = atoi(&year[0]); return year_return;}
//Get the month function//The input value is the address of the month position//The return value is a two-digit decimal integer int Get_Moonth(char *m){ int moonth_return; moonth_return = atoi(m) / 100000000; //Get the month return moonth_return;}
//Get the date function//The input value is the address of the date position//The return value is a two-digit decimal integer int Get_Day(char *d){
    int day_return; day_return = atoi(d) / 1000000; //Get the date
    return day_return;}
//Get Time//Input value is the address of the time location//Return value is the total number of seconds in decimal integers int Get_Times(char *h, char *m, char *s){ int time_return; int hour_return; int min_return; int sec_return;
    hour_return = atoi(h) / 10000; //Get the hour min_return = atoi(m) / 100; //Get the minute sec_return = atoi(s); //Get the second
    time_return = hour_return * 3600 + min_return * 60 + sec_return; //Convert to the total number of seconds
    return time_return;}

Key code in WeChat Mini Program

uses picker-view The component implements a scrolling category selection function.
A `scrollSelecter.vue` file is created to write the selector style, and the function is imported into the "Add Medication Plan" interface.
A `bindChange(e)` event is created to store the set time in an array for easy display and distribution to the smart pillbox.
The `getSelectRes(res)` function in the "Add Medication Plan" interface retrieves the set medication time and other information.
 
A physical demonstration shows
 
 
a 3D-printed monkey resin shell, fabricated on a JLCPCB, powered by Type-C. The main control unit consists of two stacked PCBs connected by copper pillars. The bottom PCB houses the infrared detection module and the network module. The top PCB contains the AIR32 main controller and the OLED display. Overall control is achieved via buttons or a WeChat mini-program.
 
WeChat mini-program display
 
design notes:
This project only includes the control and display part of the smart pillbox. For the bottom sensor PCB, please refer to the attachment or the following link:
Sensor Baseboard Link
Other
demonstration videos: Home Smart Pillbox Developed Based on Hezhou Air32
Due to certain reasons, the project source code only provides the basic part.
Project attachments: Embedded code
WeChat mini-program
 
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2026-03-28 20:45:05
  • The most vicious Chinese website, please take a look and click randomly...
  • Can ADOCE be used to operate mdb files generated by Access on a PC?
  • See who has more ideas
  • Back home
  • Study on MSP430G2553 timer
  • Xilinx FPGA Development Tools

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号