Welcome to Solarduino , A blog about DIY Solar PV and Arduino projects

How to use Datalogger Shield?

Datalogger Shield is an extension board that consists of 3 major elements : the SD Card Module, Real Time Clock (RTC) module and the prototype board. The SD Card and RTC modules are very important in data logging while the prototype board can be used to wire sensor terminals or any wiring modification. 

 

Arduino UNO (compatible board)

If you still not yet own an Arduino Micro-controller Board, you can get it cheap at our affiliate link here !!!

Datalogger Shield

If you plan to record the data in a proper way, you may consider this Datalogger Shield. It allows your arduino to record your data in SD Card. Datalogger shield is often installed together with LCD Display shield. Please find it at our affiliate link here !!! 

The datalogger shield can be used right after stacked on top of the Arduino Uno board. You do not need to do any other wiring connection unlike if you get SD Card module and RTC module separately.

Normally this datalogger shield is widely used together with the LCD Display Shield. The LCD display shield provides the display screen to show the instantaneous value while datalogger shield recording the data. The datalogger shield is stacked in between LCD display shield and arduino board will look something like this:

 

I recommend you to add a 16X2 LCD Display Shield which can be directly fit on to the top of the Arduino board and datalogger shield without the need of extra wiring for the LCD Display. Without the LCD Display, you can only monitor the measured current value on PC via Serial Monitor. You can get the LCD Display board at our affiliate link here !!!. 

Before going further,  let me briefly explain about Arduino Common Communication Peripherals. Devices and sensors can be communicate with Arduino micro controller board by 3 common types of communication protocols: UART, I2C, and SPI.

1) UART

UART stands for Universal Asynchronous Reception and Transmission, is a simple communication protocol that allows the Arduino to communicate with serial devices. It communicate through Rx and Tx pins and with other computer via USB port.

2) I2C

I2C stands for inter-integrated-circuit, is a serial communications protocol specially designed for micro controllers communication. It is very popular among modules and sensors which could potentially connect up to 128 devices on the Arduino board. I2C makes it possible to connect multiple masters and slaves to your board using the exact same wires. The trade off for this simplified wiring is slower speeds than SPI.

3) SPI

SPI stands for Serial Peripheral Interface. It is similar to I2C which  the communication protocol is specially designed for communication between micro controllers. Unlike I2C, SPI allows a single master device with slave devices up to 4 units only. However, SPI is much faster than I2C due to simple protocol. SPI is commonly found in modules where speed is important such as SD cards and display modules, or sometimes sensors that requires fast information changes like temperature sensors.

Different model of Arduino board has different pin location of communication protocols. Above is an overview for the 3 communication protocols on Arduino UNO. You need to find out the pin location for other board if you are using different Arduino board (such as Arduino Mega).

 

Real Time Clock Module

Let’s begin with this part of the shield, the RTC. It uses I2C communication with arduino board. In order to communicate with I2C, pin SDA and SCL of the arduino board is needed. I2C communication pins for Arduino UNO are the Analog Pin A4 (SDA) and A5 (SCL). These 2 pins are automatically occupied for RTC setting and you may not use these 2 Analog Pins for any other sensors whenever you use this Data logger Shield.

RTC module needs 2 libraries. The first library that is required for RTC is <wire.h> library. It allows your board to communicate with I2C devices. This library is automatically installed when you install the Arduino IDE software. So you just need to activate this library in the code. The second library is “RTClib.h” which is not installed with your Arduino IDE software. This library enables you to make settings and command codes related RTC. You need to install the RTClib.h library by clicking the tools > manage libraries …

In the search area, key in for “RTClib” and look for RTClib by Adafruit. Install the library and you can activate the library by including the codes in your program.

This shield is using DS1307 microchip. In my code as attached below, you can see the RTC is defined as “RTC DS1307 RTC;”. There is also similar shield which is using PCF8523 chip where you may need to change to re-define code to “RTC PCF8523 RTC;”. If you plan to get RTC module with different chip number, you have to check whether the RTClib.h can support your chip model. Go to File > Example > (scroll down) RTClib > you can see the chip number that is supported. Open the examples and look for line code that is similar to my line RTC DS1307 RTC;” and replace the code. Make sure the last word “RTC” change all to big capital letters.

RTC Module DS3231

This is one of the reliable and low cost RTC module for arduino. You can get it from our affiliate link here !!!

SD Card Module

SD Card module or SD Card part that in the shield is using SPI protocol to communicate with Arduino board. In order to communicate using SPI, pin MOSI, MISO, SCK and SS/CS in the arduino board  are needed. SPI communication pins for Arduino UNO are the Digital Pin 11 (MOSI), Pin 12 (MISO), Pin 13 (SCK), and Pin 10 (SS/CS). Besides the Analog pin A4 and A5, these 4 Digital pins are also automatically occupied for SD Card communication and you may not use these Pins for any other sensors whenever you use this Data logger Shield.

SD Card module needs 2 libraries. The first library that required is  library. It allows your board to communicate with SPI devices. This library is automatically installed when you install the Arduino IDE software. So you just need to activate this library in the code. The second library is <SD.h> which is also already pre-installed with your Arduino IDE software. This library enables you to make settings and command codes related SD Card. Just include the libraries to the code to activate the function codes.

