Arduino MicroSD Data Logger

Sample a sensor once per second and write the timestamped value to a CSV file on a microSD card — standalone logging with no internet required.

Difficulty: Breadboard. Estimated build time: about 45 minutes. Estimated parts cost: about US$8.00. 6-line bill of materials. Compare supplier offers when available. A standalone data logger that records sensor readings to a FAT32-formatted microSD card.

Wire the SD breakout

Most microSD breakouts have six pins: VCC, GND, MISO, MOSI, SCK, CS. The cheaper ones run from 5 V (and include onboard level shifters); a few logic-level boards need 3.3 V. Connect VCC to 5 V, GND to GND, MISO to D12, MOSI to D11, SCK to D13, and CS to D10. (CS can go to any digital pin; D10 is the conventional choice on the UNO.)

Format the card and test the library

Format the microSD as FAT32 using your computer's disk utility — most cards ship pre-formatted as FAT32 but it's worth confirming. Insert the card. In the Arduino IDE, open File > Examples > SD > CardInfo. Edit the chipSelect line to 10 and upload. Open Serial Monitor at 9600 baud and you should see the card type, file system, and size. If it says "initialization failed", check the wiring — SPI swaps are the most common cause.

Open a file for append

In your sketch, call SD.begin(10) in setup(). Then call File dataFile = SD.open("LOG.CSV", FILE_WRITE). FILE_WRITE opens for append — the next write lands at the end of any existing data, so re-running the sketch never wipes the file. Write a header line on the first run: dataFile.println("millis,temperatureC"). Always dataFile.close() so the changes are flushed before the next loop iteration.

Log a sensor value every second

Inside loop(), read your sensor (a TMP36 on A0, a DS18B20 on D2, anything you've already played with), then dataFile.print(millis()); dataFile.print(","); dataFile.println(temperatureC); dataFile.close(); delay(1000). After a minute, pull the card and read it on your computer. You'll see exactly sixty lines of comma-separated millis,temperature. From here you can plot, look for trends, swap in any other sensor, or wake from sleep to extend battery-powered runs to weeks.