Problem using SD card reader on arduino MEGA 2560 shield

I am using a Arduino Mega with Data logging Shield V1.0 which works most of the time. Using it with a Arduino Uno I get the message "Global variables use 1654 bytes (80%) of dynamic memory, leaving 394 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur." and it fails to read the SD card. Loading the standard sketches for reading the SD card everything works. I get the impression the problem lies with the limited memory of the UNO. How does on solve the problem?

Need to determine what is wasting your RAM (dynamic memory).
Select all your sketches in the IDE, right click and select [Copy for Forum] and post it here!

We'd need to see your code.
Have you made sure that you're using the minimum necessary data types? There's just a million questions that can't be guessed at.
Please autoformat it in the IDE, then post your code using the code tags: </>

The SD library needs to allocate 512 bytes of ram for a buffer, so you are going to need to free up some memory on the UNO.

I do not know how to post my code using the code tags:
Can you please explain in detail? Thanks

Certainly, please check out this article:
How to get the best out of this forum - Using Arduino / Programming Questions - Arduino Forum

The purpose of the sketch is to read 5 temperatures and two on/off signals, then write the data to the screen and SD files. Running a simple card reader sketch does recognize the SD card.
The main problem is that the SD card is often not recognized. Another problem is that the RTC clock is 10 minutes behind the correct time. The last problem is that Strings does not work. I guess all the problem are memory related. Hope you can help.

[code]
/*
21-09-04: Dit werk nou reg en kan gebruik word met Mega.
21-09-01: Werk met Com 10 en onthou draadjies van SDA/SCL
21-08-29 Stel tyd reg by pomp aan/af, dit werk nou reg en ook vir pomp
21-8-28:timeStr werk Open en Close kodes uitgahaal, Skryf nie pomp aan na sd.
Plaas alle Open en Close kodes weer terug. Dit lyk of alles nou werk
Tyd wat pomp aankom is nie reg, tyd moet bepaal word net voordat dit geskryf word.
21-08-23: Afgelaai by Arduino Data logging shield V1.0 - YouTube
*/
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"

String progNaam = "GeiserMonitorMegaW7";
float minInterval = 10; // Stel aantal minute tussen lesings
//float minInterval = .2;

const int chipSelect = 10; //cs or the save select pin from the sd shield is connected to 10.

RTC_DS1307 RTC;
int tempRegstelling = -15;
int ThermistorPinGeiser = 2; // Geiser A2
int ThermistorPinSonP = 3; // Sonpaneel
int ThermistorPinWandG = 0; // Geiserwand
int ThermistorPinPlafon = 7; // Plafon
int ThermistorPinBuite = 1; // Buite

int VGo, VSo, VWo, VPo, VBo;
float R1 = 10000;
float logR2, R2, geiserT, sonpaneelT, wandT, plafonT, buiteT;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
int geiser2Aan;
int pomp2Aan;

//float temperatureAll = {0};
//-------------------------------------
const int geiserAan = 6; // geiser is gekoppel aan pen 9
const int pompAan = 7; // pomp is gekoppel aan pen 10
const int ledPin = 13; // the pin that the LED is attached to
int pompAanStatus = 0; // current state of the button
int geiserAanStatus = 0; // current state of the button
int lastButtonStateGeiser = 0; // previous state of the button
int lastButtonStatePomp = 0; // previous state of the button
int i = 0;
float tempT2;
//-------------------------------------

File dataFile;
DateTime now;

void setup(void) {
Serial.begin(9600);
//-------------------------------------
// initialize the button pin as a input:
// pinMode(geiserAan, INPUT);
pinMode(pompAan, INPUT);

//-------------------------------------
//setup clock

Wire.begin();
RTC.begin();
//check or the Real Time Clock is on
Serial.println(" ");
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
// uncomment it & upload to set the time, date and start run the RTC!
// RTC.adjust(DateTime(DATE, TIME));
}

//setup SD card
Serial.println("Initializing SD card...");

// see if the SD card is present and can be initialized:

// if (!SD.begin(chipSelect)) {
if (!SD.begin(10, 11, 12, 13)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}

Serial.println("card initialized.");

