0% found this document useful (0 votes)
59 views12 pages

Alarm Otomatis: Sistem Kerja Alat

This document describes an Arduino-based automatic alarm system that uses an RTC module, LCD display, buttons, and buzzer. The system allows the user to set the alarm time and turn the alarm on/off using buttons. When the current time matches the set alarm time, the buzzer will sound until turned off. The code includes functions for reading the RTC, displaying time on LCD, checking buttons, setting and storing alarm times in EEPROM, and converting between BCD and decimal formats for time.

Uploaded by

Bastian Salfinus
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)
59 views12 pages

Alarm Otomatis: Sistem Kerja Alat

This document describes an Arduino-based automatic alarm system that uses an RTC module, LCD display, buttons, and buzzer. The system allows the user to set the alarm time and turn the alarm on/off using buttons. When the current time matches the set alarm time, the buzzer will sound until turned off. The code includes functions for reading the RTC, displaying time on LCD, checking buttons, setting and storing alarm times in EEPROM, and converting between BCD and decimal formats for time.

Uploaded by

Bastian Salfinus
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
You are on page 1/ 12

1 Inkubatek [supported by : www.tokotronik.

com]

Alarm otomatis
Sistem Kerja Alat:
Alarm akan berbunyi sesuai dengan jam yang telah dibuat sebelumnya. Disamping
menapilkan display tersebut jam dapat diseting dengan 4 tombol yaitu tombol Next, Back,
Up dan Down.

Kebutuhan Hardware :
 Modul RTC DS1307
 4 Tombol push ON
 LCD 2x16
 Buzzer
 Modul Arduino UNO
 Power supply +9Volt

INKUBATEK

Modul RTC DS1307 Buzzer

Diagram Blok:
RTC
DS1307
LCD 2x16

Tombol Set
Arduino UNO

Tombol Up

Tombol Down

Buzzer
Tombol Alarm
OFF

Schematics
2 Inkubatek [supported by : www.tokotronik.com]

INKUBATEK

Koneksi Arduino UNO dengan LCD:


Pin ARDUINO LCD

2 RS
3 EN
4 D4
5 D5
6 D6
7 D7

Koneksi RTC:
Pin RTC Pin ARDUINO

VCC +5V
GND GND
SDA Pin A4
SCL Pin A5
3 Inkubatek [supported by : www.tokotronik.com]

Koneksi Tombol:
Tombol Pin ARDUINO

NEXT Pin 8
BACK Pin 9
UP Pin 10
DOWN Pin 11

Koneksi ARDUINO:
Pin ARDUINO Koneksi

Pin 12 Buzzer +

Source Code/Sketch :
/*************************************
* Program : Project 6. Alarm otomatis
* Input : 4 Tombol push on, Module RTC DS1307
* Output : LCD 2x16, BUZZER
* 125 Proyek Arduino Inkubatek
* www.tokotronik.com
* ***********************************/
#include <EEPROM.h>
#include <LiquidCrystal.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00;

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

byte second ,minute,hour, weekDay;


byte monthDay,month,year;
byte minuteOn,hourOn,minuteOff,hourOff;
byte f_tombol, f_alarm, f_key, menu;
byte keluar=1;
byte setRTC;

boolean up=false;
boolean down=false;

