Koneksi RTC DS1307 dan Nodemcu v3 - Berbage Ilmu | Tutorial Arduino Android SEO Networking Software

Koneksi RTC DS1307 dan Nodemcu v3

Kali ini saya akan memberikan tutorial tentang bagaimana melakukan koneksi atau menghubungkan RTC DS1307 dengan Esp Nodemcu V3. berikut ini merupakan koneksi antar pin RTC DS1307 dan Nodemcu v3.
Koneksi Pin :
RTC         Nodemcu
GND ----- GND
VCC ------ 3v / 5v
SDA ------ D2
SCL ------- D1
Selanjutnya anda download library RTC nya DISINI. Kemudian anda tambahkan library tersebut ke Arduino IDE anda. Langkah selanjutnya copy sketch berikut dan paste di projek pada Arduino IDE anda.

// CONNECTIONS:
// DS1307 SDA --> D2
// DS1307 SCL --> D1
// DS1307 VCC --> 5v
// DS1307 GND --> GND

#include <Wire.h> // must be included here so that Arduino library object file references work
#include <RtcDS1307.h>
RtcDS1307<TwoWire> Rtc(Wire);
/* for normal hardware wire use above */
void setup ()
{
    Serial.begin(9600);
    Serial.print("compiled: ");
    Serial.print(__DATE__);
    Serial.println(__TIME__);
   
    Rtc.Begin();
    RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
    printDateTime(compiled);
    Serial.println();
    if (!Rtc.IsDateTimeValid())
    {
        Serial.println("RTC lost confidence in the DateTime!");
        Rtc.SetDateTime(compiled);
    }
    if (!Rtc.GetIsRunning())
    {
        Serial.println("RTC was not actively running, starting now");
        Rtc.SetIsRunning(true);
    }
    RtcDateTime now = Rtc.GetDateTime();
    if (now < compiled)
    {
        Serial.println("RTC is older than compile time!  (Updating DateTime)");
        Rtc.SetDateTime(compiled);
    }
    else if (now > compiled)
    {
        Serial.println("RTC is newer than compile time. (this is expected)");
    }
    else if (now == compiled)
    {
        Serial.println("RTC is the same as compile time! (not expected but all is fine)");
    }
    Rtc.SetSquareWavePin(DS1307SquareWaveOut_Low);
}
void loop ()
{
    if (!Rtc.IsDateTimeValid())
    {
        Serial.println("RTC lost confidence in the DateTime!");
    }
    RtcDateTime now = Rtc.GetDateTime();
    printDateTime(now);
    Serial.println();
    delay(1000);
}
#define countof(a) (sizeof(a) / sizeof(a[0]))
void printDateTime(const RtcDateTime& dt)
{
    Serial.print(dt.Day());
    Serial.print("/");
    Serial.print(dt.Month());
    Serial.print("/");
    Serial.println(dt.Year());
    Serial.print(dt.Hour());
    Serial.print(":");
    Serial.print(dt.Minute());
    Serial.print(":");
    Serial.println(dt.Second());
}
maka hasilnya akan seperti pada gambar berikut.


Sekian & terimakasih, Semoga bermanfaat..😁😁
Latest

1 komentar:

port sda dan scl bisa dipindah di port lain nggk?
misal scl ke pin d3 dan sda ke pin d4