Interfacing Real Time Clock to Arduino Mega Sensor Shield

It’s time to fire up the Real Time Clock and the DS18B20 digital temperature sensor with the Arduino Mega. Remember that there is also a DS18B20 sensor on the RTC module, hence, this tutorial shows you how to interface two temperature sensors and a RTC with the Arduino Mega. The Mega Sensor shield reduces lots of pain while connecting the parts together, so it's highly recommended. Firstly of all, use the jumper wires to connect the circuit shown below (click to enlarge).


Arduino Mega Sensor Shield

RTC Module

DS18B20 Sensor

GND

GND

 

Signal 18

VCC

 

Signal 17

DS

 

Signal 20

SDA

 

Signal 21

SCL

 

GND

 

GND (black)

Signal 7

 

Signal (white)

Signal 6

 

VCC (red)

 

 

4.7k pull-up resistor between Signal and VCC



The external DS18B20 sensor requires a 4.7K pull-up resistor connecting between its VCC and Signal lines.

Now, download this RTClib, unzip it and put it to the Arduino libriary directory (C:\arduino-1.0.5\libraries). Restarting the Arduino IDE is required for the libriary to be installed properly. We are going to test the RTC and the Temperature sensor separately, this way it's easier to diagnose if there is any hardware problems.


RTC Testing

In Arduino IDE, navigate to File -> Examples -> RTClib -> setTimeAndPointToSerial

RTC example code

Download the example code to the Arduino (make sure the correct board and Serial COM are selected), and open Serial Monitor, and set the Baudrate to be 57600, if the RTC module is working, you should see someting like this. You may need to press the Reset button for the text to come out.

RTC Serial Results


Temperature Sensor Testing

There are two temperature sensors in the circuit, we call the one with a long wire and a steel cap as External sensor, and the one on the RTC module as Internal sensor.

Download the OneWireLibrary and install it into the arduino IDE libraries folder and then load this code to Arduino Mega, and open Serial Monitor on Baudrate 57600. You should see the temperature reading like this. Again, you may need to press the Reset button for the text to come out.


Temp Reading Serial


If that's what you see, great, you have got the circuit working!

Zircon - This is a contributing Drupal Theme
WeebPal