Data won't store on SD card breakout from Arduino Uno

Please see my updated post below...I intended to just save a draft with this post, not make it live. Sorry!

I see no attached code.

SurferTim: I see no attached code.

That's right, the code didn't work, so there is no reason to post it?

Why did he even ask the question?



I’m writing a program to store data from a series of sensors on an SD card. The data is not being stored on the card.

Here are the sensors:
Si1145 UV Light Sensor (Adafruit)
HMC5883 Magnetometer (Adafruit)
BMP180 Pressure Sensor (Adafruit)
MQ131 Ozone Sensor (Sainsmart)
254 MicroSD card breakout board+ (Adafruit)

I currently have the sensor array and SD card holder set up on the same breadboard and connected to the Arduino Uno. I wrote a sketch that makes use of the sensors only (see withoutSD). It checks to see that each of the sensors is operational and then prints their readings periodically to the serial monitor. This has worked every time for me.

I also have code using only the SD card (see testSD) that I found on Adafruit’s tutorial for the SD breakout. It opens a file and prints “Testing 1, 2, 3” once before closing the file again. The SD card itself has been formatted and has nothing stored on it. This has also worked every time.

The problem arises when I try to take the data outputted from the sensors and store it in a file on the SD card (see withSD). There are no errors from the compiler, but the code stops running once it reaches the line where I want it to open a file and start storing data.

The code is broken into 5 tabs: withSD has the setup and loop functions, sensorCheck and sdCheck make sure the sensors and sd breakout are working, fileSetup creates and opens a file and puts headers in for each piece of data to be collected, and fileWrite stores the data from each sensor under those headers. sensorCheck, sdCheck, and fileSetup are each called during setup. fileWrite is called during loop. I know that sensorCheck and sdCheck are completed successfully. I also know that fileSetup is started, but not completed successfully.

The code is attached below.

The error seems to come from this line, in both fileSetup and fileWrite:

myFile =“data.txt”, FILE_WRITE);

Strangely, a file does get opened on the sd card under the name “DATA,” but nothing is written to it. Also, I don’t get any notification through the serial monitor that the file is opened. Instead, the serial monitor printout either stops completely or loops back to check the sensors and sd again and again. I don’t know why the code fails at this point, since the line is the same as in the example code.

I hope my summary of the problem is sufficient. Please let me know if you have an questions, and thanks in advance for your help.


withoutSD.ino (5.64 KB)

testSD.ino (1.06 KB)

withSD.ino (860 Bytes)

sensorCheck.ino (1.16 KB)

sdCheck.ino (475 Bytes)

fileWrite.ino (1.67 KB)

fileSetup.ino (1.01 KB)

Sorry about the first post...I intended to just save the draft but I guess I accidentally posted it instead and didn't realize. The new post is more thorough and includes attachments.

The new post isn't much better than your first. Post all the code for your withSD sketch, not just a snippet.