Simvik

Greenhouse: is the water arriving?

Judge each pump run and tell an empty tank from a broken sensor. A medium embedded C problem (Error handling), run and graded in the browser.

medium · Error handling · faults · diagnostics · product

Product: Smart greenhouse controller (Agriculture)

Requirement. A pump that runs dry burns out, and a controller that trusts a broken sensor floods the bed. After every pump run, judge it from the soil moisture before and after (in percent) and how long it ran:

  1. Sensor fault if either reading is outside 0 to 100, or the soil got more than 10 points drier while being watered (soil does not dry while you water it).
  2. Otherwise, tank empty if the run lasted the full 5000 ms or more and the soil rose by less than 3 points.
  3. Otherwise the run is OK: a short run that stopped early, or a full run that raised the soil.

Starter code

run_result_t check_run(int before, int after, uint32_t run_ms) {
  if (after - before < 3) return RUN_TANK_EMPTY;
  return RUN_OK;
}

Example tests

A good run and a dry run

printf("%d %d\n", check_run(20, 35, 3000), check_run(20, 21, 5000));

Expected output:

0 1

A short top-up is not a fault

printf("%d\n", check_run(40, 41, 1200));

Expected output:

0

Learn it first

More Error handling problems