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
Read the handout text online
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
| Term | Working definition |
| integration | |
| pin definition | |
| common ground | |
| subsystem | |
| fault isolation | |
| hypothesis | |
| evidence |
1. Pin and power map
| Device | Power | Ground | Signal pin | Extra component |
| DS18B20 | 3.3V | GND | GPIO4 | 6.8k pull-up to 3.3V |
| EC board | 3.3V | GND | AO → GPIO1 | T1 unused |
| Turbidity board | 5V | GND | Divider point → GPIO2 | 10k/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
| Reading | Temperature | EC raw | EC mS/cm | Turbidity raw | Turbidity GPIO V |
| 1 | |||||
| 2 | |||||
| 3 |
5. Troubleshooting log
| Symptom | Evidence checked | Hypothesis | One change made | Result |
| 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. |