logzly. Arduino Innovator

Build a Wi-Fi Controlled Arduino Smart Garden in 30 Minutes

Read this article in clean Markdown format for LLMs and AI context.

Ever looked at a wilted basil plant and thought, “If only I could tell it when to drink?” A smart garden does exactly that, and you can have one up and running before your coffee is cold. In this guide I’ll walk you through a quick, cheap, and fun project that lets you water your herbs from a phone, see soil moisture, and even get alerts when something’s off. No PhD required – just a bit of curiosity and a handful of parts.

What you need

The core board

  • Arduino Uno (or any compatible board you already have) – this board can also be the brains behind a self‑balancing robot.
  • ESP‑01 Wi‑Fi module – this is the cheap brain that talks to your phone.
  • Soil moisture sensor – the two‑wire kind that gives an analog voltage.
  • Mini water pump (5 V) and a small relay module to switch it on.
  • Breadboard and jumper wires – keep things tidy.
  • Power supply – a 5 V USB charger works fine for the Arduino; the pump can share the same source if it’s not too power‑hungry.

Optional but handy

  • LED for status indication.
  • Enclosure (a small plastic box) to protect the electronics from water.
  • Smartphone with a web browser – we’ll use a simple web page, no app needed.

All of these parts can be found on any hobby electronics site for under $20. I pulled mine from a local maker store while waiting for my coffee to brew.

Wiring the hardware

1. Power and ground

  • Connect the 5 V pin of the Arduino to the VCC rail on the breadboard.
  • Tie the GND pin to the ground rail. Every component will share this ground.

2. Soil moisture sensor

  • The sensor has three pins: VCC, GND, and A0 (analog output).
  • Plug VCC to 5 V, GND to ground, and A0 to A0 on the Arduino. This will give us a value from 0 (wet) to 1023 (dry).

3. Relay and pump

  • The relay module has a IN pin, VCC, GND, and two screw terminals for the pump.
  • Connect IN to digital pin 8 on the Arduino.
  • Power the relay’s VCC and GND from the same rails.
  • Wire the pump’s positive lead to the normally open (NO) terminal, the other side to ground. Then connect the relay’s common (COM) terminal to the 5 V supply. When the relay is activated, the pump gets power.

4. ESP‑01 Wi‑Fi

  • The ESP‑01 needs 3.3 V, not 5 V. Use a 3.3 V regulator or a dedicated ESP‑01 breakout board that already has one.
  • Connect VCC to 3.3 V, GND to ground, TX to Arduino pin 2, and RX to Arduino pin 3 (through a 1 kΩ resistor to protect the ESP from 5 V logic).
  • Add a reset pin to Arduino pin 4 if you want to reboot the module from code.

5. Status LED (optional)

  • Put the LED’s anode (long leg) through a 220 Ω resistor to digital pin 13, cathode to ground. We’ll blink it when Wi‑Fi is connected.

Double‑check every wire – a loose connection is the most common cause of “it won’t work” moments.

Programming the Arduino

1. Install the libraries

You’ll need two small libraries:

  • ESP8266WiFi – handles the Wi‑Fi connection.
  • ESP8266WebServer – lets the Arduino serve a web page.

Both can be added through the Arduino IDE’s Library Manager. Search for “ESP8266” and install the first result.

2. Sketch outline

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

ESP8266WebServer server(80);

const int moisturePin = A0;
const int pumpPin = 8;
const int ledPin = 13;

void handleRoot() {
  int moisture = analogRead(moisturePin);
  String html = "<h1>Smart Garden</h1>";
  html += "<p>Soil moisture: " + String(moisture) + "</p>";
  html += "<a href=\"/pump/on\">Turn pump ON</a><br>";
  html += "<a href=\"/pump/off\">Turn pump OFF</a>";
  server.send(200, "text/html", html);
}

void handlePumpOn() {
  digitalWrite(pumpPin, HIGH);
  server.sendHeader("Location", "/");
  server.send(302, "text/plain", "");
}

void handlePumpOff() {
  digitalWrite(pumpPin, LOW);
  server.sendHeader("Location", "/");
  server.send(302, "text/plain", "");
}

void setup() {
  pinMode(pumpPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pumpPin, LOW);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWiFi connected");
  digitalWrite(ledPin, HIGH); // LED on when connected
  server.on("/", handleRoot);
  server.on("/pump/on", handlePumpOn);
  server.on("/pump/off", handlePumpOff);
  server.begin();
}

void loop() {
  server.handleClient();
}

3. Upload steps

  1. Connect the Arduino to your PC via USB.
  2. In the IDE, select Board > Arduino Uno and the correct COM port.
  3. Click Upload. The sketch will compile and send to the board.
  4. Open the Serial Monitor (115200 baud) to see the Wi‑Fi connection progress.

If the ESP‑01 doesn’t respond, press the reset button on the module after the upload finishes. That usually clears any hiccup.

Testing and tweaking

1. Find the IP address

When the board connects, the Serial Monitor prints something like IP address: 192.168.1.45. Type that address into any phone or laptop browser on the same Wi‑Fi network.

You should see a simple page with the current moisture reading and two links to turn the pump on or off. Click “Turn pump ON” – the pump should whirr for a second, then stop when you click “OFF”. If nothing happens, double‑check the relay wiring and make sure pin 8 is set as OUTPUT.

2. Calibrate the moisture sensor

The raw analog value depends on soil type and sensor placement. A quick way to calibrate:

  • Stick the probe into dry soil, note the reading (e.g., 800).
  • Then into water‑soaked soil, note the reading (e.g., 300).
  • Map these numbers to “dry” and “wet” in your mind, or adjust the web page to show “Dry”, “Moist”, “Wet” based on thresholds.

3. Automate watering

If you want the garden to water itself, add a tiny function in loop():

if (analogRead(moisturePin) > 700) { // dry threshold
  digitalWrite(pumpPin, HIGH);
  delay(2000); // run pump for 2 seconds
  digitalWrite(pumpPin, LOW);
}

You can also add a delay(60000) to check once a minute, or use a real‑time clock for scheduled watering.

4. Protect the electronics

Water and electronics don’t mix well. Put the Arduino, ESP‑01, and relay inside a small plastic box with a hole for the sensor probe and pump wires. Seal any gaps with silicone. I used a reused mint tin – cheap and surprisingly sturdy.

A few lessons learned

  • Power matters – the ESP‑01 is picky about 3.3 V. A cheap regulator can save you from a fried module.
  • Reset is your friend – a quick reset of the ESP after uploading often clears “no response” bugs.
  • Keep it simple – the web page is plain HTML on purpose. Adding CSS looks nice, but it also adds extra bytes and can slow down the tiny ESP‑01.

That’s it! In under half an hour you have a garden that talks to your phone, tells you when the soil is thirsty, and waters itself on command. The next step is to add a temperature sensor, a light sensor, or even a tiny camera. For a complete environmental view, consider building a battery‑powered weather station. The sky’s the limit, but even this basic version makes a big difference for anyone who forgets to water their herbs.

Happy making, and may your basil stay forever green.

Reactions
Do you have any feedback or ideas on how we can improve this page?