void setup(){
pinMode(8,INPUT);
4 Inkubatek [supported by : www.tokotronik.com]

pinMode(9,INPUT);
pinMode(10,INPUT);
pinMode(11,INPUT);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
pinMode(12,OUTPUT);
lcd.begin(16, 2);
lcd.print(" Alarm ARDUINO");
delay(2000);
lcd.clear();
Wire.begin();
//-----------baca alarm
hourOn = EEPROM.read(0);
minuteOn = EEPROM.read(1);
hourOff = EEPROM.read(2);
minuteOff = EEPROM.read(3);
//-----------jika belum ada alarm
if(hourOn==255)hourOn=0;
if(minuteOn==255)minuteOn=0;
if(hourOff==255)hourOff=0;
if(minuteOff==255)minuteOff=0;

/*
//-------------- seting jam
hour=12;
minute=30;
second=0;
weekDay=1;
monthDay=29;
month=4;
year=16;
setingRTC();
*/

}
void loop(){
bacaRTC();
lcdDisplay();
lcd.setCursor(0,1);
lcd.print("Alarm ");
lcd.print(hourOn);
lcd.print(":");
lcd.print(minuteOn);
5 Inkubatek [supported by : www.tokotronik.com]

lcd.print(":0 ");
//---------- jika waktu sama dengan jam alarm ON maka alarm ON
if(hourOn==hour && minuteOn==minute && f_alarm==0){
digitalWrite(12,HIGH);
f_key=1;
}
//---------- jika waktu sama dengan jam alarm OFF maka alarm OFF
else if(hourOff==hour && minuteOff==minute){
digitalWrite(12,LOW);
f_alarm=0;
f_key=0;
}
//---------- jika Tombol matikan alarm di tekan maka alarm OFF
if(digitalRead(11)==0){
digitalWrite(12,LOW);
f_alarm=1;
f_key=0;
}
delay(200);
if(f_key==0){
cekTombol();
}
}

void cekTombol(){
if (digitalRead(8)==0){
do{
f_tombol++;
delay(100);
if(f_tombol>20)goto lanjut;
}
while(!digitalRead(8));

lanjut:
if(f_tombol<20){
setRTC=1;
lcd.clear();
lcd.print("Set Alarm");
delay(2000);
lcd.clear();
}
else{
lcd.clear();
lcd.print("Seting Jam");
delay(2000);
6 Inkubatek [supported by : www.tokotronik.com]

lcd.clear();
setRTC=0;
}
f_tombol=0;
lcdDisplay();
menu++;
lcd.blink();
lcd.setCursor(7,0);
do{
//------------------------next
if (digitalRead(8)==0){
delay(300);
menu++;
}
//---------------------------up
else if(digitalRead(9)==0){
delay(200);
up=true;
}
//----------------------------down
else if(digitalRead(10)==0){
delay(200);
down=true;
}
//-------------------------edit data jam
if (menu==1){
if (up==true && hour < 24){
hour++;
lcdDisplay();
}
else if (down==true && hour>0){
hour--;
lcdDisplay();
}
up=false;
down=false;
if (hour<10){
lcd.setCursor(6,0);
}
else {
lcd.setCursor(7,0);
}
}

//-------------------------edit data menit


7 Inkubatek [supported by : www.tokotronik.com]

else if (menu==2){
if (up==true && minute < 59){
minute++;
lcdDisplay();
}
else if (down==true && minute>0){
minute--;
lcdDisplay();
}
up=false;
down=false;

if (hour<10 && minute<10){


lcd.setCursor(8,0);
}
else if (hour<10 && minute>9){
lcd.setCursor(9,0);
}
else if (hour>9 && minute<10){
lcd.setCursor(9,0);
}
else if (hour>9 && minute>9){
lcd.setCursor(10,0);
}
}

//-------------------------edit data detik


else if (menu==3){
if (up==true && second < 59){
second++;
lcdDisplay();
}
else if (down==true && second>0){
second--;
lcdDisplay();
}
up=false;
down=false;

if (hour<10 && minute<10 && second<10){


lcd.setCursor(10,0);
}
else if (hour<10 && minute<10 && second>9){
lcd.setCursor(11,0);
}
8 Inkubatek [supported by : www.tokotronik.com]

else if (hour<10 && minute>9 && second<10){


lcd.setCursor(11,0);
}
else if (hour>9 && minute<10 && second<10){
lcd.setCursor(11,0);
}
else if (hour<10 && minute>9 && second>9){
lcd.setCursor(12,0);
}
else if (hour>9 && minute>9 && second<10){
lcd.setCursor(12,0);
}
else if (hour>9 && minute<10 && second>9){
lcd.setCursor(13,0);
}
else if (hour>9 && minute>9 && second>9){
lcd.setCursor(13,0);
}
}

//-------------------------simpan data Jam


if (setRTC==0 && menu==4){
setingRTC();
lcd.clear();
lcd.noBlink();
lcd.print("Seting Jam OK!");
delay(1000);
lcd.clear();
keluar=0;
}
//-------------------------simpan data Alarm
//----------------------selisih alarm Off adalah 5 menit
if(menu==3 && setRTC==1){
hourOn=hour;
minuteOn=minute;
hourOff=hour;
minuteOff=minute+5; //penambahan jeda alarm off
if(minuteOff>60){
hourOff=hourOff+1;
minuteOff=minuteOff-60;
}
lcd.noBlink();
lcd.clear();
lcd.print("On =");
lcd.print(hourOn);
9 Inkubatek [supported by : www.tokotronik.com]

lcd.print(":");
lcd.print(minuteOn);
lcd.setCursor(0,1);
lcd.print("Off=");
lcd.print(hourOff);
lcd.print(":");
lcd.print(minuteOff);
//------------simpan EEPROM
EEPROM.write(0, hourOn);
EEPROM.write(1, minuteOn);
EEPROM.write(2, hourOff);
EEPROM.write(3, minuteOff);
delay(3000);
lcd.clear();
lcd.print("Set Alarm OK!");
delay(1000);
lcd.clear();
setRTC=0;
keluar=0;
}
}
while(keluar);
keluar=1;
menu=0;
}
}

