Arduino Tutorial 31# How to make 12 hour format clock (DS1302) with Arduino

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.พ. 2018
  • Arduino Tutorial 31# How to make 12 hour format clock (DS1302) with Arduino
    Scroll down for code.....
    Please like & Subscribe for more videos
    Real Time Clock (DS1302) library
    www.rinkydinkelectronics.com/l...
    LiquidCrystal_I2C library Github link
    github.com/fdebrabander/Ardui...
    I2C scanner to find out I2C address
    playground.arduino.cc/Main/I2c...
    If you want to support my video please buy any product through my amazon affiliate link. I will receive a commission, at no extra cost to you.
    LIST OF COMPONENT (affiliate links)
    amzn.to/2fvSRJq (Arduino)
    amzn.to/2gRFSiv (RTC DS1302)
    amzn.to/2yBk7eT (LCD display)
    amzn.to/2zg8aeX (I2C)
    amzn.to/2wxPmWz (Breadboard)
    amzn.to/2vJ3lvo (Jumper wire)
    #include (Wire.h)
    #include (LiquidCrystal_I2C.h) //instead of parenthesis () put angle bracket as TH-cam description does not allow angle bracket
    // Set the LCD address to 0x3F for a 16 chars and 2 line display // note: it may be different for your LCD please find it.
    LiquidCrystal_I2C lcd(0x3F, 16, 2);
    #include (DS1302.h)
    // Init the DS1302
    DS1302 rtc(2, 3, 4);
    // Init a Time-data structure
    Time t;
    void setup()
    {
    // Set the clock to run-mode, and disable the write protection
    rtc.halt(false);
    rtc.writeProtect(false);
    // The following lines can be commented out to use the values already stored in the DS1302
    rtc.setDOW(TUESDAY); // Set Day-of-Week to TUESDAY
    rtc.setTime(23, 59, 50); // Set the time to 24hr format it will automatically take time according to AM/PM
    rtc.setDate(06, 2, 2018); // Set the date to Febrauray 6th, 2018
    // initialize the LCD
    lcd.begin();
    }
    void loop()
    {
    // Get data from the DS1302
    t = rtc.getTime();
    lcd.setCursor(0, 0);
    if (t.date(=9){
    lcd.setCursor(0,0);
    lcd.print("0");
    lcd.setCursor(1,0);
    lcd.print(t.date, DEC);
    }
    else {
    lcd.print(t.date, DEC);}
    lcd.setCursor(3, 0);
    lcd.print(rtc.getMonthStr());
    lcd.setCursor(12,0);
    lcd.print(t.year, DEC);
    lcd.setCursor(4,1);
    {if (t.hour)=12){
    lcd.setCursor(13,1);
    lcd.print("PM");
    lcd.setCursor(4,1);
    t.hour = t.hour-12;
    if (t.hour== 0) {
    t.hour = 12; // Day 12 PM
    }
    if (t.hour(=9){
    lcd.setCursor(4,1);
    lcd.print("0");
    lcd.setCursor(5,1);
    lcd.print(t.hour, DEC);
    }
    else {
    lcd.print(t.hour, DEC);}}
    else { if(t.hour==0){
    t.hour=12; // Night 12 AM
    }
    lcd.setCursor(13,1);
    lcd.print("AM");
    lcd.setCursor(4,1);
    if (t.hour(=9){
    lcd.setCursor(4,1);
    lcd.print("0");
    lcd.setCursor(5,1);
    lcd.print(t.hour, DEC);
    }
    else {
    lcd.print(t.hour, DEC);}} }
    lcd.setCursor(6,1);
    lcd.print(":");
    lcd.setCursor(7,1);
    if (t.min(=9){
    lcd.setCursor(7,1);
    lcd.print("0");
    lcd.setCursor(8,1);
    lcd.print(t.min, DEC);
    }
    else {
    lcd.print(t.min, DEC);}
    lcd.setCursor(9,1);
    lcd.print(":");
    lcd.setCursor(10,1);
    if (t.sec(=9){
    lcd.setCursor(10,1);
    lcd.print("0");
    lcd.setCursor(11,1);
    lcd.print(t.sec, DEC);
    }
    else {
    lcd.print(t.sec, DEC);}
    delay (1000);
    lcd.clear();
    }

ความคิดเห็น • 37

  • @JJ10880011
    @JJ10880011 2 ปีที่แล้ว

    Thank you so much for your information. Your information is really through and I was able to complete to set up 12 format clock using DS1302 and 1602a LCD. As you comment I've changed lcd(0x3F) to (0x27) and worked safisfacorily. The only problem I found was that time counts form 6:30 pm after unpluged power supply though I put a battery to DS1302. However this is very minor problem so I don't care. Thanks again.

  • @eddiejones8709
    @eddiejones8709 2 ปีที่แล้ว

    Thank you for providing an excellent video. I'm not using a1302 but with your information I am going to see if I can take what you have provided and apply that to my 3231.

  • @wowo1081
    @wowo1081 2 ปีที่แล้ว

    Good working code. I modified the end of the Loop function a bit, commented out delay (1000); which could be cause seconds to skip and lcd.clear(); to eliminate flickering of the screen.

  • @StudentBuilds
    @StudentBuilds 6 ปีที่แล้ว +2

    nice vids, keep them up!

  • @Scanito
    @Scanito 4 ปีที่แล้ว +1

    Quite clear and easy to understand. Thanks Sir!

  • @maresdaniel2768
    @maresdaniel2768 5 ปีที่แล้ว

    Hey, can you help me modify the code to work whit the ds1307 RTC , and seting the hour /min/sec whit push buttons please?

  • @vijayjadhav4488
    @vijayjadhav4488 3 ปีที่แล้ว +1

    Very nice clock

  • @milanjpatel1201
    @milanjpatel1201 4 ปีที่แล้ว

    Do you have code for atmel studio 7 in assembler language

  • @edebiyat_arastirmacisi
    @edebiyat_arastirmacisi 3 ปีที่แล้ว

    Hocam selamlar.

  • @jenntek.101

    7 segment display TM1637 would be fun for just time... not the date...

  • @ranjeetminhas9051
    @ranjeetminhas9051 4 ปีที่แล้ว

    i am using the code given by u but my arduino software is giving errors. so tell me the right code or software version

  • @qboyqboy

    hi, i try this codes, maybe something wrong or my side, please help: if (t.min(=9){

  • @geoffairbourniawbor2873
    @geoffairbourniawbor2873 5 ปีที่แล้ว +1

    How to write the code without using LCD?

  • @ianacoustic6685
    @ianacoustic6685 ปีที่แล้ว +1

    hello sir can i request?please create a tutorial about how to set time and date using the buttons please help me im a student thankyouu i using ds3231 rtc

  • @pareshpanchal52
    @pareshpanchal52 5 ปีที่แล้ว +1

    can you add a little beep on completion of each hour. say hourly signal or sound.

  • @mahedihassan7611
    @mahedihassan7611 3 ปีที่แล้ว

    Vai how do i do it with ds 3231 rtc

  • @RainbowPlayzo
    @RainbowPlayzo 2 ปีที่แล้ว

    When i upload the code the lcd still shows nothing

  • @harpreetsinghbhinder9
    @harpreetsinghbhinder9 3 ปีที่แล้ว

    no matching function for call to 'LiquidCrystal_I2C::begin()'

  • @pritambakshi6936
    @pritambakshi6936 4 ปีที่แล้ว +1

    I can use any RTC Module , (Yes or No) *Particular This Project.

  • @manindersingh4834
    @manindersingh4834 4 ปีที่แล้ว

    Hello can you make 20 time alarm clock with arduino