#include <FS.h>
#include <SD.h>
#include <SPI.h>
#define SD_CS 5 // Chip Select pin for SD card
File file;
void setup() {
Serial.begin(115200);
if (!SD.begin(SD_CS)) {
Serial.println("Card Mount Failed");
return;
}
Serial.println("SD Card initialized.");
file = SD.open("/data.txt", FILE_APPEND);
if (!file) {
Serial.println("Failed to open file");
return;
}
file.println("ESP32 Data Logging Start");
file.close();
}
void loop() {
int sensorValue = analogRead(34);
file = SD.open("/data.txt", FILE_APPEND);
if (file) {
file.print("Sensor Value: ");
file.println(sensorValue);
file.close();
Serial.print("Logged: ");
Serial.println(sensorValue);
} else {
Serial.println("Error opening file");
}
delay(2000);
}