//---------------------
// Serial.print("Start logging on: ");
// Serial.println(now.year(),DEC);
//----------------------

now = RTC.now();
// Skryf opskrif na skerm
Serial.println("---------------------------------------");
Serial.print("Begin meet op: ");
// Serial.print(now.dayOfTheWeek(), DEC);
// Serial.print('-');
Serial.print(now.year(), DEC);
Serial.print('-');
Serial.print(now.month(), DEC);
Serial.print('-');
Serial.println(now.day(), DEC);
Serial.print("Progam naam = "); Serial.println(progNaam);
Serial.print("Lees temperature elke "); Serial.print(minInterval); Serial.println(" minute.");
Serial.println(" Temperature");
Serial.println("Tyd Gei Son Wand Plaf Buite Gaan Paan");
Serial.println("-------------------------------------------------");

// Skryf opskrif na SD kaart

dataFile = SD.open("datalog.csv", FILE_WRITE);
dataFile.print("Begin meet op: ");
dataFile.print(now.year(), DEC);
dataFile.print('-');
dataFile.print(now.month(), DEC);
dataFile.print('-');
dataFile.print(now.day(), DEC);
dataFile.println(" ");
dataFile.print("Progam naam = "); dataFile.println(progNaam);
dataFile.print("Lees temperature elke "); dataFile.print(minInterval); dataFile.println(" minute.");
dataFile.println(" --------------Temperature--------------");
dataFile.print("Tyd"); dataFile.print(",");
dataFile.print("Geiser"); dataFile.print(",");
dataFile.print("Sonpaneel"); dataFile.print(",");
dataFile.print("Wand"); dataFile.print(",");
dataFile.print("Plafon"); dataFile.print(",");
dataFile.print("Buite"); dataFile.print(",");
dataFile.print("Geiser aan"); dataFile.print(",");
dataFile.println("Pomp aan");
dataFile.close();

} // -------------- Einde void setup

void loop(void) { // -----------Begin herhaling
// ---------------- geiser temperatuur bereken

// geiserT = geiserT - 273.15 + 28.4; // Aangepas

VGo = analogRead(ThermistorPinGeiser); // van W6
R2 = R1 * (1023.0 / (float)VGo - 1.0);
logR2 = log(R2);
geiserT = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
geiserT = geiserT - 273.15 - 16 + 26; // Aangepas

// ---------------- sonpaneel temperatuur bereken
VSo = analogRead(ThermistorPinSonP);
R2 = R1 * (1023.0 / (float)VSo - 1.0);
logR2 = log(R2);
sonpaneelT = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
// sonpaneelT = sonpaneelT - 273.15 + 28.4;
sonpaneelT = sonpaneelT - 273.15 - 16 + 26;
// ---------------- geiser wand temperatuur bereken

VWo = analogRead(ThermistorPinWandG);
R2 = R1 * (1023.0 / (float)VWo - 1.0);
logR2 = log(R2);
wandT = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
// wandT = wandT - 273.15 - 15;
wandT = wandT - 273.15 - 18;
// ---------------- plafon temperatuur bereken

VPo = analogRead(ThermistorPinPlafon); // van W6
R2 = R1 * (1023.0 / (float)VPo - 1.0);
logR2 = log(R2);
plafonT = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
plafonT = plafonT - 273.15 - 18;
// ---------------- buite temperatuur bereken

VBo = analogRead(ThermistorPinBuite);
R2 = R1 * (1023.0 / (float)VBo - 1.0);
logR2 = log(R2);
buiteT = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));
// buiteT = buiteT - 273.15 - 16;
buiteT = buiteT - 273.15 - 18;
// buiteT = 0.115*VBo - 53 - 12;

// ----------------- temperature klaar bereken

String tempStr, timeStr;
String dataString = "";

now = RTC.now(); //read the time
timeStr = "";
// if the file is available, write to it:
// log the temperature and time.

