0% found this document useful (0 votes)
36 views9 pages

Nama: Andi Ihzan Iznain NIM: 1926042013 Prodi: Pendidikan Vokasional Mekatronika

The document describes modifications made to an Arduino program to display real-time clock data from a DS3231 RTC module on an LCD screen. The program was modified to: 1. Display the time read from the RTC (hours, minutes, seconds, date) on the LCD. 2. Add an alarm function to turn an LED on at 5:30am and 6:00pm according to the RTC, with the status displayed on the LCD. 3. The program and circuit were tested in Proteus simulator, correctly displaying the time and turning the LED on and off at the set times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views9 pages

Nama: Andi Ihzan Iznain NIM: 1926042013 Prodi: Pendidikan Vokasional Mekatronika

The document describes modifications made to an Arduino program to display real-time clock data from a DS3231 RTC module on an LCD screen. The program was modified to: 1. Display the time read from the RTC (hours, minutes, seconds, date) on the LCD. 2. Add an alarm function to turn an LED on at 5:30am and 6:00pm according to the RTC, with the status displayed on the LCD. 3. The program and circuit were tested in Proteus simulator, correctly displaying the time and turning the LED on and off at the set times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Nama : Andi Ihzan Iznain

NIM : 1926042013
Prodi : Pendidikan Vokasional Mekatronika

(RTC) DS1307 atau DS3231

• Modifikasi Program sebelumnya agar dapat menampilkan data pembacaan waktu pada
LCD 16x2!
• Hasil Modifikasi Program :
#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
#include <LiquidCrystal.h>
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// Convert normal decimal numbers to binary coded decimal


byte decToBcd(byte val){
return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val){
return( (val/16*10) + (val%16) );
}
void setup(){
Wire.begin();
Serial.begin(9600);
lcd.begin(16,2);
// set the initial time here:
// DS3231 seconds, minutes, hours, day, date, month, year
setDS3231time(30,11,20,6,17,3,21);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte
month, byte year){
// sets time and date data to DS3231
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds register
Wire.write(decToBcd(second)); // set seconds
Wire.write(decToBcd(minute)); // set minutes
Wire.write(decToBcd(hour)); // set hours
Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
Wire.write(decToBcd(month)); // set month
Wire.write(decToBcd(year)); // set year (0 to 99)
Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year){
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void displayTime(){
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
// send it to the serial monitor
Serial.print(hour, DEC);
lcd.setCursor(4, 0);
lcd.print(hour, DEC);
// convert the byte variable to a decimal number when displayed
Serial.print(":");
lcd.print(":");
if (minute<10){
Serial.print("0");
lcd.print("0");
}
Serial.print(minute, DEC);
lcd.print(minute, DEC);
Serial.print(":");
lcd.print(":");
if (second<10){
Serial.print("0");
lcd.print("0");
}
Serial.print(second, DEC);
lcd.print(second, DEC);
Serial.print(" ");
lcd.print(" ");
Serial.print(dayOfMonth, DEC);
lcd.setCursor(0, 1);
lcd.print(dayOfMonth, DEC);
Serial.print("/");
lcd.print("/");
Serial.print(month, DEC);
lcd.print(month, DEC);
Serial.print("/");
lcd.print("/");
Serial.print(year, DEC);
lcd.print(year, DEC);
Serial.print(" Hari : ");
switch(dayOfWeek){
case 1:
Serial.println("Minggu");
lcd.print(" [Minggu");
break;
case 2:
Serial.println("Senin");
lcd.print(" [Senin]");
break;
case 3:
Serial.println("Selasa");
lcd.print(" [Selasa]");
break;
case 4:
Serial.println("Rabu");
lcd.print(" [Rabu]");
break;
case 5:
Serial.println("Kamis");
lcd.print(" [Kamis]");
break;
case 6:
Serial.println("Jumat");
lcd.print(" [Jumat]");
break;
case 7:
Serial.println("Sabtu");
lcd.print(" [Sabtu]");
break;
}
}
void loop(){
displayTime(); // display the real-time clock data on the Serial Monitor,
delay(1000); // every second
}

• Hasil Percobaan pada Proteus :


• Berdasarkan soal no. 1 Lakukan analisis berdasarkan program dan hasil yang anda
peroleh!
• Berdasarkan hasil percobaan diatas menggunakan Real Time Clock (RTC) untuk
menampilkan apa yang dibaca oleh RTC menggunakan program
{readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth,
&month, &year);} dimana akan menampilkan secara berurutan dari kiri ke kanan
yaitu detik, menit, jam, hari, tanggal, bulan dan tahun. Dimana akan diurutkan mulai
dari jam, menit, detik dan dipisahkan dengan tanda “:” kemudian dilanjutkan dengan
menampilkan tanggal, bulan dan tahun yang dipisahkan dengan tanda “/” untuk
menampilkan hari digunakan command switch dengan total 7 case dari hari Minggu
sampai dengan hari Sabtu, dan menggunakan variable dayOfWeek yang digunakan
agar RTC dapat membacanya.

