My SD is not working

I am using an Arduino UNO with a MicroSD card (Intenso MicroSDHC 8GB). I am trying to make the sensor work but it does not cooperate ...I got the code from the Arduino examples and it's still not working. The Arduino is working properly and the SD card as well. I have already done a format to the SD but the monitor still shows that initialization failed.

#include <SPI.h>
#include <SD.h>
File myFile;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.print("Initializing SD card...");
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.

myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:

if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("This is a test file :)");
myFile.println("testing 1, 2, 3.");
for (int i = 0; i < 20; i++) {
myFile.println(i);
}
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}

Could be a problem with how you have the SD card connected to the Ardiuno.

So perhaps provide the forum with a schematic and a picture of the setup ?

1 Like


That's an old schematic I had created but the arduino will change (will be a nano or micro)
Also we need to take into consideration expect from (BMP 180, NEO6M (GPS), Micro SD, Buzzer) a High Dynamic Range Digital Light Sensor, CCS811 Air Quality Sensor Breakout - VOC & eCO2, one led, and maybe a rocker switch

To test the SD card, remove everything else attached to the Arduino, and start with a simple example from the SD library.

1 Like

yeah, that's what I am doing. I tried with and without breadboard but nothing

Please post the correct schematic diagram for the SD test case (hand drawn is fine), post the code you tried using code tags, and describe what happened when you tried it.

1 Like

/*
  SD card read/write

  This example shows how to read and write data to and from an SD card file
  The circuit:
   SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)

  created   Nov 2010
  by David A. Mellis
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.

*/

#include <SPI.h>
#include <SD.h>

File myFile;

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


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}


the connections are written in the code

A screen shot and a photo of a wiring rat's nest don't help, and suggest that you are too lazy to document the problem.

Good luck with your project!

On most breadboards, there is no connection between the two sides...

image

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.