I am sorry that this topic may be discussed a million times already, but i cant still make mine working. so please bear with me.i have attached my code in the attachment. A pretty long one. Basically i want to "real time logging temperature and voltage in a room" for a week. I am currently using kingston SD card (4GB, FAT32). I have done an overnight run with the arduino and the data logger. The program actually still works but the logger has stopped working after 2 hours. Having done some searching on Google reveals the problem may due to memory leakage. Is there any way that i could done to solve this? Please kindly advise. Thank you very much guys!

Thank you for the advice! But i have another issue when using the SdFat library. I tested the library with the ReadWriteSdFat example. In the Serial Com, it showed "Writing to test.txt...done.", "error: opening test.txt for read failed", "SD errorCode: 0x13,0x0". When i used another SD card, same error pops up with a different error code as 0x6,0x1. Does anyone know what is the meaning about this?

Thank you for your help and replies, Marco_C! I have used Sdfat.lib while the card can now be used. However, this time when i run the program for like 24 hours with a 5 second time interval between logging, the card has stopped after 14 hours of operations, recording about 28281 data. Is this happening still related to memory leak? Or my program is too long and there isn't any memory left for the data logging stuff? Thank you guys in advice!

None of your code for reading from the serial port is worth anything. You test that there is at least one byte to read, and then proceed to read as much as you want, assuming that the stupid delay() call will somehow make serial data appear in time.

There are plenty of resources about for reading serial data properly (always test there there is data, stopping when the end of a packet arrives, etc.). You need to find them, and fix your code.

I don't understand the memory leakage problem. If you feed the stuff direct to the SD, I can't see where there could be a memory problem. Here is what I have been using of late and it has been working continuously for days. The daily output is about 400k. Some of it is abit messy but the SD stuff might be useful.

I am sorry for the late reply. I have been troubleshooting the SD shield lately and it has continued to work for a week. I am no programming or Arduino expert. But here is what i have done in the code to solve it. I hope it helps even if it may not make sense.