Loading
Loading
IoT Lab content is currently available in Arabic only. We're working on an English version.
عرض بالعربية →Collect weather data for your farm for months in an Excel file.
SPI protocol. For Uno: CS(4), MOSI(11), MISO(12), SCK(13).
#include <SPI.h>
#include <SD.h>
File dataFile;
void setup() {
Serial.begin(9600);
if (!SD.begin(4)) { Serial.println("Failed"); return; }
}
void loop() {
dataFile = SD.open("data.csv", FILE_WRITE);
if (dataFile) {
dataFile.println("12:00, 25.5C");
dataFile.close();
}
delay(60000); // سجل كل دقيقة
}Removing the SD card while Arduino is running, or writing code without closing the file with dataFile.close(), which corrupts the entire file.