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

Integrate three sensors

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

3 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 9: Integrating All Three Sensors

Wiring audit, combined code, and troubleshooting log

Grade 9 MYP Design | From USB to Field System

Name: __________________Class / team: __________________Date: __________________
Today’s goals • Combine three sensors without losing safe power and signal conditions. • Use structured fault isolation.

Key vocabulary

TermWorking definition
integration
pin definition
common ground
subsystem
fault isolation
hypothesis
evidence

1. Pin and power map

DevicePowerGroundSignal pinExtra component
DS18B203.3VGNDGPIO46.8k pull-up to 3.3V
EC board3.3VGNDAO → GPIO1T1 unused
Turbidity board5VGNDDivider point → GPIO210k/20k divider

2. Integration checklist

☐ Power OFF while wiring.

☐ All grounds connect to one common-ground net.

☐ Each sensor has already worked by itself.

☐ GPIO1, GPIO2, and GPIO4 match the code.

☐ Turbidity divider point was measured below 3.3V.

☐ No raw 12V reaches ESP32 or sensors.

3. Integrated test code

#include <OneWire.h>#include <DallasTemperature.h>#include <DFRobot_EC.h>#include <EEPROM.h>#define DS18B20_PIN 4#define EC_PIN 1#define TURBIDITY_PIN 2OneWire oneWire(DS18B20_PIN);DallasTemperature tempSensor(&oneWire);DFRobot_EC ec;int averageAnalog(int pin) { long total = 0; for (int i = 0; i < 20; i++) { total += analogRead(pin); delay(10); } return total / 20;}void setup() { Serial.begin(115200); EEPROM.begin(32); tempSensor.begin(); ec.begin(); analogReadResolution(12); analogSetPinAttenuation(EC_PIN, ADC_11db); analogSetPinAttenuation(TURBIDITY_PIN, ADC_11db); Serial.println("temp_C,ec_raw,ec_mV,ec_mS_cm,turb_raw,turb_gpio_V");}void loop() { tempSensor.requestTemperatures(); float tempC = tempSensor.getTempCByIndex(0); int ecRaw = averageAnalog(EC_PIN); float ecMV = ecRaw * (3300.0 / 4095.0); float ecMS = ec.readEC(ecMV, tempC); ec.calibration(ecMV, tempC); int turbRaw = averageAnalog(TURBIDITY_PIN); float turbGPIOV = turbRaw * (3.3 / 4095.0); Serial.print(tempC, 2); Serial.print(','); Serial.print(ecRaw); Serial.print(','); Serial.print(ecMV, 1); Serial.print(','); Serial.print(ecMS, 3); Serial.print(','); Serial.print(turbRaw); Serial.print(','); Serial.println(turbGPIOV, 3); delay(2000);}

4. First integrated readings

ReadingTemperatureEC rawEC mS/cmTurbidity rawTurbidity GPIO V
1
2
3

5. Troubleshooting log

SymptomEvidence checkedHypothesisOne change madeResult
Recommended order 1) power voltage, 2) common ground, 3) signal voltage, 4) physical pin, 5) code pin definition, 6) library/compile messages. Change one thing at a time.