Toll-Free Customer Support 24/7

Data Logger Sheild Compatible for Arduino

/*
* Project name:
Data Logger Sheild Compatible for Arduino
* Copyright
(c) Researchdesignlab.com
* Description:

* Test configuration:
MCU: ATMEGA328
Dev.Board: Arduino uno
Oscillator: 16 MHz
Software: Arduino

*/

/*
WHEN THE XBEE RECIVE THE DATA
'S' = DATA LOGGER START STORING DATA TO SD CARD
'P' = PAUSE THE STORING DATA TO SD CARD
'R' = READ THE DATA FROM THE SD CARD AND TRANSIMIT THROUGH XBEE
*/

#include <Wire.h>
#include "RTClib.h"
#include <SD.h>

RTC_DS1307 RTC;
File myFile;


int Serial_value = 0; // value read from the xbee
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to

int sensorValue = 0;
int START_STORE = 0;

void setup()
{
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.println(" Wireless Xbee Data Logger Sheild ");
Wire.begin();
RTC.begin();
RTC.adjust(DateTime("Jun 20 2014","17:11:45")); //INIT of Time and Date


pinMode(10, OUTPUT);

if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
myFile = SD.open("RDL.txt", FILE_WRITE); //creating open RDL.text file

}

void loop()
{

if (Serial.available()) //check If data is received form xbee
{
Serial_value=Serial.read(); // read the received data form xbee
if(Serial_value=='S'){ //Xbee value is equal to 'S'
myFile = SD.open("RDL.txt", FILE_WRITE);
if (myFile) { //Enable data logger to store data in SD card
START_STORE=1;
Serial.println("Enable data logger to store data ");
}
else
Serial.println("Error opening RDL.txt");
}

else if(Serial_value=='P'){ //Xbee value is equal to 'P'
START_STORE=0; //Disable data logger to store data in SD card
myFile.close();
Serial.println("Disable data logger to store data ");
}
else if(Serial_value=='R'){ //Xbee value is equal to 'F'

Serial.println("Read store data of data logger");
delay(1000);
myFile = SD.open("RDL.txt");
if (myFile) {
Serial.println("RDL.txt : ");

// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}

myFile.close();
}
else {
// if the file didn't open, print an error:
Serial.println("Error opening RDL.txt");
}

}

}




if(START_STORE==1)
{
DateTime now = RTC.now();


myFile.print("DATE : ");
myFile.print(now.year(), DEC);
myFile.print('/');
myFile.print(now.month(), DEC);
myFile.print('/');
myFile.print(now.day(), DEC);
myFile.print(' ');
myFile.print(" TIME : ");
myFile.print(now.hour(), DEC);
myFile.print(':');
myFile.print(now.minute(), DEC);
myFile.print(':');
myFile.print(now.second(), DEC);
sensorValue = analogRead(analogInPin);
myFile.print(" AN0 = " );
myFile.print(sensorValue);
myFile.println();
delay(1000);

}







}

Back to top