2017년 8월 8일 화요일

ds1307 RTC 모듈로 시계구현 하기

ds1307 RTC 모듈은 뒤에 코인형 밧데리를 끼워서 시간 진행상태를 유지해주는 모듈입니다.

RTC 라이브러리를 아래링크에서 받아서 아두이노에 설치합니다.

RTC 모듈의 SDA 핀은 아두이노 우노의 A4, SCL 핀은 아두이노 우노의 A5에 연결합니다.


// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
 
#include <Wire.h>
#include "RTClib.h"
 
RTC_DS1307 RTC;
 
void setup () {
    Serial.begin(9600);
    Wire.begin();
    RTC.begin();
 
  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();
 
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
 
    delay(1000);
}

그러면 아래와 같이 시리얼 모니터에 나옵니다.

댓글 없음:

댓글 쓰기