You are on page 1of 10

CHAPTER 3

HARDWARE DESIGN AND SOFTWARE IMPLEMENTATION

3.1. Hardware Design

The hardware design of the Arduino Based Medical Remainder includes Power
supply, Liquid Crystal Display, Real time clock module, L298 motor driver, DC motor,
and Arduino UNO .
3.2.Overall Block Diagram

3.3.Block Operation(Brifely)

At the operation of Arduino Based Medical Remainder, Arduino UNO use for
controlling operations. Real Time Clock and Swithches use as input devices.L298Motor
Driver, DC Motor, 16x2Liquid Crystal Display and Buzzer use for output devices. 5VDC
supply and 12DC supply use to active Arduino UNO and L298 Motor Driver.
3.4.Circuit Diagram

Figure: Circuit Diagram of Arduino Based Medicine Remainer

Motor Driver

Figure: The circuit diagram of the L298 motor driver


Figure:pin diagram of the L298 IC

Table: Pin definitions of the L298 IC


Working Principle

Table: Working Principle of the L298 IC


Speed control
The speed of the motors can be adjusted by connecting PWM outputs from your
robot's microcontroller to the ENA and ENB input pins on the motor driver board. The
ENA pin controls Motor A and the ENB pin controls Motor B. When these pins are
HIGH, power is output to the motor. By using PWM, you are turning power on and off
very quickly to adjust the speed of the motor. The longer the PWM duty cycle is, the
faster the motor will turn. We recommend always using a PWM duty cycle of 90% or
less.
Direction control

The direction that the motors turn is controlled using the IN1, IN2, IN3 and IN4 input
pins on the motor driver board. Connect these pins to digital outputs on your robots
microcontroller. To make Motor A go forward, set IN1=HIGH and IN2=LOW. To make
Motor A go backward set IN1=LOW and IN2=HIGH. The same method is used to
control Motor B: set IN3=HIGH and IN4=LOW to o forward and set IN3=LOW and
IN4=HIGH to go backwards. Note that "forward" and "backwards" refer to the direction
of the motors themselves. If your robot does not move in the expected direction, reverse
the motor polarity by swapping the green screw terminals for Motor A + and - and/or
Motor B + and -.
Stopping

To remove power from the motors, simply set ENA=LOW for Motor A and
ENB=LOW for Motor B. This will result in the motors stopping slowly and naturally
from friction. To perform a quick braking operation, set ENA=LOW, IN1=LOW and
IN2=LOW for Motor A and ENB=LOW, IN3=LOW and IN4=LOW for Motor B. The
motors will come to an instant stop. Here are some handy tables to show the various
modes of operation.

3.5.Software Implementation

The software implementation is the Arduino IDE based software


environment. A program written with the Arduino IDE is called a sketch.
Sketches are saved on the development computer as text files with the file
extension .ino. Arduino Software (IDE) pre-1.0 saved sketches with the extension
.pde.

A minimal Arduino C/C++ program consist of only two functions:

 setup(): This function is called once when a sketch starts after power-up or
reset. It is used to initialize variables, input and output pin modes, and other
libraries needed in the sketch.
 loop(): After setup() function exits (ends), the loop() function is executed
repeatedly in the main program. It controls the board until the board is
powered off or is reset.

3.6.Program (Coding)
#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);
pinMode(7,OUTPUT);
lcd.begin(16,2);
lcd.clear();

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);
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());
}
3.7.Program Flowchart
Start

Init all I/O pin

LCD start showing


“Select time”

Set time from user

Yes No
Reach selected
time?

Buzzer on & dc
motor drive forward

Delay (600)

Buzzer off & dc


motor drive
backward

Delay (600)

Display LCD

END

Figure() Programming of the Arduino Based Medical Remainder

3.8.Explanation on Flowchart

Figure: Defining the input/output pins


Figure: Defining switches and declaring Liquid Crystal Display function

Figure: Defining RTC module and setting date and time

Figure: Open medical box reaching setting time

Figure: Close medical box when switch push

You might also like