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
Read the handout text online
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
| Term | Working 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 name | Meaning | Unit | Example |
| time_ms | Elapsed time since boot | ms | 5000 |
| temp_C | Water temperature | °C | 23.81 |
| ec_mS_cm | Estimated conductivity | mS/cm | 0.412 |
| turbidity_raw | ESP32 ADC reading | ADC count | 2860 |
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?