Writing to and Reading from an SD card for a Data Logger


I’m new to Arduino and have probably picked a more difficult project than I should have, but it’s too late to turn back now unfortunately.

I am trying to create a data logger capable of reading multiple sensors, recording readings to an SD card, reading from the SD card and sending the data over SMS to a phone.

So far I have managed to record readings and save the data to the SD card as a .csv file and I have managed to send character texts to my phone in a seperate code.

I would like to know how to get that data back from the SD and be able to insert it in to an SMS.

I am using an Uno, an Arduino GSM shield, a Deek Robot SD shield and just one DHT11 sensor for now.

I have included my code (which has been reduced down due to lack of SRAM on the Arduino Uno) any help, improvements or tips will be appreciated.

#include <Wire.h>
#include <SD.h>
#include <dht.h>
#include <GSM.h>

#define I2CDS1307Add 0x68
#define SD_CS_DIO 10
#define DHT11_PIN 8
#define PINNUMBER ""

File DataFile;
GSM gsmAccess;
GSM_SMS sms;

dht DHT;

void setup() {
  pinMode(SD_CS_DIO, OUTPUT);

  int chk = DHT.read11(DHT11_PIN);  
  Serial.print("Temp = ");
  Serial.print("Hum = ");
  DataFile = SD.open("data2.csv", FILE_WRITE);
  if (DataFile) 
    DataFile.print(", ");
    DataFile.print(", ");

void loop() {


it is tough to read a file open for output.

Open a new file for output,
write records to it,
close it (the file) when you are done,,,,
open it (the file) for input,
read records from it,
close it when you are done and optionally, delete it.

or send the records to GSM as you write them to the file on SD.

The dumpfile example in the SD section of the IDE should have all you need. You don't read from the file, you just send the file whole.

Sorry I got busy then. Thanks for the answers. I'll have a look at it again when I get the chance.