Introduction
Data logging helps you keep track of what your device does over time. It lets you see patterns and find problems easily.
Data logging helps you keep track of what your device does over time. It lets you see patterns and find problems easily.
Use functions like Serial.print() or write to an SD card using SD library to save data.
Serial.print("Temperature: "); Serial.println(25);
#include <SD.h> File dataFile; void setup() { SD.begin(4); dataFile = SD.open("datalog.txt", FILE_WRITE); if (dataFile) { dataFile.println("Start logging"); dataFile.close(); } }
This program initializes the SD card and writes a temperature log line to a file. It also prints status messages to the serial monitor.
#include <SD.h> const int chipSelect = 4; void setup() { Serial.begin(9600); while (!Serial) {} if (!SD.begin(chipSelect)) { Serial.println("SD card failed or not present"); return; } File dataFile = SD.open("datalog.txt", FILE_WRITE); if (dataFile) { dataFile.println("Logging data: Temperature = 25 C"); dataFile.close(); Serial.println("Data logged successfully."); } else { Serial.println("Error opening datalog.txt"); } } void loop() { // Nothing here }
Always check if the SD card is present before writing data.
Use Serial Monitor to see quick logs during development.
Data logging helps you find problems by looking at past data.
Data logging saves important information for later review.
It helps find patterns and troubleshoot devices.
Use simple commands to log data to serial or SD cards.
void setup() {
Serial.begin(9600);
Serial.print("Temp: ");
Serial.print(25);
Serial.println(" C");
}
void loop() {}#include <SD.h>
File dataFile;
void setup() {
SD.begin(4);
dataFile = SD.open("log.txt", FILE_WRITE);
dataFile.println("Start logging");
dataFile.close();
}
void loop() {}Pass the test and this pattern moves unknown