SD Card Module

Sometimes you might just want to get a separate module rather than a shield? you can find it at our affiliate link here !!! 

Dupont Line wire

In order to connect wiring between Arduino board and module, you need the dupont line cables male to female. You can get it at our affiliate link here !!!

Example Code 

Let’s take an example from my previous post : how to measure DC Voltage with Arduino? We are planning to upgrade this simple code (code that without display module) to add recording function using this Data Logger Shield. The wiring is still the same as stated in the post but instead of doing wiring on Arduino borad, this time doing wiring on Data Logger Shield as the shield will be stacked on top of Arduino UNO pins. 

DC Voltage Measurement Hardware Connection

Software Codes

The final step would be adding source code onto Arduino board. I assume you have installed the Arduino Software. If you still have not installed the software, the link here can bring you to the official download site. Once you have downloaded the software, you may download the code file (.ino) for this application below (right click save link). 

Before upload the source code to Arduino board, make sure you checked all the items in the checklist below:

1) Make sure you are using an Arduino UNO not other Arduino board as this shield is specially design only to fit Arduino UNO communication pins. 

2) Make sure you have already install the RTClib.h from Adafruit as explained earlier.

3) Slot in the SD Card in the Data Logger Shield. Make sure to clear some memories inside and the SD Card is readable by your PC or laptop.

Codes for DC Voltmeter with Datalogger Shield. Note: the codes shown here may not be 100% correct due to translation error. For accurate code, kindly download the .ino file. 

// DC Voltage Module with Datalogger Shield By Solarduino

// 1 - DC Voltage Measurement

int analogInputPin = A2;
float vArduino = 0.0;
float vActual = 0.0;
float R1 = 30000.0;
float R2 = 7500.0;
int rawValueRead= 0;

// 2 - Data Logger shield

#include&lt;Wire.h&gt;
#include "RTClib.h" // Must download the library from manage library &gt; type RTCLib by Adafruit
#include&lt;SPI.h&gt;
#include&lt;SD.h&gt;

RTC_DS1307 RTC;
DateTime now;

int chipSelect = 10;

File mySensorData;
unsigned long startMillisSD;
unsigned long currentMillisSD;
const unsigned long periodSD = 5000;

void setup()
{

// 1 - DC Voltage Measurement

pinMode(analogInputPin, INPUT);
Serial.begin(9600);
Serial.println("DC VOLTMETER");

// 2 - Data Logger shield

pinMode(chipSelect,OUTPUT);
RTC.begin();
Wire.begin();
SD.begin(chipSelect);
startMillisSD = millis();
RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
if(! RTC.isrunning())
{
Serial.println("RTC is not running !");
}

}

void loop()

{
// 1 - DC Voltage Measurement

rawValueRead = analogRead(analogInputPin);
vArduino = (rawValueRead * 5.0) / 1024.0;
vActual = vArduino / (R2/(R1+R2));

Serial.print("Vdc = ");
Serial.println(vActual,2);
delay(1000);

// 2 - Data Logger shield

currentMillisSD = millis();
if (currentMillisSD - startMillisSD &gt;= periodSD)
{
mySensorData=SD.open("SOLARD.txt",FILE_WRITE);
if(mySensorData)
{
DateTime now = RTC.now();
mySensorData.print(now.year(),DEC);
mySensorData.print("/");
mySensorData.print(now.month(),DEC);
mySensorData.print("/");
mySensorData.print(now.day(),DEC);
mySensorData.print(" ");
mySensorData.print(now.hour(),DEC);
mySensorData.print(":");
mySensorData.print(now.minute(),DEC);
mySensorData.print(":");
mySensorData.print(now.second(),DEC);
mySensorData.print(",");

mySensorData.println(vActual,2);

mySensorData.close();
Serial.println("written to SD Card !");
startMillisSD = currentMillisSD ;
}
}

}

Before we end, we would like to give gratitude to you for taking the time to read the post. We would need readers like you to support us in order to keep growing. You can support us in the following ways :

Donate & Fund Raising

If you like my work, please send me a donation to encourage me to do more. Thanks

Aliexpress Affiliate

We are the member of Aliexpress affiliate marketing. Do support us by clicking the affiliate product links if you do wish to purchase them.

Like and Share

If you like our post, we need your support to like and share our posts or videos so that it can reach more and more people like you !!

Result – In Serial Monitor

Result – In SD Card Files

Data Processing

Once you got the file SOLARD.txt created in the SD Card, open it from your PC using Microsoft EXCEL Software. If you can’t find the file in your EXCEL Software, search by all file types. The text import wizard will pop out as below. Click NEXT.

at the second step, make sure to choose Comma as a cell separator. So meaning to say if you want to separate each cell or category, just Serial print comma Serial.print(” , “)  in between values. Finally the values shown in the excel can be analysed. I use the Pivot Chart to create a time graph which shows the voltage value within the time frame which is more professional to present.

For Arduino Code Files, Remember to Right Click > Save Link As … The Code files will explain the function of all the codes. You may alter the internal code as you wish. Happy coding !! 

DC Voltage with Datalogger .ino