Professional Documents
Culture Documents
BY
MA EI MYAT MON
GRADUATION THESIS
OCTOBER, 2018
MEIKTILA
TECHNOLOGICAL UNIVERSITY (MEIKTILA)
DEPARTMENT OF ELECTRONIC ENGINEERING
Board of Examiners:
BY
MA EI MYAT MON
A THESIS
SUBMITTED TO THE DEPARTMENT OF
ELECTRONIC ENGINEERING
IN PARTIAL FULFILMENT OF THE REQUIREMENTS
FOR THE BACHELOR DEGREE
(ELECTRONICS)
OCTOBER, 2018
MEIKTILA
i
ACKNOWLEDGEMENT
First, the author would like to express her deep gratitude to Union Minister Dr.
Myo Thein Gyi, Ministry of Education, for opening the Bachelor Degree of
Engineering at Technological University (Meiktila) and his invaluable permission.
The author would like to express her gratitude to Dr. Aung Myo Thu, Pro-
Rector, Technological University (Meiktila), for his kindness and suggestions for
completion of this thesis.
The author is deeply grateful to Dr. Khine Myint Mon, Professor and Head,
Department of Electronic Engineering, Technological University (Meiktila), for her
suggestions, kind encouragements, permission and help till the completion of this
thesis.
The author would like to express special thanks to her supervisor, Dr. May
San Hlaing, Assistant Lecturer, Department of Electronic Engineering, Technological
University (Meiktila), for her patient guidance, constructive comments, criticism,
encouragement and willingness to share ideas during a long period of this thesis.
The author wishes to acknowledge especially to her co-supervisor, Daw Hay
Man Oo, Lecturer, Department of Electronic Engineering, Technological University
(Meiktila), for her guidance, valuable help, encouragement and editing this thesis.
The author is much obliged to the members of the board of examiners and the
groups of checking format and language for the absolute perfection of thesis book, for
their effective suggestions and sharing their valuable experience.
Special thanks go to all the teachers from Technological University (Meiktila)
who have taught her other supporting subjects including English and Mathematics.
Last but not least, the author is deeply grateful to her parents, aunt and brother
for their supports and encouragement to attain her destination without any trouble and
all her friends who help in any situation.
ii
ABSTRACT
This thesis investigates the Arduino based medicine reminder system. This
system includes DS1307 Real Time Clock (RTC) module, L298N motor driver, DC
motor, I2C Liquid Crystal Display (LCD) module, four push buttons and buzzer.
Arduino UNO is used to activate the whole system. Four push button enters the time
for the person to take medicine. The clock module is used to set up time and LCD is
used to display time for the taking medicine. The buzzer is used to alarm the time for
taking medicine. The motor driver is used to drive the DC motor which controls the
opening and closing function of the medical box.
iii
TABLE OF CONTENTS
Page
ACKNOWLEDGEMENT i
ABSTRACT ii
TABLE OF CONTENTS iii
LIST OF FIGURES vi
LIST OF TABLES viii
LIST OF ABBREVIATIONS ix
CHAPTER TITLE
1 INTRODUCTION 1
1.1. Introduction to Alarm System 1
1.2. Aim and Objectives 2
1.3. Scope of Thesis 3
1.4. Implementation Programs 3
1.5. Outline of Thesis 3
2 LITERATURE REVIEW 4
2.1. Historical Background of Pill Dispenser 4
2.2. Smart Pill Boxes 5
2.2.1. Adhere Tech’s Smart Pill Bottle 5
2.2.2. iMediPac 6
2.2.3. Memo Box 6
2.2.4. uBox 7
2.2.5. Glow Cap and Glow Packs 8
2.2.6. Med Minder 8
2.2.7. ePill’s Monitored Med Smart PLUS 8
2.2.8. Philips Medications Dispensing Service 9
3 HARDWARE COMPONENTS OF MEDICINREMINDER 10
3.1. Required Components 10
3.2. Overview of Arduino 10
3.2.1. Types of Arduino Boards 11
3.2.2. Arduino UNO 11
3.2.2.1. Summary of technical specification 12
3.2.2.2. Power 13
iv
3.2.2.3. Memory 14
3.2.2.4. Input and output 14
3.2.2.5. Communication 15
3.2.2.6. Programming 15
3.2.2.7. Automatic (Software) reset 16
3.2.2.8. USB over current protection 16
3.2.2.9. Physical characteristics 17
3.3. Power Supply 17
3.3.1. Full Wave Bridge Rectifier 18
3.3.2. 7805 Regulator 18
3.4. Real Time Clock (RTC) Module 20
3.4.1. Features of DS1307 RTC Module 21
3.4.2. Pin Diagram and Pin Description of DS1307 RTC 22
3.5. Liquid Crystal Display (LCD) 23
3.5.1. LCD Work 24
3.5.2. Features of 16×2 LCD Module 25
3.6. Motor Driver 26
3.7. DC Motor 27
3.8. Push Button 28
3.9. Buzzer 29
4 SOFTWARE AND HARDWARE IMPLEMENTATION 30
4.1. Medicine Reminder Process 30
4.2. Overall Circuit Diagram 31
4.3. Overall Operation 32
4.4. Components List of Arduino Based Medicine Reminder 32
4.5. Software Implementation 33
4.5.1. Software Implementation for RTC Module 33
4.5.2. Software Implementation for Medical Box
Open and Buzzer ON 33
4.5.3. Software Implementation for Medical Box
Close and Buzzer OFF 33
4.6. Overall System Flowchart 34
5 TEST AND RESULTS 36
v
LIST OF FIGURES
Figure Page
1.1. Overall Block Diagram of Arduino Based Medicine Reminder 2
2.1. Shapes of Pills 4
2.2. Adhere Tech’s Smart Pill Bottle 5
2.3. iMediPac Pillbox 6
2.4. Memo Box Pillbox 6
2.5. uBox Pillbox 7
2.6. Exploded View of the uBox Pillbox 7
2.7. Glow Cap and Glow Pack Pillbox 8
2.8. Med Minder Pillbox 8
2.9. ePill's Monitored Med Smart PLUS Pillbox 9
2.10. Philips Medications Dispensing Service 9
3.1. Arduino UNO Board 11
3.2. Pin Specification of Arduino UNO Board 12
3.3. 5V Regulated Power Supply 17
3.4. Full Wave Bridge Rectifier 18
3.5. 7805 Regulator 20
3.6. DS1307 RTC Module 21
3.7. Pin Diagram of DS1307 22
3.8. 16×2 LCD Module with I2C Module 23
3.9. 16×2 LCD Module with I2C Module 24
3.10. L298N Motor Driver 26
3.11. Pin Diagram of L298N IC 26
3.12. DC Motor 28
3.13. Push Button 28
3.14. Buzzer 29
4.1. Medicine Reminder Process 30
4.2. Overall Circuit Diagram 31
4.3. Overall System Flowchart 34
5.1. Testing of Arduino Based Medicine Reminder 36
5.2. Output DC Voltage Testing for Power Section 37
5.3. Testing of Select Time 37
vii
LIST OF TABLES
Table Page
3.1. Pin Description of DS1307 22
3.2. Pin Description of LCD 24
3.3. Pin Description of L298N Motor Driver 26
4.1. Components List of Arduino Based Medicine Reminder 32
ix
LIST OF ABBERVIATIONS
Abberviations Description
AC Alternating Current
AREF Analog Read Reference
DC Direct Current
DFU Device Firmware Update
DIP Dual In line Package
DTR Data Terminal Ready
EEPROM Electrically Erasable Programmable Read Only Memory
FTDI Future Technology Devices International
GPL General Public License
GSM Global System for Mobile
I2C Inter Integrated Circuit
IC Integrated Circuit
IDE Integrated Development Environment
ISP In System Programming
LCD Liquid Crystal Display
LED Light Emitting Diode
LGPL Lesser General Public License
MISO Master In Slave Out
MOSI Master Out Slave In
NV Nonvolatile
OCR Optical Character Recognition
PWM Pulse Width Modulation
RAM Random Access Memory
RTC Real Time Clock
RX Receiver
SCK Serial Clock
x
Switch 1
16x2 LCD
Switch 3
Buzzer
Switch 4
buttons and buzzer. Real Time Clock (RTC) and switches use as input devices for
setting time. L298N motor driver, DC motor, 16×2 Liquid Crystal Display (LCD) and
buzzer use for output devices. DC motor is used to draw the medicine box. LCD is
used to display date and time. Buzzer is used to alarm to take the medicine for the
user.
Second problem is taking of pill on the right time so that manufacturers have
put pills inside special packed to remove them by one by with hand and take on the
time but it could be useless for some patients. Therefore, in 1964, David P. Wagner
has invented the first patent pill dispenser to control oral contraceptive pills of his
wife.
Significant development of pill dispenser has started to appear in 1980s
because of technological developments which have affected all devices because old
devices were not enough to make life easier. Therefore, in the 1980s, automated
dispensing devices appeared on the pill market. The invention and production of these
devices brought hopes of reduced rates of medication errors, increased efficiency for
pharmacy and nursing staff, ready availability of medications.
2.2.2. iMediPac
iMediPac is an intelligent pillbox in which pills are sorted by each day in a
disposable envelope which can be later inserted in the pillbox. Each day the pillbox
lights up the compartment which has to be taken that day and the user breaks and
retrieves the pills from inside the pillbox. If pills are not taken the pillbox alerts
relatives with notifications. On the down side, the pillbox is very bulky of a huge size
making it difficult for a person to carry it all day, while pills can probably have to be
taken throughout the day. It also shows in the promotional videos a complex method
of configuring personal data which may lead to elderly people not being able to
program it correctly. Finally it doesn’t solve the problem of pills complexity as
nurses, pharmacists, etc, have to spend huge amounts of time preparing the dose for
each day in the refill sheet as well as refills having to be constantly bought and
refilled. Figure 2.3 shows the iMediPac pillbox with are filling loaded with pills.
Memo Box is a small pillbox with just one compartment in which many
different pills can be stored. It possesses a portable size and can track when the
pillbox is forgotten at home. Whilst its simplicity can be very attractive it offers no
7
more functionality than the one which could be achieved with a normal pillbox and a
pill reminder application installed in the phone. Figure 2.4 shows the memo box
pillbox with different pills stored inside.
2.2.4. uBox
uBox is a really small pillbox which can be easily carried by its user. It
consists on a cylindrical structure with different compartments inside. It has a
childproof lock and can alert user and relatives if pills are not taken. Different pills for
each dose are stored in the same compartments which may be its only inconvenient.
Figure 2.5 shows an actual photograph of the pillbox while Figure 2.6 shows an
exploded view of the pillbox.
Their elevated price also may dissuade the users to buy this pill dispenser. Figure 2.9
shows some of these pill dispensers.
Figure 3.1 shows the Arduino UNO board. The Arduino UNO is a
microcontroller board based on the ATmega328 (datasheet). It has 14 digital input
and output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16
MHz crystal oscillator, a USB connection, a power jack, an ICSP header and a
reset button. It contains everything needed to support the microcontroller; simply
connect it to a computer with a USB cable or power it with a AC to DC
adapter or battery to get started. The UNO differs from all preceding boards in that it
does not use the FTDI USB to serial driver chip. Instead, it features the Atmega8U2
programmed as a USB to serial converter.
12
UNO means one in Italian and is named to mark the upcoming reference
versions of Arduino, moving forward. The UNO is the latest in a serious of USB
Arduino boards and the reference model for the Arduino platform for a comparison
with previous versions.
Microcontroller ATmega328
Operating voltage 5V
Input voltage (recommended) 7V-12V
Input voltage (limits) 6V-20V
Digital I/O pins 14(of which 6 provide PWM output)
Analog input pins 6
DC current per I/O pin 40mA
DC current for 3.3V pin 50mA
Flash memory 32kB of which 0.5kB is used by bootloader
SRAM 2kB
EEPROM 1kB
Clock speed 16MHz
3.2.2.2. Power
The Arduino UNO can be powered via the USB connection or with an
external power supply. The power source is selected automatically. External (non
USB) power can come either from an AC to DC adapter (wall wart) or battery. The
adapter can be connected by plugging a 2.1mm center positive plug into the board’s
power jack. Leads from a battery can be inserted in the GND and VIN pin headers of
the power connector.
The board can operate on an external supply of 6V to 20V. If it is supplied
with less than 7V, however, the 5V pin may supply less than five volts and the board
may be unstable. If it is used more than 12V, the voltage regulator may overheat and
damage the board. The recommended range is 7V to 12V.
The power pins are as follows:
VIN: The input voltage to the Arduino board when it’s using an external
power source (as opposed to 5V from the USB connection or other
regulated power source). The voltage can be supplied through this pin or if
supplying voltage via the power jack, access it through this pin.
5V: The regulated power supply used to power the microcontroller and
other components on the board. This comes either from VIN via an on-
board regulator or be supplied by USB or another regulated 5V supply.
3.3V: A 3.3V supply generated by the on-board regulator. Maximum
current draw is 50mA.
14
3.2.2.3. Memory
The Atmega328 has 32kB of flash memory for storing code (of which 0.5kB is
used for the bootloader); it has also 2kB of SRAM and 1kB of EEPROM (which can
be read and written with the EEPROM library).
Reset: Bring this line LOW to reset the microcontroller. Typically used to
add a reset button to shield which block the one on the board.
3.2.2.5. Communication
The Arduino UNO has a number of facilities for communicating with a
computer, another Arduino or the ATmega328 provides UART TTL (5V) serial
communication which is available on digital pins 0 (RX) and 1 (TX). An ATmega8u2
on the board channels this serial communication over USB and appears as a virtual
com port to software on the computer. The 8U2 firmware uses the standard USB
COM drivers and no external drive is needed. However, on windows, an *.inf file is
required.
The Arduino software includes a serial monitor which allows simple textual
data to be sent to and from the Arduino board. The RX and TX LEDs on the board
will flash when data is being transmitted via the USB to serial chip and USB
connection to the computer (but not for serial communication on pins 0 and 1).
A software serial library allows for serial communication on any of the UNO’s
digital pins. The ATmega328 also supports I2C (TWI) and SPI communication. The
Arduino software includes a wire library to simplify use of the I2C bus .
3.2.2.6. Programming
The Arduino UNO can be programmed with the Arduino software
(download). Select Arduino UNO w/ATmega32 from the Tools > Board menu
(according to the microcontroller on the board). The ATmega328 on the Arduino
UNO comes preburned with a bootloader that allows to upload new code to it without
the use of an external hardware programmer. It communicates using the original
STK500 protocol.
The ATmega8U2 firmware source code is available. The ATmega8U2 is
loaded with a DFU bootloader which can be activated by connecting the solder
jumper on the back of the board (near the map of Italy) and then resetting the 8U2.
User can use Atmel’s FLIP software (Windows) or the DFU programmer (Mac OS X
and Linux) to load a new firmware. The ISP header can be used with an external
programmer (overwriting the DFU bootloader).
16
case. Note that the distance between digital pins 7 and 8 is 160 mil (0.16 inch), not an
even multiple of the 100 mil spacing of the other pins.
D1 D4
1 2
7805
Np:Ns
D2 D3 3
AC C1 5V Power
Supply
(AC) input into a direct current (DC) output, it is known as a bridge rectifier. A bridge
rectifier provides full wave rectification from a two wire AC input, resulting in lower
cost and weight as compared to a rectifier with a three wire input from a transformer
with a center tapped secondary winding. Figure 3.4 shows full wave bridge rectifier.
Vp = 2 × Vrms -1.4 Equation (3.1)
D1
D4
AC +V
D2 Load
D3 DC
-V
0V
1000µF 100µF
GROUND
OUTPUT
INPUT
GND
registers are used for the clock register the remaining 56 vacant can be used as RAM
contains temporary variable if desired. The first seven registers contain information
about the time of the clock including: seconds, minutes, hours, secondary, date, month
and year. The DS1307 include several components such as power circuits, oscillator
circuits, logic controller and I2C interface circuit and the address pointer register (or
RAM). Figure 3.6 shows the DS1307 RTC module.
X1 1 5 VCC
X2 2 6 SQW/OUT
DS1307
VBAT 3 7 SCL
GND 4 8 SDA
display is very basic module and is very commonly used in various devices and
circuits. These modules are preferred over seven segments and other multi segment
LEDs. A 16×2 LCD means it can display 16 characters per line and there are 2 such
lines. Figure 3.8 shows 16×2 LCD module with I2C module.
The specifications of the LCD module is described below:
Display format: 16 character × 2 line
Viewing direction: 6 o’clock
Input data: 4 bits or 8 bits interface available
Display font: 5 × 8 dots
Power supply: Single power supply (5V + (or) - 10 %)
Since less pin are needed for this thesis, LCM1602 I2C module is used
together with 1602A LCD.
I2C (inter-integrated circuit) protocol uses Serial Data (SDA) and Serial Clock
(SCL) pins and it uses 0x27 address or 0x3F address (sometimes).
Interface: I2C
I2C address: 0x27
Pin definition: VCC, GND,SDA,SCL
Back lit (green with white char color)
Supply voltage: Single power supply
change in the angle of the top polarizing filter. As a result a little light is allowed to
pass the polarized glass through a particular area of the LCD. Thus that particular area
will become dark compared to other. The LCD works on the principle of blocking
light. While constructing the LCD’s, a reflected mirror is arranged at the back. An
electrode plane is made of indium tin oxide which is kept on top and a polarized glass
with a polarizing film is also added on the bottom of the device. The complete region
of the LCD has to be enclosed by a common electrode and above it should be the
liquid crystal matter[16Ano].
Next comes to the second piece of glass with an electrode in the form of the
rectangle on the bottom and, on top, another polarizing film. It must be considered
that both the pieces are kept at right angles. When there is no current, the light passes
through the front of the LCD it can be reflected by the mirror and bounced back. As
the electrode is connected to a battery the current from it causes the liquid crystals
between the common plane electrode and the electrode shaped like a rectangle to
untwist. Thus the light is blocked from passing through. That particular rectangular
area appears blank. Figure 3.9 shows the pin diagram of LCD display and Table 3.2
shows the pin description of LCD display.
14 Data Pin 7
15 LED Positive Backlight LED pin positive terminal
stepping motors. Two enable inputs are provided to enable or disable the device
independently of the input signals. The emitters of the lower transistors of each bridge
are connected together and the corresponding external terminal can be used for the
connection of an external sensing resistor. An additional supply input is provided so
that the logic works at a lower voltage. Figure 3.10 shows the L298N motor driver
module and Figure 3.11 shows the pin diagram of motor driver. Table 3.3 shows the
pin description of L298N motor driver module.
13 Out 3 Outputs of the bridge B; The current that flows through the load
14 Out 4 connected between these two pins is monitored at pin 15.
3.7. DC Motor
Almost every mechanical moment is accomplished by an electric motor.
Electric machines are means of converting energy. Motors take electrical energy and
produce mechanical energy. Nearly all types of DC motors have some internal
mechanism, either electromechanical or electronic, to periodically change the
direction of current flow in part of the motor. DC motors were the first type widely
used, since they could be powered from existing direct current lighting power
distribution systems. DC motor’s speed can be controlled over a wide range, using
either a variable supply voltage or by changing the strength of current in its field
windings. An example of small motor applications includes motors used in
automobile, robot, hand power tools and food blenders. Larger DC motors are used in
propulsion of electrical vehicles, elevator and hoists or in drives for steel rolling mills.
It has two power connections to supply the voltage, one is termed as positive and the
other is negative. The operation voltage is 3V to 6V DC. Reduction ratio is 1:48.
Figure 3.12 shows DC motor.
Specifications of DC motor are as follow:
Operating voltage: 3V to 6V
28
Speed: 2,650rpm at 3V
Speed:5,000rpm at 6V
Free running current: 0.04A at 3V
Free running current: 0.04A at 6V
Stall current: 0.14A at 3V
Stall current: 0.29A at 6V
Length without the shaft: 25mm
Shaft length: 6.5mm
Shaft diameter: 2mm
Weight:19g
or pushed. Buttons are most often biased switches, although many un-biased buttons
(due to their physical nature) still require a spring to return to their unpushed state.
Terms for the pushing of a button include pressing, depressing, mashing, hitting and
punching. Figure 3.13 shows push button.
3.9. Buzzer
A buzzer or beeper is an audio signaling device which may be mechanical,
electromechanical or piezoelectric (piezo for short). Typical uses of buzzers and
beepers include alarm devices, timers and confirmation of user input such as a mouse
click or keystroke. The electric buzzer was invented in 1831 by Joseph Henry. They
were mainly used in early doorbells until they were phased out in the early 1930s in
favor of musical chimes which had a softer tone. There are several different kinds of
buzzers. At future electronics, many of the most common types can be categorized by
type, sound level, frequency, rated voltage, dimension and packaging type. The most
common sizes for sound level are 80dB, 85dB, 90dB and 95dB. Buzzers carry up to
105dB of sound level. There are several types available including electro acoustic,
electromagnetic, magnetic and piezo, among others. Figure 3.14 shows buzzer.
Start
END
Initially, LCD shows the select time. Then, the user set the select time by
pressing push button. When the current time reaches the select time, the buzzer is ON
state and the motor drive reaches forward condition. If the user press any button, the
buzzer is OFF state and the motor drive return to backward condition. Finally, the
current date and time display on LCD.
IN1
IN2
IN1
IN2
Push Button
Buzzer
10k
10k
330
330
GND
6 7 2 3 4 5
D4
Np:Ns GND
D1
8
Arduino UNO
1 7805 2
AC Vcc
SDA SDA
3
RTC module
SCL SCL
D2
.
D3 1000µF 100µF
5V
GND Vcc
Vcc
A4 A5
GND
SDA
SCL
Vcc
GND
I2C module
16
16 xx 22 LCD
LCD
In this system,Arduino UNO is used for controlling the whole system. DS1307
real time clock chip is used for running the time accurate and to prevent the time after
light failure by using 3V li-on battery connected with this real time clock chip at pin
3. SDA and SCL pin of real time clock chip is directly connected with SDA and SCL
pin of Arduino respectively. The main supply VCC is connected with 5V DC supply
circuit. Liquid Crystal Display (LCD) is connected with I2C to reduce from 16 pin to
4 pin. SDA and SCL pin of I2C module is connected with A4 and A5 pin of Arduino
respectively. The power supply pin VCC is directly connected with 5V DC power
32
supply circuit. The pin 8 of Arduino is connected with buzzer. The ground pin of
buzzer is connected with ground pin of Arduino. Four push buttons are connected
with pin 2, 3, 4 and 5 of Arduino respectively. There are 15 pins in L298N motor
driver but only 6 pins are used in this system. IN1 and IN2 which is connected to pin
number 6 and 7 of Arduino respectively. OUT1 and OUT2 pin of L298N motor driver
is connected with DC motor. The power supply pin is connected with 12V DC power
supply. Figure 4.2 shows overall circuit diagram.
4.5.3. Software Implementation for Medical Box Close and Buzzer OFF
The programming language is written for medical box close and buzzer OFF..
At the loop function includes the pin 6 of motor driver is low, pin 7 of motor driver is
high and buzzer is low. At this time, medical box is closed and buzzer is OFF.
(digitalWrite(6,LOW);
34
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
START
Reach selected No
time?
Yes
Buzzer ON and DC
motor drive forward
No
Press any button?
Yes
Display LCD
END
CHAPTER 6
DISCUSSIONS AND CONCLUSION
6.1. Discussions
Arduino based medicine reminder is a prototype design. But it is available for
using in family medical care processes. It have many advantages for elder mans who
helpless from their family and friends. Furthermore, this machine help for the
operations of medical checkup and medical take care at hospital. This machine is
reliable but don’t resist overflow of power. Because this machine use low DC power
consumed devices.
6.2. Conclusion
There are many systems which are serving for the same purpose. But these
systems are difficult to use, non mobile, expensive and complex process. The
proposed system overcomes these problems. The Arduino based medicine reminder is
simple to use, affordable, better accuracy. This system is helpful for every age group
and can also be used in hospital for a group of people. This system definitely reduces
the bad effect caused due to wrong intake of medicine. This system can be made more
effective by upgrading its few features. In future due to manual work, the available
system can become more time consuming. So in the give future, an attempt can be
made to implement fully automatic medication reminder system based on handwritten
character recognition. This is achieved with the help of artificial neural network.
Neural network is very effective to decipher any character of any language. The
accuracy of character recognition is more important. So accuracy of characters needs
to improve by adding probability to each character. For example, a character Q is very
less easy to find because character Q is more often mistaken with O in most of the
OCR systems. The proposed system only set the reminders in the built in calendar
application of the mobile. This reminder reminds user about their medicine in take
schedule. The system which are implementing to give the reminder about doctor’s
41
next appointment. It also tells the user of the end of the medicines. The scheduled
reminder don’t suggest any kind of medicine, dose of medicine, etc.
#include<Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);//27 or 3F
const int DS1307 = 0x68; // Address of DS1307 see data sheets
byte second = 0;
byte minute = 0;
byte hour = 0;
byte weekday = 0;
byte monthday = 0;
byte month = 0;
byte year = 0;
int selecttime=6;
float hours;
void setup() {
pinMode(2,INPUT);pinMode(3,INPUT);pinMode(4,INPUT);pinMode(5,INPUT);
pinMode(6,OUTPUT); pinMode(8,OUTPUT);
lcd.begin (16, 2);
lcd.clear();
45
lcd.setCursor(0,1);
lcd.print("Select time?");
delay(3000);
if (digitalRead(2)) selecttime=4;
if (digitalRead(3)) selecttime=5;
if (digitalRead(4)) selecttime=6;
if (digitalRead(5)) selecttime=7;
delay(1000);
lcd.setCursor(0,1);
lcd.print("Select time=");
lcd.print(selecttime);lcd.print("am");
}
void loop()
{
readTime();
hours=hour+minute/60.0+second/3600.0;
lcd.setCursor(0,0);
lcd.print(monthday); lcd.print("/");
lcd.print(month); lcd.print("/");
lcd.print(year); lcd.print(" ");
lcd.print(hour); lcd.print(":");
lcd.print(minute); lcd.print(":");
lcd.print(second);
if (hours>selecttime&&hours<(selecttime+0.006) ||
hours>(selecttime+8)&&hours<(selecttime+8.006) ||
hours>(selecttime+16)&&hours<(selecttime+16.006) )
//Open
{
digitalWrite(6,HIGH);digitalWrite(7,LOW);digitalWrite(8,HIGH);
delay(500);delay(100);
}
if (digitalRead(2)||digitalRead(3)||digitalRead(4)||digitalRead(5))
//Close
{ digitalWrite(6,LOW);digitalWrite(7,HIGH);digitalWrite(8,LOW);
46
delay(500);delay(100);
}
}
byte bcdToDec(byte val) {
return ((val/16*10) + (val%16));
}
void readTime() {
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(DS1307, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());
weekday = bcdToDec(Wire.read());
monthday = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
RTC software OF ARDUINO BASED MEDICINE REMINDER is shown as
below.
#include <Wire.h>
const int DS1307 = 0x68; // Address of DS1307 see data sheets
const char* days[] =
{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday"};
const char* months[] =
{"January", "February", "March", "April", "May", "June", "July",
"August","September", "October", "November", "December"};
// Initializes all values:
byte second = 0;
byte minute = 0;
byte hour = 0;
byte weekday = 0;
47
byte monthday = 0;
byte month = 0;
byte year = 0;
void setup() {
Wire.begin();
Serial.begin(9600);
delay(2000); // This delay allows the MCU to read the current date and time.
Serial.print("The current date and time is: ");
printTime();
Serial.println("Please change to newline ending the settings on the lower
right of the Serial Monitor");
Serial.println("Would you like to set the date and time now? Y/N");
while (!Serial.available()) delay(10);
if (Serial.read() == 'y' || Serial.read() == 'Y')
// This set of functions allows the user to change the date and time
{
Serial.read();
setTime();
Serial.print("The current date and time is now: ");
printTime();
}
Serial.println("Thank you.");
}
// Continuous function for converting bytes to decimals and vice versa
void loop() {
}
byte decToBcd(byte val) {
return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) {
return ((val/16*10) + (val%16));
}
// This set of codes is allows input of data
void setTime() {
48
Wire.write(byte(0));
Wire.endTransmission();
// Ends transmission of data
}
byte readByte() {
while (!Serial.available()) delay(10);
byte reading = 0;
byte incomingByte = Serial.read();
while (incomingByte != '\n') {
if (incomingByte >= '0' && incomingByte <= '9')
reading = reading * 10 + (incomingByte - '0');
else;
incomingByte = Serial.read();
}
Serial.flush();
return reading;
}
void printTime() {
char buffer[3];
const char* AMPM = 0;
readTime();
Serial.print(days[weekday-1]);
Serial.print(" ");
Serial.print(months[month-1]);
Serial.print(" ");
Serial.print(monthday);
Serial.print(", 20");
Serial.print(year);
Serial.print(" ");
if (hour > 12) {
hour -= 12;
AMPM = " PM";
}
else AMPM = " AM";
50
Serial.print(hour);
Serial.print(":");
sprintf(buffer, "%02d", minute);
Serial.print(buffer);
Serial.println(AMPM);
}
void readTime() {
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(DS1307, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());
weekday = bcdToDec(Wire.read());
monthday = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}