• Buatlah rangkaian Alaram dengan algoritma sebagai berikut. Tambahkan LED pada
rangkaian sebagai lampu. Kemudian lakukan settingan pada program setiap pukul 5.30
pagi lampu mati, kemudian apabila masuk pukul 18.00 maka lampu menyala. (indicator
lampu menyala dan mati ada pada LED dan ditampilkan pada LCD
• Program :
#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
#include <LiquidCrystal.h>
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int ledRed = 13;
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val){
return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val){
return( (val/16*10) + (val%16) );
}
void setup(){
Wire.begin();
Serial.begin(9600);
lcd.begin(16,2);
// set the initial time here:
// DS3231 seconds, minutes, hours, day, date, month, year
setDS3231time(57,59,17,6,17,3,21);
pinMode (13, OUTPUT);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte
month, byte year){
// sets time and date data to DS3231
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds register
Wire.write(decToBcd(second)); // set seconds
Wire.write(decToBcd(minute)); // set minutes
Wire.write(decToBcd(hour)); // set hours
Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
Wire.write(decToBcd(month)); // set month
Wire.write(decToBcd(year)); // set year (0 to 99)
Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year){
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void displayTime(){
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
// send it to the serial monitor
Serial.print(hour, DEC);
lcd.setCursor(0, 0);
lcd.print(hour, DEC);
// convert the byte variable to a decimal number when displayed
Serial.print(":");
lcd.print(":");
if (minute<10){
Serial.print("0");
lcd.print("0");
}
Serial.print(minute, DEC);
lcd.print(minute, DEC);
Serial.print(":");
lcd.print(":");
if (second<10){
Serial.print("0");
lcd.print("0");
}
Serial.print(second, DEC);
lcd.print(second, DEC);
Serial.print(" ");
lcd.print(" ");
Serial.print(dayOfMonth, DEC);
lcd.setCursor(0, 1);
lcd.print(dayOfMonth, DEC);
Serial.print("/");
lcd.print("/");
Serial.print(month, DEC);
lcd.print(month, DEC);
Serial.print("/");
lcd.print("/");
Serial.print(year, DEC);
lcd.print(year, DEC);
Serial.print(" Hari : ");
switch(dayOfWeek){
case 1:
Serial.println("Minggu");
lcd.print(" [Minggu");
break;
case 2:
Serial.println("Senin");
lcd.print(" [Senin]");
break;
case 3:
Serial.println("Selasa");
lcd.print(" [Selasa]");
break;
case 4:
Serial.println("Rabu");
lcd.print(" [Rabu]");
break;
case 5:
Serial.println("Kamis");
lcd.print(" [Kamis]");
break;
case 6:
Serial.println("Jumat");
lcd.print(" [Jumat]");
break;
case 7:
Serial.println("Sabtu");
lcd.print(" [Sabtu]");
break;
}
if(hour==5 && minute==30 && second<16){
digitalWrite (ledRed, HIGH);
lcd.setCursor(9, 0);
lcd.print("LED:ON ");
}
else if(hour==18 && minute==0 && second<16){
digitalWrite (ledRed, HIGH);
lcd.setCursor(9, 0);
lcd.print("LED:ON ");
}
else {
digitalWrite (ledRed, LOW);
lcd.setCursor(9, 0);
lcd.print("LED:OFF");
}
}
void loop(){
displayTime(); // display the real-time clock data on the Serial Monitor,
delay(1000); // every second
}

• Tampilan pada Proteus untuk pukul 5.30 :

• Tampilan pada Proteus untuk pukul 18.00 :

You might also like