Kamis, 04 Agustus 2016

Jam Digital DS1307 LCD 16X2 FULL SHOW

 JAM DIGITAL DS1307 FULL SHOW
VIA ARDUINO


Salam elektro,pada beberapa jenis jam digital biasanya tidak menggunaka ic backup data,jadi ketika listrik aliran listrik di rumah kalian padam,jam akan mereset pad posisi semula bisanya 12.00 atau tergantung program yang dibuat oleh pabrikan,nah banyak yang bertanya" bagaimana sih agar waktu tersebut tidak reset dengan sendiri,artinya ketika listrik padam,jam tertap menghitung clock detik,pada tutorial kali ini aruselektronika akan memberi solusinya,pada postikan kali ini aruselektronika menambahkan beberapa data yang tampil pada lcd 16x2,silahkan kalian simak penjelasannya dibawah ini.

TOLONG BACA DENGAN DETAIL !

Siapkan alat dan bahan :
  • Arduino Nano/Uno/Mega(sama saja)
  • IC DS1307
  • Crystal 32.768 Khz
  • Breadboard
  • Resistor 10k
  • Laptop
  • Software arduino ide
  • Kabel usb
  • Kabel male to female
  • Library <Wire.h>  (tutorial instal library klik disini)
  • Library "RTClib.h"  (tutorial instal library klik disini)
  • Library <LiquidCrystal.h> (tutorial instal library klik disini)
  • Download simulasi proteus (cara simulasi arduino di proteus klik disini)
1. Sambungkan board arduino & komponen jam lain (sesuai gambar dibawah) 
 
    
CATATAN !
a. Jangan lupa perhatikan sambungan pin SCL dan SDA & pullup resistor 10k,dalam beberapa kasus bila pin tersebut terbalik maka lcd akan menampilkan 65:65:65
b. Apabila ic ds1307 kalian belum pernah sama sekali diisi data bisa kalian hapus "//" (artinya komentar) pada bagian program rtc.adjust(DateTime(2014, 1, 21, 3, 13, 12)); setting manual jam menit detik tanggal bulan tahun dan rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); setting data otomatis menyesuaikan dengan jam di laptop kalian silahkan kalian pilih salah satu   

2. Copy paste sketch/program di bawah ini  ke dalam software arduino 
/*
 * By Fickry Muhammad
 */
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>

RTC_DS1307 rtc;
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

char weekdays[][7]={"Sun","Mon","Tue","Wed","Thr","Fri","Sat"};
char months[][12] = {"No","Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
byte icon1[8]={B00000,B00100,B01110,B01110,B01110,B11111,B00100,B00000};

int var; 
int temp;

void setup () {
  lcd.createChar(0,icon1);
  //Serial.begin(9600);
  Wire.begin();
  rtc.begin();
  lcd.begin(16,2);

  Wire.beginTransmission(0x68);
  Wire.write(0x07); // move pointer to SQW address
  Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
  Wire.endTransmission();


  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    //rtc.adjust(DateTime(2014, 1, 21, 3, 13, 12));
  }else{
    Serial.println("RTC is running!");
    //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void loop () {

  /*
   byte newChar[8] = {
 B00100,
  B01110,
  B01110,
  B01110,
  B01110,
  B01110,
  B11111,
  B00100
};
   */

    /*
     #include <LiquidCrystal.h>
 
LiquidCrystal lcd(5,6,7,8,9,10);
 
byte icon1[8]={B00000,B00100,B01110,B01110,B01110,B11111,B00100,B00000};
void setup()
{
 lcd.begin(16,2);
 lcd.createChar(0,icon1);
 
}
 
void loop()
{
 lcd.write(byte(0))
}
     */
    DateTime now = rtc.now();
    var=analogRead(A0);
    temp = ((var*500)/1024);

    //Serial.println(weekdays[now.dayOfWeek()]);

    char text[50];
    char text2[50];
    char dayofweek[50]; 
    
    //Via Serial
    //sprintf(text, "This Time Is = %02d:%02d:%02d ",  now.hour(),now.minute(),now.second());
    //sprintf(text2, "This Date Is = %02d:%02d:%02d", now.day(),now.month(),now.year());
    //Serial.print(text);
    //Serial.print("\t");
    //Serial.print("\t");
    //Serial.print("\t");
    //Serial.print(text2);
    //Serial.println();
    //Serial.println(dayofweek);
    //*Via LCD
    sprintf(text, "%02d:%02d:%02d ",  now.hour(),now.minute(),now.second());
    sprintf(text2, "%02d",now.year());
    lcd.setCursor(0,1);lcd.print(text);
    lcd.setCursor(12,1);lcd.print(temp);lcd.print(char(223));lcd.print("C");
    lcd.setCursor(0,0);lcd.print(weekdays[now.dayOfWeek()]);lcd.print(",");
    lcd.setCursor(5,0);lcd.print(now.day());lcd.print(" ");lcd.print(months[now.month()]);lcd.print(" ");lcd.print(text2);
    lcd.setCursor(9,1);
    if(now.hour()>12){lcd.write(byte(0));}else{lcd.print("PM");}
    
    /*
    lcd.setCursor(0,0);lcd.print(weekdays[now.dayOfWeek()]);
    lcd.setCursor(5,0);lcd.print(text);
    lcd.setCursor(0,1);lcd.print(months[now.month()]);
    lcd.setCursor(5,1);lcd.print(text2);
    */
    /*
    switch (now.dayOfWeek()){
      case 1:sprintf(dayofweek,"Senin");break;
      case 2:sprintf(dayofweek,"Selasa");break;
      case 3:sprintf(dayofweek,"Rabu");break;
      case 4:sprintf(dayofweek,"Kamis");break;
      case 5:sprintf(dayofweek,"Jum'at");break;
      case 6:sprintf(dayofweek,"Sabtu");break;
      case 7:sprintf(dayofweek,"Minggu");break;
    }
    */
      
    /*
    Serial.print(now.year());
    Serial.print('/');
    Serial.print(now.month());
    Serial.print('/');
    Serial.print(now.day());
    Serial.print(' ');
    Serial.print(now.hour());
    Serial.print(':');
    Serial.print(now.minute());
    Serial.print(':');
    Serial.print(now.second());
    Serial.println();
    */
    delay(200);
}
3. Verify program arduino,apabila tidak terjadi error lanjut dengan proses upload

4. Upload program,apabila succes akan muncul tulisan done uploading,apabila ada yang 
belum tahu bagaimana cara upload code/sketch ke board arduino bisa baca disini

5. Sekarang kalian coba lihat lcd 16x2 pada simulasi atau hardware jika sudah benar maka akan tampil data waktu seperti gambar dibawah ini


Share:

0 comments:

Posting Komentar

Copyright © FILAB | Powered by FILAB
Design by Fickry Muhammad | Technology by Filab.id