Simvik

Greenhouse: switch the pump with a band

Decide whether the pump runs, with a band so the relay does not chatter. An easy embedded C problem (Decisions and loops), run and graded in the browser.

easy · Decisions and loops · if · hysteresis · product

Product: Smart greenhouse controller (Agriculture)

Requirement. Start watering when the soil is drier than the grower's level, and stop only once it is 15 points wetter than that level. Between the two, the pump keeps doing what it was doing.

running is whether the pump runs now, soil the moisture in percent and water_below the grower's level. Return whether the pump should run next.

Starter code

bool pump_next(bool running, int soil, int water_below) {
  return soil < water_below;
}

Example tests

Dry soil starts it, wet soil stops it

printf("%d %d\n", pump_next(false, 20, 30), pump_next(true, 50, 30));

Expected output:

1 0

Inside the band it keeps its state

printf("%d %d\n", pump_next(true, 38, 30), pump_next(false, 38, 30));

Expected output:

1 0

Learn it first

  • Decisions and loops · Choosing with if and switch, repeating with while and for, and the loop that never ends.

More Decisions and loops problems