使用Arduino的自动药物提醒
原文:https://circuitdigest.com/microcontroller-projects/arduino-medicine-reminder
使用Arduino的自動藥物提醒
ARDUINO PROJECTS
經過**阿比曼尤·潘迪(Abhiemanyu Pandit)** 2019年1月22日
使用Arduino的醫學提醒
對于我們所愛的人,我們始終希望保持他們的健康和健康。但是,如果他們生病而忘記按時吃藥,將會發生什么。我們會擔心,對嗎?在醫院里,有很多病人,很難提醒每個病人準時吃藥。傳統方式需要人工來提醒他們按時服藥。數字時代并沒有隨之而來,我們可以使用機器來做到這一點。Smart Medicine Reminder的應用范圍非常廣泛,可以被家庭患者,醫院的醫生以及許多其他地方使用。關于提醒,可以有多種提醒方法:
我們可以根據需要結合多種方式。為了使事情簡單,我們使用Arduino創建了一個簡單的藥品提醒,提醒我們每天服用1或2或3次藥物。可以使用按鈕選擇時隙。此外,它還顯示當前的日期和時間。我們將其進一步擴展到IoT項目傳入的文章,在該文章中,電子郵件或SMS通知將發送給用戶。該用藥提醒也可以與患者監測系統集成。
使用Arduino的自動藥物提醒所需的組件
使用Arduino Circuit的Arduino Medicine提醒
下面顯示了 使用Arduino構建智能藥箱的完整電路圖
以下是Arduino與不同外設的引腳連接
? Arduino****引腳外圍引腳
- 2 -----------------------------> Dx的16x2 LCD顯示屏
- 3 -----------------------------> D6的16x2 LCD顯示屏
- 4 -----------------------------> D5的16x2 LCD顯示屏
- 5 -----------------------------> D4的16x2 LCD顯示屏
- 7 ----------------------------->第三個按鈕
- 8 ----------------------------->第二個按鈕
- 9 ----------------------------->第一個按鈕
- 11 -----------------------------> 16x2 LCD顯示屏的EN引腳
- 12 -----------------------------> 16x2 LCD顯示器的RS引腳
- 13 -----------------------------> +蜂鳴器和LED的Ve引腳
- A0 ----------------------------->停止按鈕
- A4 -----------------------------> DS3231的SDA
- A5 -----------------------------> DS3231的SCL
- 3.3V -----------------------------> DS3231的Vcc
- Gnd ----------------------------->Gnd
在此醫學提醒項目中,RTC DS3231通過I2C協議與Arduino Uno接口。您還可以使用 RTC IC DS1307與Arduino讀取時間。RTC DS3231還具有內置的32k存儲器,可用于存儲其他數據。RTC模塊通過Arduino uno的3.3V引腳供電。甲16×2 LCD顯示器使用SPI接口。一個buzze R用于警示和提醒,它的時間服藥。四個按鈕用于每個都有獨特選擇功能的地方。第一個按鈕用于提醒每天服藥一次。第二個按鈕每天提醒兩次,第三個按鈕每天提醒三次。當用戶聽到警報時,第四個按鈕用于停止蜂鳴器。
自動藥品提示系統的工作
該丸提醒警報使用5V電源供電。當它第一次啟動時,它會顯示一個歡迎按摩,如" Welcome to Circuit Digest “。LCD屏幕設置為在三個屏幕之間循環。1個ST屏幕顯示按摩為"保持健康,早日康復”。第二個屏幕是一個幫助屏幕,告訴您按選擇按鈕以選擇任何一個要提醒的時間段(一天一次/兩次/三次)。該時隙可在程序中更改,并可進行相應配置。現在,我們將其固定為三個時段,即上午8點,下午2點和晚上8點。
我們將時隙分為三種模式。模式1用于選擇吃藥一次/天在早上8時,用戶按下1個ST按鈕。當用戶按下第二個按鈕時,模式2選擇每天兩次在上午8點和晚上8點服藥。模式3個選擇吃藥三次/天上午8點,下午2點和下午8點,如果用戶按壓3次按鈕。
我們還可以添加一項功能,使蜂鳴器暫停10分鐘(此項目不包括此功能)。當用戶通過按下按鈕選擇所需的插槽時,將記錄用戶輸入,并從RTC中獲取時間。當時間與選定的時隙匹配時,蜂鳴器開始蜂鳴。用戶可以通過按"停止"按鈕來停止蜂鳴器。下一個插槽提醒將繼續相同的過程。本節末尾的視頻中顯示了完整的過程。
編程Arduino UNO進行醫學提醒
一旦想到了提醒服用藥丸的方法,編寫程序就非常容易。此處將在顯示屏上顯示提醒,對蜂鳴器進行蜂鳴并使用LED進行指示。它還具有選擇三個時隙(每天一次/兩次/三次)的選項,并且當時間到時將開始通過蜂鳴器的蜂鳴來提醒患者。然后整個系統將如下所示:
用戶在顯示屏上獲得幫助說明>用戶選擇時隙(一次/天,兩次/天,三次/天)>在顯示屏上顯示確認消息>計時開始>當時間與用戶選擇的時隙相匹配時蜂鳴器和LED響起>用戶停止按下停止按鈕>結束
如果要添加更多功能,我們可以更改程序和硬件。為了以更簡單的方式理解,我們將程序分解為小功能。這些功能易于理解和實現。完整的程序在該項目的末尾給出。讓我們從程序開始。
由于我們使用了其他外設,例如16x2 LCD顯示器,RTC DS3231,因此我們首先必須包含庫f或那個庫。所需的庫如下:
<LiquidCrystal.h> <RTClib.h>(https://github.com/adafruit/RTClib) <EEPROM.h> <Wire.h>如果未打開Arduino,則EEPROM庫用于跟蹤用戶選擇輸入。而且,當用戶打開Arduino電源時,它會使用EEPROM庫獲得按鈕的先前狀態。之所以使用Wire.h庫,是因為RTC DS3231模塊是使用I2C進行通信的。
始終檢查RTC接線是否正確或是否已損壞,因為RTC在整個提醒系統的計時中將發揮重要作用。
if(!rtc.begin()){//檢查rtc是否已連接Serial.println("找不到RTC"); while(1); } if(rtc.lostPower()){ Serial.println(" RTC掉電,請設置時間!"); }時間調整可以通過兩種方式完成,要么自動使用系統編譯時間,要么手動輸入。設置時間后,除非您想再次更改RTC時間,否則請注釋以下幾行。
rtc.adjust(DateTime(F(__ DATE__),F(__ TIME__))); //rtc.adjust(DateTime(2019,1,10,7,59,52));該**switch語句用于讀取按鈕的先前保存狀態,**并在適當和準確的提醒時間恢復該狀態。
val2 = EEPROM.read(addr); //讀取先前保存的按鈕值,從先前保留的位置開始進行switch(val2){case 1:Serial.println("Set for 1 / day"); push1state = 1; push2state = 0; push3state = 0; pushVal = 01; break; case 2:Serial.println(" Set for 2 / day");push1state = 0; push2state = 1; push3state = 0;pushVal = 10; break; case 3:Serial.println(" Set for 3 / day")push1state = 0; push2state = 0; push3state = 1;pushVal = 11; break; }此語句用于使毫秒數用于定時和控制已定義的間隔屏幕循環。
currentMillisLCD = millis(); //在定義的時間間隔內啟動毫秒以進行LCD屏幕切換開始讀取連接到按鈕的數字引腳。
push1state = digitalRead(push1pin); push2state = digitalRead(push2pin); push3state = digitalRead(push3pin); stopinState = digitalRead(stopPin);以下功能用于讀取按鈕狀態并將其寫入EEPROM。每當按下按鈕時,狀態就會寫入EEPROM。它還在所選用戶輸入選項的LCD顯示屏上打印消息。類似地,使用函數push2()和push3()。
void push1(){//if(push1state == 1){ push1state = 0; push2state = 0; push3state = 0; // pushPressed = true; EEPROM.write(addr,1); Serial.print(" Push1 Written:"); Serial.println(EEPROM.read(addr)); //用于調試pushVal = 1; //保存按鈕1的狀態lcd.clear(); lcd.setCursor(0,0); lcd.print(" Reminder set"); lcd.setCursor(0,1); lcd.print("每天一次!"); delay(1200); lcd.clear(); } }以下功能用于停止蜂鳴器和指示燈。提出建議總是好的。在"用溫水服藥"顯示屏上打印建議消息。
void stopPins(){//if(stopinState == 1) 用戶按下停止按鈕時停止嗡嗡聲的功能{ // stopinState = 0; // pushPressed = true; pushval= 1; lcd.clear(); lcd.setCursor(0,0); lcd.print(" Take Medicine"); lcd.setCursor(0,1); lcd.print("帶溫水"); delay(1200); lcd.clear(); } }以下功能與計時無關,但始終在三個屏幕上循環,這對用戶有幫助。由于我們一直在照顧患者,因此請打印問候語,因為我們知道情感支持對于更快地治愈患者非常有幫助。您可以選擇自己的創意信息。讓我們打印一條消息,“保持健康,早日康復”。
第二個屏幕用于向患者發出指示,例如"按提醒按鈕…"。 第三個屏幕僅用于顯示當前日期和時間。
void changeScreen() { //function for Screen Cycling// Start switching screen every defined intervalLCDif (currentMillisLCD - previousMillisLCD > intervalLCD) // save the last time you changed the display{previousMillisLCD = currentMillisLCD;screens++;if (screens > maxScreen) {screens = 0; // all screens over -> start from 1st}isScreenChanged = true;}// Start displaying current screenif (isScreenChanged) // only update the screen if the screen is changed.{isScreenChanged = false; // reset for next iterationswitch (screens){case getWellsoon:gwsMessege(); // get well soon messagebreak;case HELP_SCREEN: helpScreen(); // instruction screenbreak;case TIME_SCREEN:timeScreen(); // to print date and timebreak;default://NOT SET.break;}} }如果已達到所選時間,則此功能可用于同時開始蜂鳴和LED閃爍。
void startBuzz() { // function to start buzzing when time reaches to defined interval // if (pushPressed == false) {if (pushpressed == 0) {Serial.println("pushpressed is false in blink");unsigned long currentMillis = millis();if (currentMillis - previousMillis >= interval) {previousMillis = currentMillis; // save the last time you blinked the LEDSerial.println("Start Buzzing");if (ledState == LOW) { // if the LED is off turn it on and vice-versa:ledState = HIGH;} else {ledState = LOW;}digitalWrite(ledPin, ledState);}}else if (pushpressed == 1) {Serial.println("pushpressed is true");ledState = LOW;digitalWrite(ledPin, ledState);} }*此功能用于比較用戶在上午8點選擇的時隙,并開始蜂鳴蜂鳴器并使LED閃爍,直到用戶按下停止按鈕為止。類似地,*void at2pm()* 和void at8pm的***功能用于啟動蜂鳴器,并在2pm和8pm引導。
void at8am(){//函數從上午8點開始嗡嗡聲DateTime now = rtc.now(); if(int(now.hour())> = buzz8amHH){ if(int(now.minute())> = buzz8amMM){ if(int(now.second())> buzz8amSS){ // /// startBuzz() ; / /// } } } }這是您可以使用Arduino簡單地制作自己的自動藥品提醒的方法。您還可以將ESP8266與Arduino結合使用,使其成為一個IoT項目,該項目將能夠向用戶發送電子郵件警報。
完整的代碼和演示視頻如下。
代碼
//Medicine Reminder using Arduino Uno // Reminds to take medicine at 8am, 2pm, 8pm /* The circuit:LCD RS pin to digital pin 12LCD Enable pin to digital pin 11LCD D4 pin to digital pin 5LCD D5 pin to digital pin 4LCD D6 pin to digital pin 3LCD D7 pin to digital pin 2LCD R/W pin to groundLCD VSS pin to groundLCD VCC pin to 5V10K resistor:ends to +5V and groundwiper to LCD VO pin (pin 3)*/#include <LiquidCrystal.h> #include <Wire.h> #include <RTClib.h> #include <EEPROM.h>int pushVal = 0; int val; int val2; int addr = 0;RTC_DS3231 rtc;const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // lcd pins LiquidCrystal lcd(rs, en, d4, d5, d6, d7);#define getWellsoon 0 #define HELP_SCREEN 1 #define TIME_SCREEN 2//bool pushPressed; //flag to keep track of push button state int pushpressed = 0; const int ledPin = LED_BUILTIN; // buzzer and led pin int ledState = LOW; int Signal = 0;int buzz = 13; int push1state, push2state, push3state, stopinState = 0; // int push1Flag, push2Flag, Push3Flag = false; // push button flags int push1pin = 9; int push2pin = 8; int push3pin = 7; int stopPin = A0; int screens = 0; // screen to show int maxScreen = 2; // screen count bool isScreenChanged = true;long previousMillis = 0; long interval = 500; // buzzing interval unsigned long currentMillis;long previousMillisLCD = 0; // for LCD screen update long intervalLCD = 2000; // Screen cycling interval unsigned long currentMillisLCD;// Set Reminder Change Time int buzz8amHH = 8; // HH - hours ##Set these for reminder time in 24hr Format int buzz8amMM = 00; // MM - Minute int buzz8amSS = 00; // SS - Secondsint buzz2pmHH = 14; // HH - hours int buzz2pmMM = 00; // MM - Minute int buzz2pmSS = 00; // SS - Secondsint buzz8pmHH = 20; // HH - hours int buzz8pmMM = 00; // MM - Minute int buzz8pmSS = 00; // SS - Secondsint nowHr, nowMin, nowSec; // to show current mm,hh,ss// All messeges void gwsMessege(){ // print get well soon messegelcd.clear();lcd.setCursor(0, 0);lcd.print("Stay Healthy :)"); // Give some cheerslcd.setCursor(0, 1);lcd.print("Get Well Soon :)"); // wish }void helpScreen() { // function to display 1st screen in LCDlcd.clear();lcd.setCursor(0, 0);lcd.print("Press Buttons");lcd.setCursor(0, 1);lcd.print("for Reminder...!");}void timeScreen() { // function to display Date and time in LCD screenDateTime now = rtc.now(); // take rtc time and print in displaylcd.clear();lcd.setCursor(0, 0);lcd.print("Time:");lcd.setCursor(6, 0);lcd.print(nowHr = now.hour(), DEC);lcd.print(":");lcd.print(nowMin = now.minute(), DEC);lcd.print(":");lcd.print(nowSec = now.second(), DEC);lcd.setCursor(0, 1);lcd.print("Date: ");lcd.print(now.day(), DEC);lcd.print("/");lcd.print(now.month(), DEC);lcd.print("/");lcd.print(now.year(), DEC); }void setup() {Serial.begin(9600); // start serial debuggingif (! rtc.begin()) { // check if rtc is connected Serial.println("Couldn't find RTC");while (1);}if (rtc.lostPower()) {Serial.println("RTC lost power, lets set the time!");}// rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // uncomment this to set the current time and then comment in next upload when u set the timertc.adjust(DateTime(2019, 1, 10, 7, 59, 30)); // manual time setlcd.begin(16, 2);lcd.clear();lcd.setCursor(0, 0);lcd.print("Welcome To"); // print a messege at startuplcd.setCursor(0, 1);lcd.print("Circuit Digest");delay(1000);pinMode(push1pin, INPUT); // define push button pins typepinMode(push2pin, INPUT);pinMode(push3pin, INPUT);pinMode(stopPin, INPUT);pinMode(ledPin, OUTPUT);delay(200);Serial.println(EEPROM.read(addr));val2 = EEPROM.read(addr); // read previosuly saved value of push button to start from where it was left previouslyswitch (val2) {case 1:Serial.println("Set for 1/day");push1state = 1;push2state = 0;push3state = 0;pushVal = 1;break;case 2:Serial.println("Set for 2/day");push1state = 0;push2state = 1;push3state = 0;pushVal = 2;break;case 3:Serial.println("Set for 3/day");push1state = 0;push2state = 0;push3state = 1;pushVal = 3;break;}}void loop() {push1(); //call to set once/day push2(); //call to set twice/day push3(); //call to set thrice/day if (pushVal == 1) { // if push button 1 pressed then remind at 8amat8am(); //function to start uzzing at 8am }else if (pushVal == 2) { // if push button 2 pressed then remind at 8am and 8pmat8am(); at8pm(); //function to start uzzing at 8mm}else if (pushVal == 3) { // if push button 3 pressed then remind at 8am and 8pmat8am();at2pm(); //function to start uzzing at 8mmat8pm();}currentMillisLCD = millis(); // start millis for LCD screen switching at defined interval of timepush1state = digitalRead(push1pin); // start reading all push button pinspush2state = digitalRead(push2pin);push3state = digitalRead(push3pin);stopinState = digitalRead(stopPin);stopPins(); // call to stop buzzingchangeScreen(); // screen cycle function}// push buttons void push1() { // function to set reminder once/day if (push1state == 1) {push1state = 0;push2state = 0;push3state = 0; // pushPressed = true;EEPROM.write(addr, 1);Serial.print("Push1 Written : "); Serial.println(EEPROM.read(addr)); // for debuggingpushVal = 1; //save the state of push button-1 lcd.clear();lcd.setCursor(0, 0);lcd.print("Reminder set ");lcd.setCursor(0, 1);lcd.print("for Once/day !");delay(1200);lcd.clear();} }void push2() { //function to set reminder twice/dayif (push2state == 1) {push2state = 0;push1state = 0;push3state = 0; // pushPressed = true;EEPROM.write(addr, 2);Serial.print("Push2 Written : "); Serial.println(EEPROM.read(addr));pushVal = 2;lcd.clear();lcd.setCursor(0, 0);lcd.print("Reminder set ");lcd.setCursor(0, 1);lcd.print("for Twice/day !");delay(1200);lcd.clear();} }void push3() { //function to set reminder thrice/dayif (push3state == 1) {push3state = 0;push1state = 0;push2state = 0; // pushPressed = true;EEPROM.write(addr, 3);Serial.print("Push3 Written : "); Serial.println(EEPROM.read(addr));pushVal = 3;lcd.clear();lcd.setCursor(0, 0);lcd.print("Reminder set ");lcd.setCursor(0, 1);lcd.print("for Thrice/day !");delay(1200);lcd.clear();} }void stopPins() { //function to stop buzzing when user pushes stop push buttonif (stopinState == 1) { // stopinState = 0; // pushPressed = true;pushpressed = 1;lcd.clear();lcd.setCursor(0, 0);lcd.print("Take Medicine ");lcd.setCursor(0, 1);lcd.print("with Warm Water");delay(1200);lcd.clear();} }void startBuzz() { // function to start buzzing when time reaches to defined interval// if (pushPressed == false) {if (pushpressed == 0) {Serial.println("pushpressed is false in blink");unsigned long currentMillis = millis();if (currentMillis - previousMillis >= interval) {previousMillis = currentMillis; // save the last time you blinked the LEDSerial.println("Start Buzzing");if (ledState == LOW) { // if the LED is off turn it on and vice-versa:ledState = HIGH;} else {ledState = LOW;}digitalWrite(ledPin, ledState);}}else if (pushpressed == 1) {Serial.println("pushpressed is true");ledState = LOW;digitalWrite(ledPin, ledState);} }void at8am() { // function to start buzzing at 8amDateTime now = rtc.now();if (int(now.hour()) >= buzz8amHH) {if (int(now.minute()) >= buzz8amMM) {if (int(now.second()) > buzz8amSS) {/startBuzz();/}}} }void at2pm() { // function to start buzzing at 2pmDateTime now = rtc.now();if (int(now.hour()) >= buzz2pmHH) {if (int(now.minute()) >= buzz2pmMM) {if (int(now.second()) > buzz2pmSS) {///startBuzz();//}}} }void at8pm() { // function to start buzzing at 8pmDateTime now = rtc.now();if (int(now.hour()) >= buzz8pmHH) {if (int(now.minute()) >= buzz8pmMM) {if (int(now.second()) > buzz8pmSS) {/startBuzz();/}}} }//Screen Cycling void changeScreen() { //function for Screen Cycling// Start switching screen every defined intervalLCDif (currentMillisLCD - previousMillisLCD > intervalLCD) // save the last time you changed the display{previousMillisLCD = currentMillisLCD;screens++;if (screens > maxScreen) {screens = 0; // all screens over -> start from 1st}isScreenChanged = true;}// Start displaying current screenif (isScreenChanged) // only update the screen if the screen is changed.{isScreenChanged = false; // reset for next iterationswitch (screens){case getWellsoon:gwsMessege(); // get well soon messagebreak;case HELP_SCREEN: helpScreen(); // instruction screenbreak;case TIME_SCREEN:timeScreen(); // to print date and timebreak;default://NOT SET.break;}} }總結
以上是生活随笔為你收集整理的使用Arduino的自动药物提醒的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Scrapy——基本用法(命令行工具、I
- 下一篇: 致敬达叔 -- 80、90的童年观影记忆