Automating your gardening

We are now going to configure our project so it automatically waters the plant if the humidity falls below a given threshold.

The first step is actually to define two thresholds:

floatlowThreshold = 20.00;
floathighThreshold = 25.00;

We need two thresholds here because if we just defined one, the pump will constantly switch between the on and off states.

So we will have the pump turn on when the humidity goes below the low threshold, and turn off when we reach the high threshold again.

Next, we define which pin the relay is connected to:

#define relayPin 15

In the setup() function of the sketch, we set the relay pin as an output:

pinMode(relayPin, OUTPUT);

In the loop() function, we constantly check whether the humidity went below ...

Get Internet of Things with ESP8266 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.