How to log the collected data from arduino to an SD card

Hi All,

I have connected all my sensors to an Arduino Uno R3 board and all of them are working as expected. Now we would like to deploy them in an outdoor environment where we will not have a PC to store the data so I need to know how to log the data to an external SD card. Any help will be appreciated.


Check the SD examples included in the IDE, and all will be revealed. It is essentially a matter of exchanging Serial.print for myFile.print.

SPI card must be controlled using D13,12,11 and a slave select, usually 10, but can be another. If another, D10 Must be an output for the Arduino to be SPI master. Or, you will have to find a software based SD library. I don't know of any. SDfat.h and the less-preferred SD.h both use the internal SPI hardware. If you have non-SPI based sensors connected to those pins, can they be moved to the analog/digital pins A0-A3/D14-D17?

ashokthella: @Nick_Pyner The thing is I have already used my I2C and SPI ports for other sensors. Is there any other alternative way to connect the SD card?

Probably not, but where is the problem? The SPI bus and the I2C bus are busses. You need to understand what a bus is. By definition, several passengers can sit on a bus. In the case of the SPI, each requires their own module select pin. I2C selection is done by software.

The SD library is included in the IDE. It is probably all you need. The chip selection and I2C addressing are done in the main programme.

When you define your sensors/modules etc etc you define them by their addresses.
Several modules with different addresses can be connected to the same pin/bus.

You can also use a “stand alone” SD module (called “openlogger”) and free up your board.