Grade 9 · From USB to Field System: ESP32 water quality

Record CSV data and timestamps

Follow the student handout to build, test and document this stage of the water-quality system.

Prepared lesson material. Start this task when your teacher introduces it; it is not currently assigned homework.

For this lesson

2 pages · Use the handout for the complete instructions, examples and response spaces.

Read the handout text online

For diagrams, visual examples and the full layout, open the handout above.

Lesson 10: CSV Output and Timestamps

Structured logging and spreadsheet import

Grade 9 MYP Design | From USB to Field System

Name: __________________Class / team: __________________Date: __________________
Today’s goals • Create elapsed timestamps with millis(). • Print consistent CSV rows every five seconds. • Import and graph the data.

Key vocabulary

TermWorking definition
CSV
header
field
row
timestamp
millis()
interval
delimiter

1. Diagnose the CSV

Valid example

time_ms,temp_C,ec_mS_cm,turbidity_raw5000,23.81,0.412,286010000,23.81,0.417,284815000,23.88,0.415,2855

What would break the import? List three possible formatting mistakes.

________________________________________________________________________________________________________________

________________________________________________________________________________________________________________

________________________________________________________________________________________________________________

2. Logging code pattern

const unsigned long READ_INTERVAL_MS = 5000;unsigned long nextReading = 0;void loop() { unsigned long now = millis(); if (now >= nextReading) { nextReading = now + READ_INTERVAL_MS; // Read sensors here Serial.print(now); Serial.print(','); Serial.print(tempC, 2); Serial.print(','); Serial.print(ecMS, 3); Serial.print(','); Serial.println(turbRaw); }}

3. Header and fields

Field nameMeaningUnitExample
time_msElapsed time since bootms5000
temp_CWater temperature°C23.81
ec_mS_cmEstimated conductivitymS/cm0.412
turbidity_rawESP32 ADC readingADC count2860

4. Data collection record

☐ Header prints once.

☐ Every row has the same number of commas.

☐ Readings are approximately five seconds apart.

☐ No commentary appears inside the CSV data.

☐ File is saved with .csv extension.

5. Spreadsheet task

Open the CSV in your spreadsheet program.

Verify each field appears in its own column.

Create one line graph against time.

Add axis labels, units, and a descriptive title.

Write a caption stating the sample and whether the values are calibrated.

6. Reflection

What does millis() tell us, and what does it not tell us? How could a future version record real date and time?