SD card connection with Arduino mega 2560

I have bought the following sd card however I cannot get my arduino program to recognise it after trying for around a week. My wiring and code are shown below. Can anyone see any obvious flaws?

My wiring is shield – arduino
gnd – gnd
3.3v – 3.3 v
5v – 5v
cs – 53
mosi – 51
sck – 52
miso – 50
gnd – gnd

#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 53;    

void setup()
 // Open serial communications and wait for port to open:
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  Serial.print("\nInitializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
  pinMode(53, OUTPUT);     // change this to 53 on a mega

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
  } else {
   Serial.println("Wiring is correct and a card is present."); 

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
    case SD_CARD_TYPE_SD2:

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  // list all files in the card with date and size | LS_DATE | LS_SIZE);

void loop(void) {

That SD card has no logic level converter. That could cause a problem.

Have you tried another pin for the chip select, like D4?

SurferTim: That SD card has no logic level converter. That could cause a problem.

Have you tried another pin for the chip select, like D4?

Yes I have also tried D4 with no success.

Find attached the picture of the board i am using, i believe it is the same as the lc studio version, and my wiring.

This module works with some SD cards but does not comply with the SD card standard.

It will cause your card to draw excess current since the Arduino tries to drive CS, MOSI, and SCK with 5V. The voltage on the pins will be limited by the current the Arduino pins can supply.

I have a lot of cards that I use for testing SdFat and many fail in this module.

This module is fine on 3.3V systems but only level shifters truly fix it for 5V systems.

Not surprising, you can get them two for $2.25 with shipping on ebay.

Thanks for the reply. It seems I have two options.

1) Try many SD cards and see if I can find one which works 2) Build a system which incorporates level shifters


1) Try many SD cards and see if I can find one which works 2) Build a system which incorporates level shifters

May I suggest option 2. It is cheaper and the correct way to do it.

Thanks, I will get to it and report back on how I get on.

The mega works off of different ports for spi than the uno. I whipped up a shield adapter using a proto board

I know have the level shifter installed however I am still unable to recognise the SD card.

The voltage readings I am getting at the Sd card module are

GND -- 0V 3.3 V -- 3.3V 5V -- 5V CS -- 0v rising to 1.8V and dropping to 0V very quickly MOSI -- 3.5 V SCK -- 1.8 V dropping to 1.6 V and returning to 1.8 V very quickly MISO -- 3.5 V GND -- 0V

With my limited knowledge of electronics I think these voltages look ok, the CS and SCK seems to be acting as counters.

Can anyone confirm if these voltages are correct?

If they are I guess that leaves the SD card as the problem.

Anyone able to help with this?

Where is the 3.3V from? The mega regulator may not have enough current capacity to support some SD cards.

The 3.3V and 5V are both coming from the Arduino, with the Arduino powered by a laptop via a usb.

Try a higher current capacity 3.3V source.

I happen to have the same SD card with euanmcc, which I bought from the following supplier

The suppplier suggests a connection circuit as per the attached image (I apologize, but this is my first post and I was not able to insert the image). He uses voltage dividers through resistors, which I understsand solves the problem of the voltage difference between Arduino and the SD card, and, what is most important, he leaves the 3.3 Volts not connected.
If you follow the link, you can find there the schematic, together with other useful documentation

I was wandering for three days, trying to find out how to connect the SD card - I am completely newbie - and then I saw this thread and the code of euanmcc (I really thank you for that - I had a big problem understanding what is going on with the CS pin). So. I copied the code into my sketch board, made the connections as per the suggested circuitry and it run from the first try :-).
I attach a picture of my test layout. As you can see, the SDcard module manufacturer is the same.

Please note the following:
a. I tested 4 SD cards I happen to have, 1 of 4 Gbytes and 3 of 8Gbytes. All of them performed Ok, with the exception that they were all reported as “Volume size (Mbytes): 3496” - do not know why.
To further check this, I filled up an 8 Gbytes SDcard with three big movie files (2,5 - 2,2 and 1,5 Gbytes, two of them placed in subfolders), thus exceeding the 3496 Mbytes number, and then apart from the “List files” test, I also performed a Read - Write test in a text file. it worked perfectly well
Below is the files list result.

Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3665821696
Volume size (Kbytes): 3579904
Volume size (Mbytes): 3496

Files found on the card (name, date and size in bytes): 
TEST.TXT      2000-01-01 01:00:00 642
THEGRE~1.AVI  2012-03-03 20:56:06 1485920248
1/            2013-10-13 14:06:58
  THEDES~1.ISO  2012-02-12 15:16:06 2551543808
NEWFOL~1/     2013-10-13 14:07:06
  JEDGAR~1.MP4  2012-02-12 16:00:44 2207540517

b. When sometime the earthing jumper (red wire) was accidentally disconnected from the three voltage dividers ground, the SD card module could still read the two of them, but did not recognize the other two cards. When I found out what had happened and re-earthed the three voltage dividers, everything returned to normal.

Hope this helps.

P.S. As I said, I am completely newbie, and this is my first post ever to a blog - I signed in just yesterday. I am glad to meet the community and thank you all for your help.

SDcard.bmp (805 KB)

All of them performed Ok, with the exception that they were all reported as "Volume size (Mbytes): 3496" - do not know why.

Thank you, fat16lib.

@tsam this really worked for me too. Thanks a lot