#include <SD.h>
#include <SPI.h>
File dataFile;
const int chipSelect = 10; // Change this to match your SD card module's chip select pin
void setup() {
// Open serial communication and initialize the SD card
Serial.begin(9600);
if (!SD.begin(chipSelect)) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("SD card initialized successfully.");
// Create a CSV file named "data.csv" and open it for writing
dataFile = SD.open("data.csv", FILE_WRITE);
if (dataFile) {
Serial.println("Writing to data.csv...");
// Write header row
dataFile.println("Sensor1, Sensor2, Sensor3");
// Write data rows
dataFile.println("100, 200, 300");
dataFile.println("150, 250, 350");
// Close the file
dataFile.close();
Serial.println("Data written to data.csv.");
} else {
Serial.println("Error opening data.csv.");
}
}
void loop() {
// Your main program loop (if needed)
}