реклама:

DS1307 clock module. Part 8.

DS1307 clock module

I do not understand why such a powerful processor as Atmega2560, which is the heart of our board Arduino, does not have built-in clock. For correct operation of the controller, we need to know the date and time. This is exactly what can be done with an external clock module. Connecting of this module is much easier - only 4 wires. On the board (pcb) of DS1307 you will find four pins: SCL, SDA, VCC and GND.

Here is a table of conformity between module DS1307 and Arduino:

DS1307 pinsArduino pins
SCL21
SDA20
VCC5V
GNDGND

Wiring diagram:

DS1307 clock module

Real connection. You may see how one contact GND is on top of other GND :)

DS1307 clock module DS1307 clock module

Click to zoom

Moreover, 5V and GND can be taken from there, where you took them to the LCD display, and can be connected as shown in the figure. Given that we already have connected the display and clock module, you can download to your arduino example below. After loading the display should light up and show the current date and time.

Skecth example:

// include the library code:
#include <LiquidCrystal.h>
#include <Wire.h>
#include "RTClib.h"

// LCD   
#define PWM_LED_PIN 3 
// LCD  
#define PIN_LCD_RS 39
#define PIN_LCD_EN 41
#define PIN_LCD_D4 43
#define PIN_LCD_D5 45
#define PIN_LCD_D6 47
#define PIN_LCD_D7 49

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd( PIN_LCD_RS, PIN_LCD_EN, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7 );
RTC_DS1307 RTC;

void setup() {   
  analogWrite( PWM_LED_PIN, 255 );
  
  lcd.begin(16, 2); 
  lcd.print("House4u sol.proj");
  lcd.setCursor(0, 1); 
  
   Wire.begin();
   RTC.begin();
   
   RTC.adjust(DateTime(__DATE__, __TIME__));
}

void loop() 
{   
    lcd.setCursor(0, 1);
    DateTime now = RTC.now();
    lcd.print(now.year(), DEC);
    lcd.print('/');
    lcd.print(now.month(), DEC);
    lcd.print('/');
    lcd.print(now.day(), DEC);
    lcd.print(' ');
    lcd.print(now.hour(), DEC);
    lcd.print(':');
    lcd.print(now.minute(), DEC);
    lcd.print(':');
    lcd.print(now.second(), DEC);
    lcd.print(" ");

    delay( 1000 ); 
}

The result of the example:

DS1307 is working

If you have a small screen 16x02, then seconds may not completely fit into the screen.

If you received a similar result - hurray! Can move on...


<< BackNext >>


Share with friends:

Donate