Difference between revisions of "Arduino: RTC and LCD"

From OnnoWiki
Jump to navigation Jump to search
(Created page with " Source: #include <Wire.h> #include “RTClib.h” #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); RTC_DS1307 RTC; void setup () { Serial.begin(9...")
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
Sumber: http://microcontrollerslab.com/real-time-clock-ds1307-interfacing-arduino/
  
 +
[[File:Circuit-diagram-of-DIgital-clock-using-real-time-clock-and-Arduino.png|center|200px|thumb]]
  
  
 
Source:
 
Source:
 +
  
 
  #include <Wire.h>
 
  #include <Wire.h>
  #include “RTClib.h”
+
  #include <RTClib.h>
 
  #include <LiquidCrystal.h>
 
  #include <LiquidCrystal.h>
 +
 
  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
 
  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
 
  RTC_DS1307 RTC;
 
  RTC_DS1307 RTC;
 
   
 
   
 
  void setup () {
 
  void setup () {
Serial.begin(9600);
+
    Serial.begin(9600);
Wire.begin();
+
    Wire.begin();
RTC.begin();
+
    RTC.begin();
lcd.begin(20, 4);
+
    lcd.begin(16, 2);
+
   
pinMode(8,OUTPUT);
+
    pinMode(8,OUTPUT);
 
+
 
if (! RTC.isrunning()) {
+
    if (! RTC.isrunning()) {
Serial.println(“RTC is NOT running!);
+
      Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
+
      // following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
+
      RTC.adjust(DateTime(__DATE__, __TIME__));
}
+
      }
 
  }
 
  }
  
 
  void loop () {
 
  void loop () {
DateTime now = RTC.now();
+
    DateTime now = RTC.now();
lcd.setCursor(0, 0);
+
    lcd.setCursor(0, 0);
lcd.print(now.day(), DEC);
+
    lcd.print(now.day(), DEC);
lcd.print(/);
+
    lcd.print("/");
lcd.print(now.month(), DEC);
+
    lcd.print(now.month(), DEC);
lcd.print(/);
+
    lcd.print("/");
lcd.print(now.year(), DEC);
+
    lcd.print(now.year(), DEC);
lcd.print(‘ ‘);
+
    lcd.print(" ");
lcd.setCursor(0, 1);
+
    lcd.setCursor(0, 1);
if (now.hour()<10)
+
    if (now.hour()<10)
lcd.print(‘0’);
+
      lcd.print("0");
lcd.print(now.hour(), DEC);
+
    lcd.print(now.hour(), DEC);
lcd.print(:);
+
    lcd.print(":");
if (now.minute()<10)
+
    if (now.minute()<10)
lcd.print(‘0’);
+
      lcd.print("0");
lcd.print(now.minute(), DEC);
+
    lcd.print(now.minute(), DEC);
lcd.print(:);
+
    lcd.print(":");
if (now.second()<10)
+
    if (now.second()<10)
lcd.print(‘0’);
+
      lcd.print("0");
lcd.print(now.second(), DEC);
+
    lcd.print(now.second(), DEC);
delay(1000);
+
    delay(1000);
 
  }
 
  }
 +
 +
 +
 +
==RTCLib==
 +
 +
Bisa di download dari
 +
 +
https://github.com/adafruit/RTClib
 +
 +
copykan library
 +
 +
cd ~/Downloads
 +
unzip RTClib-master.zip
 +
mv RTClib-master RTClib
 +
mv RTClib /usr/share/arduino/libraries/
 +
 +
==Referensi==
 +
 +
* http://microcontrollerslab.com/real-time-clock-ds1307-interfacing-arduino/

Latest revision as of 19:31, 6 May 2017

Sumber: http://microcontrollerslab.com/real-time-clock-ds1307-interfacing-arduino/

Circuit-diagram-of-DIgital-clock-using-real-time-clock-and-Arduino.png


Source:


#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
RTC_DS1307 RTC;

void setup () {
   Serial.begin(9600);
   Wire.begin();
   RTC.begin();
   lcd.begin(16, 2);
   
   pinMode(8,OUTPUT);
  
   if (! RTC.isrunning()) {
      Serial.println("RTC is NOT running!");
      // following line sets the RTC to the date & time this sketch was compiled
      RTC.adjust(DateTime(__DATE__, __TIME__));
      }
}
void loop () {
   DateTime now = RTC.now();
   lcd.setCursor(0, 0);
   lcd.print(now.day(), DEC);
   lcd.print("/");
   lcd.print(now.month(), DEC);
   lcd.print("/");
   lcd.print(now.year(), DEC);
   lcd.print(" ");
   lcd.setCursor(0, 1);
   if (now.hour()<10)
      lcd.print("0");
   lcd.print(now.hour(), DEC);
   lcd.print(":");
   if (now.minute()<10)
      lcd.print("0");
   lcd.print(now.minute(), DEC);
   lcd.print(":");
   if (now.second()<10)
      lcd.print("0");
   lcd.print(now.second(), DEC);
   delay(1000);
}


RTCLib

Bisa di download dari

https://github.com/adafruit/RTClib

copykan library

cd ~/Downloads
unzip RTClib-master.zip
mv RTClib-master RTClib
mv RTClib /usr/share/arduino/libraries/

Referensi