timeStr = String(now.hour(), DEC);
timeStr += ":";
timeStr += String(now.minute(), DEC);
timeStr += ":";
timeStr += String(now.second(), DEC);
tempStr = timeStr + ",";
tempStr += String(geiserT, 1) + "," + String(sonpaneelT, 1) + ",";
tempStr += String(wandT, 1) + "," + String(plafonT, 1) + ",";
tempStr += String(buiteT, 1) + ",";
tempStr += String(geiser2Aan) + "," + String(pomp2Aan);
// Skryf temperature na skerm en SD kaart
Serial.print(timeStr); Serial.print(" ");
Serial.print(geiserT, 1); Serial.print(" ");
Serial.print(sonpaneelT, 1); Serial.print(" ");
Serial.print(wandT, 1); Serial.print(" ");
Serial.print(plafonT, 1); Serial.print(" ");
Serial.print(buiteT, 1); Serial.print(" ");
Serial.print(geiser2Aan); Serial.print(" ");
Serial.println(pomp2Aan);
// Serial.println(tempStr);

dataFile = SD.open("datalog.csv", FILE_WRITE);
dataFile.println(tempStr);
dataFile.close();

//------------------------------------ begin vertraging

while (i < 60 * minInterval) { // Begin vertraging
delay(1000);
// i++; // Einde van vertraging skuif na einde van pomp aan ens.

//  ------------------------------ Lees of Geiser Aan/Af geskakel het

timeStr = "";
now = RTC.now();    //read the time
timeStr = String(now.hour(), DEC); timeStr += ":";
timeStr += String(now.minute(), DEC); timeStr += ":";
timeStr += String(now.second(), DEC);

// read the pushbutton input pin vir Geiser
geiserAanStatus = digitalRead(geiserAan);
// compare the buttonState to its previous state

if (geiserAanStatus != lastButtonStateGeiser) {
  // if the state has changed,
  if (geiserAanStatus  == HIGH) {
    // if the current state is HIGH then the button went from off to on:
    geiser2Aan = 9;
    tempStr = timeStr + ",";
    tempStr += String(geiserT, 1) + "," + String(sonpaneelT, 1) + ",";
    tempStr += String(wandT, 1) + "," + String(plafonT, 1) + ",";
    tempStr += String(buiteT, 1) + ",";
    tempStr += String(geiser2Aan) + "," + String(pomp2Aan);
    // Skryf temperature na SD kaart
    //      Serial.print(tempStr);




    Serial.print(timeStr); Serial.print("  ");
    Serial.print(geiserT, 1); Serial.print("  ");
    Serial.print(sonpaneelT, 1); Serial.print("  ");
    Serial.print(wandT, 1); Serial.print("  ");
    Serial.print(plafonT, 1); Serial.print("  ");
    Serial.print(buiteT, 1); Serial.print("  ");
    Serial.print(geiser2Aan); Serial.print("  ");
    Serial.print(pomp2Aan);


    Serial.println("    Geiser aan");
    dataFile = SD.open("datalog.csv", FILE_WRITE);
    dataFile.print(tempStr);
    dataFile.print(",");
    dataFile.println("    Geiser aan");
    dataFile.close();

  } else {
    // if the current state is LOW then the button went from on to off:

    geiser2Aan = 0;
    //      tempStr = timeStr + ",";
    //      tempStr += String(geiserT,1) + "," + String(sonpaneelT,1) + ",";
    //      tempStr += String(wandT,1) + "," + String(buiteT,1) + ",";
    //      tempStr += String(geiser2Aan) + "," + String(pomp2Aan);

    tempStr = timeStr + ",";
    tempStr += String(geiserT, 1) + "," + String(sonpaneelT, 1) + ",";
    tempStr += String(wandT, 1) + "," + String(plafonT, 1) + ",";
    tempStr += String(buiteT, 1) + ",";
    tempStr += String(geiser2Aan) + "," + String(pomp2Aan);

    // Skryf temperature na SD kaart
    //      Serial.print(tempStr);
    Serial.print(timeStr); Serial.print("  ");
    Serial.print(geiserT, 1); Serial.print("  ");
    Serial.print(sonpaneelT, 1); Serial.print("  ");
    Serial.print(wandT, 1); Serial.print("  ");
    Serial.print(plafonT, 1); Serial.print("  ");
    Serial.print(buiteT, 1); Serial.print("  ");
    Serial.print(geiser2Aan); Serial.print("  ");
    Serial.print(pomp2Aan);


    Serial.println("    Geiser af");
    dataFile = SD.open("datalog.csv", FILE_WRITE);
    dataFile.print(tempStr); dataFile.print(",");
    dataFile.println("    Geiser af");
    dataFile.close();
  }                      // Einde if (geiserAanStatus == LOW) {
  lastButtonStateGeiser = geiserAanStatus;     // hier is die probleem

}    // Einde  if (geiserAanStatus != lastButtonStateGeiser)

//-------------------------------------- Lees of pomp Aan/Af geskakel het

pompAanStatus = digitalRead(pompAan);
if (pompAanStatus != lastButtonStatePomp) {  // Toets of iets verander het
  if (pompAanStatus == HIGH) {
    // if the current state is HIGH then the button went from off to on:
    pomp2Aan = 5;
    //        tempStr = timeStr + ",";
    //        tempStr += String(geiserT,1) + "," + String(sonpaneelT,1) + ",";
    //        tempStr += String(wandT,1) + "," + String(buiteT,1) + ",";
    //        tempStr += String(geiser2Aan) + "," + String(pomp2Aan);

    tempStr = timeStr + ",";
    tempStr += String(geiserT, 1) + "," + String(sonpaneelT, 1) + ",";
    tempStr += String(wandT, 1) + "," + String(plafonT, 1) + ",";
    tempStr += String(buiteT, 1) + ",";
    tempStr += String(geiser2Aan) + "," + String(pomp2Aan);
    // Skryf temperature na SD kaart
    //        Serial.print(tempStr);


    Serial.print(timeStr); Serial.print("  ");
    Serial.print(geiserT, 1); Serial.print("  ");
    Serial.print(sonpaneelT, 1); Serial.print("  ");
    Serial.print(wandT, 1); Serial.print("  ");
    Serial.print(plafonT, 1); Serial.print("  ");
    Serial.print(buiteT, 1); Serial.print("  ");
    Serial.print(geiser2Aan); Serial.print("  ");
    Serial.print(pomp2Aan);

    Serial.println("   Pomp aan");

    //Serial.print(VGo);Serial.print("  ");Serial.println(VSo);
    //Serial.print(VWo);Serial.print("  ");Serial.print(VPo);
    //Serial.print("  ");Serial.println( VBo);

    dataFile = SD.open("datalog.csv", FILE_WRITE);
    dataFile.print(tempStr); dataFile.print(",");
    dataFile.println("    Pomp aan");
    dataFile.close();
  } else {          // Pomp is af
    // if the current state is LOW then the button went from on to off:
    pomp2Aan = 0;
    tempStr = timeStr + ",";
    tempStr += String(geiserT, 1) + "," + String(sonpaneelT, 1) + ",";
    tempStr += String(wandT, 1) + "," + String(plafonT, 1) + ",";
    tempStr += String(buiteT, 1) + ",";
    tempStr += String(geiser2Aan) + "," + String(pomp2Aan);
    // Skryf temperature na SD kaart
    //        Serial.print(tempStr);

    Serial.print(timeStr); Serial.print("  ");
    Serial.print(geiserT, 1); Serial.print("  ");
    Serial.print(sonpaneelT, 1); Serial.print("  ");
    Serial.print(wandT, 1); Serial.print("  ");
    Serial.print(plafonT, 1); Serial.print("  ");
    Serial.print(buiteT, 1); Serial.print("  ");
    Serial.print(geiser2Aan); Serial.print("  ");
    Serial.print(pomp2Aan);
    Serial.println("    Pomp af");
    dataFile = SD.open("datalog.csv", FILE_WRITE);
    dataFile.print(tempStr); dataFile.print(",");
    dataFile.println("    Pomp af");
    dataFile.close();
  }       // Einde if the current state is LOW
  lastButtonStatePomp = pompAanStatus;
}          // Einde  if (pompAanStatus == HIGH) {

//------------------------------------------ Einde pomp aan
i++;                                  // Einde van vertraging loop

}
i = 0;

dataFile.close();
//------------------------------------------ einde vertraging

} // Einde void loop(void)
[/code]Preformatted text