byte decToBcd(byte val){


return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val) {


return ( (val/16*10) + (val%16) );
}

void bacaRTC(){
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111);
weekDay = bcdToDec(Wire.read());
monthDay = bcdToDec(Wire.read());
10 Inkubatek [supported by : www.tokotronik.com]

month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}

void lcdDisplay(){
if (setRTC==1){
lcd.setCursor(0,0);
lcd.print("Jam ");
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
lcd.print(" ");
}
else{
lcd.setCursor(0,0);
lcd.print("Jam ");
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
lcd.print(":");
lcd.print(second);
lcd.print(" ");
}
}

void setingRTC(){
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop RTC
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
}

Jalannya Alat :
1. Koneksikan antara sistem Arduino dengan peripheral lain seperti pada rangkaian
(skematik).
11 Inkubatek [supported by : www.tokotronik.com]

2. Pasang power supply (adaptor 9 V) dan hidupkan (colokkan ke sumber PLN 220V)
sehingga lampu LED indikator nyala, LCD juga nyala.
3. Tampilan pertama pada LCD :

Alarm ARDUINO

4. Setelah 2 detik tampil menjadi tampilan normal yaitu menampilkan jam dan Alarm:

Jam 12:30:51
Alarm 13:30:0
5. Selanjutnya jika ingin merubah waktu alarm ON tekan tombol set:

Jam 12:30

6. Tekan tombol UP/DOWN untuk seting jam alarm.


7. Kemudian tekan tombol SET untuk seting menit, tekan tombol UP/DOWN untuk seting
menit.
8. Tekan tombol SET untuk menyimpannya, sehingga tampilanya sebagai berikut:

On =13:30
Off =13:35
9. Waktu OFF alarm secara otomatis di tambah 5menit.
10. Selanjutnya LCD menampilkan:

Set Alarm OK!

11. Kemudian program kembali pada tampilan normal:

Jam 12:30:51
Alarm 13:30:0
12. Selanjutnya jika ingin merubah/seting jam, tekan dan tahan tombol SET sampai muncul
tulisan “Seting Jam”:

Seting Jam

13. Setelah 2 detik, kemudian menampilkan:


12 Inkubatek [supported by : www.tokotronik.com]

Jam 13:30:51

14. Tekan tombol UP untuk menambah jam, sedangkan untuk mengurangi tekan tombol
Down.
15. Jika sudah sesuai tekan tombol SET, selanjutnya seting menit dan detik prosesnya sama
dengan seting jam.
16. Setelah semua di seting tekan tombol SET untuk menyimpan data tersebut, sehingga
LCD menampilkan “Seting Jam OK!”:

Seting Jam OK!

17. Tampilan LCD kembali ke tampilan Normal.


18. Alarm akan berbunyi sesuai dengan seting waktu alarm yang telah di simpan tadi.
19. Alarm mati setelah 5 menit alarm ON, sedangkan tombol Alarm OFF juga bisa untuk
mematikan alarm.
20. OK!

[Uji coba memakai hardware “Master Mikro ARDUINO V2” :


http://tokotronik.com/master-mikro-arduino-v2/ ]

You might also like