Measure electrical conductivity
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 7: Conductivity and Analog Input
EC wiring, library installation, and sample comparison
Grade 9 MYP Design | From USB to Field System
| Name: __________________ | Class / team: __________________ | Date: __________________ |
| Today’s goals • Read raw ADC and voltage from the EC board. • Use the DFRobot_EC library with temperature compensation. • Interpret units cautiously. |
Key vocabulary
| Term | Working definition |
| conductivity | |
| ion | |
| analog | |
| ADC | |
| millivolt | |
| mS/cm | |
| µS/cm | |
| calibration | |
| temperature compensation |
1. Wiring
| ESP32.3V3 -> EC_BOARD.VCCESP32.GND -> EC_BOARD.GNDEC_BOARD.AO -> ESP32.GPIO1EC_BOARD.T1 -> NOT CONNECTED |
2. Install DFRobot_EC
Open https://github.com/DFRobot/DFRobot_EC
Choose Code → Download ZIP.
In Arduino IDE, choose Sketch → Include Library → Add .ZIP Library.
If installation fails, unzip and place a folder named DFRobot_EC in Documents/Arduino/libraries so DFRobot_EC.h is directly inside it.
3. Test code
| #include <OneWire.h>#include <DallasTemperature.h>#include <DFRobot_EC.h>#include <EEPROM.h>#define DS18B20_PIN 4#define EC_PIN 1OneWire oneWire(DS18B20_PIN);DallasTemperature tempSensor(&oneWire);DFRobot_EC ec;void setup() { Serial.begin(115200); EEPROM.begin(32); tempSensor.begin(); ec.begin(); analogReadResolution(12); analogSetPinAttenuation(EC_PIN, ADC_11db); Serial.println("temp_C,ec_raw,ec_mV,ec_mS_cm,ec_uS_cm");}void loop() { tempSensor.requestTemperatures(); float tempC = tempSensor.getTempCByIndex(0); int raw = analogRead(EC_PIN); float mV = raw * (3300.0 / 4095.0); float mS = ec.readEC(mV, tempC); ec.calibration(mV, tempC); Serial.print(tempC, 2); Serial.print(','); Serial.print(raw); Serial.print(','); Serial.print(mV, 1); Serial.print(','); Serial.print(mS, 3); Serial.print(','); Serial.println(mS * 1000.0, 1); delay(2000);} |
4. Sample comparison
| Sample | Trial 1 mS/cm | Trial 2 | Trial 3 | Mean | Prediction supported? |
| Filtered water | |||||
| Tap water | |||||
| Weak salt solution |
5. Interpret the units
Convert 1.413 mS/cm to µS/cm: __________________________
Why should today’s EC values be described as estimated or relative?
________________________________________________________________________________________________________________
________________________________________________________________________________________________________________
________________________________________________________________________________________________________________
________________________________________________________________________________________________________________
| Probe care Rinse between samples. Keep immersion depth and waiting time consistent. Do not let salt solution dry on the probe. |