Logging sensor data as CSV over Serial
Capture small experiments in a spreadsheet with timestamps, units and explicit invalid readings.
CSV means comma-separated values: one record per line, with the same columns in the same order. For a simple UNO experiment, begin with a header such as time_ms,distance_cm,valid,state. A header makes the captured text easier to understand later. Include units in the names rather than guessing whether a value is milliseconds or seconds.
Print one complete line per sample using Serial.print for fields and Serial.println for the final field. If a distance is invalid, leave the value field empty and print valid as 0. For example, 1000,,0,invalid is more useful than a fabricated zero-centimeter distance. Avoid mixing ordinary debugging sentences into the same CSV stream.
Choose a sensible sample interval. Ten rows per second is often enough for a tabletop distance experiment; a slow humidity demonstration may need much less. Printing every loop wastes bandwidth and can delay other work. Use a timestamp comparison to schedule logging separately from input handling.
Set Serial Monitor to the baud rate selected by the sketch, such as 115200. Some monitor tools add timestamps or other prefixes; disable those before copying if you want a clean CSV file. Copy the header and records into a plain text file and save with a .csv extension. This is manual capture: it does not automatically save a file from the UNO.
Open the file in a spreadsheet using comma as the delimiter. Plot time against the measured quantity and keep invalid flags visible. Do not silently fill missing readings with zero. If your regional spreadsheet settings use a different decimal separator, import the file explicitly instead of trusting automatic column detection.
For PIR experiments, log raw input and timer output as separate columns. Their difference reveals the module's hardware hold plus the extra software hold. For a servo experiment, the commanded angle is not measured physical feedback; label it command_deg, not actual_angle.
millis wraps on a typical UNO after roughly 49.7 days. Unsigned subtraction remains useful for short scheduling intervals across rollover, but a spreadsheet may need an unwrapped timeline for extremely long captures. Reconnecting the board may reset the time counter. Include the board, sketch version and test conditions beside your results. Reference: https://docs.arduino.cc/language-reference/en/functions/communication/serial/

