0% found this document useful (0 votes)
6 views14 pages

Arduino Medicine Reminder System

This document outlines the source code for a Medicine Reminder system using Arduino Uno, which reminds users to take their medicine at specified times (8 AM, 2 PM, and 8 PM). It includes details about the circuit setup, LCD screen cycling through messages, and functionality for setting reminders based on button presses. The system uses an RTC module for timekeeping and provides visual and auditory alerts when it's time to take medication.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views14 pages

Arduino Medicine Reminder System

This document outlines the source code for a Medicine Reminder system using Arduino Uno, which reminds users to take their medicine at specified times (8 AM, 2 PM, and 8 PM). It includes details about the circuit setup, LCD screen cycling through messages, and functionality for setting reminders based on button presses. The system uses an RTC module for timekeeping and provides visual and auditory alerts when it's time to take medication.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SOURCE CODE

//Medicine Reminder using Arduino Uno

// Reminds to take medicine at 8am, 2pm, 8pm

/* The circuit:

LCD RS pin to digital pin 12

LCD Enable pin to digital pin 11

LCD D4 pin to digital pin 5

LCD D5 pin to digital pin 4

LCD D6 pin to digital pin 3

LCD D7 pin to digital pin 2

LCD R/W pin to ground

LCD VSS pin to ground

LCD VCC pin to 5V

10K resistor:

ends to +5V and ground

wiper 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 - Seconds

int buzz2pmHH = 14; // HH - hours


int buzz2pmMM = 00; // MM - Minute

int buzz2pmSS = 00; // SS - Seconds

int buzz8pmHH = 20; // HH - hours

int buzz8pmMM = 00; // MM - Minute

int buzz8pmSS = 00; // SS - Seconds

int nowHr, nowMin, nowSec; // to show current mm,hh,ss

// All messeges

void gwsMessege(){ // print get well soon messege

[Link]();

[Link](0, 0);

[Link]("Stay Healthy :)"); // Give some cheers

[Link](0, 1);

[Link]("Get Well Soon :)"); // wish

void helpScreen() { // function to display 1st screen in LCD

[Link]();

[Link](0, 0);

[Link]("Press Buttons");

[Link](0, 1);

[Link]("for Reminder...!");

void timeScreen() { // function to display Date and time in LCD screen

DateTime now = [Link](); // take rtc time and print in display

[Link]();

[Link](0, 0);

[Link]("Time:");

[Link](6, 0);

[Link](nowHr = [Link](), DEC);


[Link](":");

[Link](nowMin = [Link](), DEC);

[Link](":");

[Link](nowSec = [Link](), DEC);

[Link](0, 1);

[Link]("Date: ");

[Link]([Link](), DEC);

[Link]("/");

[Link]([Link](), DEC);

[Link]("/");

[Link]([Link](), DEC);

void setup() {

[Link](9600); // start serial debugging

if (! [Link]()) { // check if rtc is connected

[Link]("Couldn't find RTC");

while (1);

if ([Link]()) {

[Link]("RTC lost power, lets set the time!");

// [Link](DateTime(F(__DATE__), F(__TIME__))); // uncomment this to set the


current time and then comment in next upload when u set the time

[Link](DateTime(2019, 1, 10, 7, 59, 30)); // manual time set

[Link](16, 2);

[Link]();

[Link](0, 0);

[Link]("Welcome To"); // print a messege at startup


[Link](0, 1);

[Link]("Circuit Digest");

delay(1000);

pinMode(push1pin, INPUT); // define push button pins type

pinMode(push2pin, INPUT);

pinMode(push3pin, INPUT);

pinMode(stopPin, INPUT);

pinMode(ledPin, OUTPUT);

delay(200);

[Link]([Link](addr));

val2 = [Link](addr); // read previosuly saved value of push button to


start from where it was left previously

switch (val2) {

case 1:

[Link]("Set for 1/day");

push1state = 1;

push2state = 0;

push3state = 0;

pushVal = 1;

break;

case 2:

[Link]("Set for 2/day");

push1state = 0;

push2state = 1;

push3state = 0;

pushVal = 2;

break;

case 3:
[Link]("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 8am

at8am(); //function to start uzzing at 8am

else if (pushVal == 2) { // if push button 2 pressed then remind at 8am and


8pm

at8am();

at8pm(); //function to start uzzing at 8mm

else if (pushVal == 3) { // if push button 3 pressed then remind at 8am and


8pm

at8am();

at2pm(); //function to start uzzing at 8mm

at8pm();

currentMillisLCD = millis(); // start millis for LCD screen switching at defined


interval of time

push1state = digitalRead(push1pin); // start reading all push button pins


push2state = digitalRead(push2pin);

push3state = digitalRead(push3pin);

stopinState = digitalRead(stopPin);

stopPins(); // call to stop buzzing

changeScreen(); // screen cycle function

// push buttons

void push1() { // function to set reminder once/day

if (push1state == 1) {

push1state = 0;

push2state = 0;

push3state = 0;

// pushPressed = true;

[Link](addr, 1);

[Link]("Push1 Written : "); [Link]([Link](addr)); // for debugging

pushVal = 1; //save the state of push button-1

[Link]();

[Link](0, 0);

[Link]("Reminder set ");

[Link](0, 1);

[Link]("for Once/day !");

delay(1200);

[Link]();

void push2() { //function to set reminder twice/day

if (push2state == 1) {

push2state = 0;
push1state = 0;

push3state = 0;

// pushPressed = true;

[Link](addr, 2);

[Link]("Push2 Written : "); [Link]([Link](addr));

pushVal = 2;

[Link]();

[Link](0, 0);

[Link]("Reminder set ");

[Link](0, 1);

[Link]("for Twice/day !");

delay(1200);

[Link]();

void push3() { //function to set reminder thrice/day

if (push3state == 1) {

push3state = 0;

push1state = 0;

push2state = 0;

// pushPressed = true;

[Link](addr, 3);

[Link]("Push3 Written : "); [Link]([Link](addr));

pushVal = 3;

[Link]();

[Link](0, 0);

[Link]("Reminder set ");

[Link](0, 1);
[Link]("for Thrice/day !");

delay(1200);

[Link]();

void stopPins() { //function to stop buzzing when user pushes stop push button

if (stopinState == 1) {

// stopinState = 0;

// pushPressed = true;

pushpressed = 1;

[Link]();

[Link](0, 0);

[Link]("Take Medicine ");

[Link](0, 1);

[Link]("with Warm Water");

delay(1200);

[Link]();

void startBuzz() { // function to start buzzing when time reaches to defined


interval

// if (pushPressed == false) {

if (pushpressed == 0) {

[Link]("pushpressed is false in blink");

unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= interval) {

previousMillis = currentMillis; // save the last time you blinked the LED

[Link]("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) {

[Link]("pushpressed is true");

ledState = LOW;

digitalWrite(ledPin, ledState);

void at8am() { // function to start buzzing at 8am

DateTime now = [Link]();

if (int([Link]()) >= buzz8amHH) {

if (int([Link]()) >= buzz8amMM) {

if (int([Link]()) > buzz8amSS) {

/////////////////////////////////////////////////////

startBuzz();

/////////////////////////////////////////////////////

void at2pm() { // function to start buzzing at 2pm

DateTime now = [Link]();


if (int([Link]()) >= buzz2pmHH) {

if (int([Link]()) >= buzz2pmMM) {

if (int([Link]()) > buzz2pmSS) {

///////////////////////////////////////////////////

startBuzz();

//////////////////////////////////////////////////

void at8pm() { // function to start buzzing at 8pm

DateTime now = [Link]();

if (int([Link]()) >= buzz8pmHH) {

if (int([Link]()) >= buzz8pmMM) {

if (int([Link]()) > buzz8pmSS) {

/////////////////////////////////////////////////////

startBuzz();

/////////////////////////////////////////////////////

//Screen Cycling

void changeScreen() { //function for Screen Cycling

// Start switching screen every defined intervalLCD

if (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 screen

if (isScreenChanged) // only update the screen if the screen is changed.

isScreenChanged = false; // reset for next iteration

switch (screens)

case getWellsoon:

gwsMessege(); // get well soon message

break;

case HELP_SCREEN:

helpScreen(); // instruction screen

break;

case TIME_SCREEN:

timeScreen(); // to print date and time

break;

default:

//NOT SET.

break;

}
OUTPUT
LCD Screen Cycles Through:

1. Screen 1 – Cheerful Message

Stay Healthy :)

Get Well Soon :)

2. Screen 2 – Help Message

Press Buttons

for Reminder...!

3. Screen 3 – Time & Date

Time: 8:00:10

Date: 10/1/2019

(Will update with your RTC time)

When You Press Push Buttons (9, 8, or 7):

• Push1 (pin 9) → Once/day reminder

LCD:

Reminder set

for Once/day !

• Push2 (pin 8) → Twice/day reminder

LCD:

Reminder set

for Twice/day !

• Push3 (pin 7) → Thrice/day reminder

LCD:

Reminder set

for Thrice/day !
At Reminder Times (8 AM, 2 PM, 8 PM):

• The built-in LED (pin 13) starts blinking.

• Serial Monitor will print:

Start Buzzing

(Buzz continues until you press the STOP button - pin A0)

When You Press STOP Button (A0):

LCD:

Take Medicine

with Warm Water

(Then the buzzer/LED stops)

You might also like