I am trying to use the SD card (Sandisk 8GB) for my code. I am using Arduino Mega.
The problem is for the first two times the loop is executed and the text file is written in SD card. But it stops abruptly after that and it shows SD card initialization failure.
; // wait for serial port to connect. Needed for native USB port only
Serial.println(“PP SD card is ready to use.”);
Serial.println(“FF SD card initialization failed”);
char fileName; // SDcard uses 8.3 names so 16 bytes is enough NOte room for the ‘\0’ char is needed!
unsigned int nr = 1;
while (nr != 0)
sprintf(fileName, “file_%03d.txt”, nr);
if (SD.exists(fileName) == false)
Serial.println( " created.");
myFile = SD.open(fileName, FILE_WRITE);
myFile.println(“testing 1, 2, 3.”);
Serial.print(“SD card done”);
What may be the problem?. Can somebody help me.
Thanks in advance.