Arduino plant monitoring system: soil, air and light on an LCD

Build a smart plant monitoring system with an Arduino UNO: it measures soil moisture, air temperature, humidity and light, shows them on a 1602 LCD and lights a red LED when your plant needs water, warmth or light. Full code,...
  • Level:Intermediate
  • Duration: 1 h
  • Ages 10+
  • Platform: Arduino

Tools for this lesson

Helpful for this build. Open a tool to see tips and more projects that use it.

Arduino plant monitoring system – EEMENTOR STEM™ guide

Quick answer: an Arduino plant monitoring system reads a soil moisture sensor for the soil, a DHT11 for air temperature and humidity and a photoresistor for light, then shows the numbers on a 1602 LCD. A green LED means "all good" and a red LED means your plant needs water, warmth or light. Everything runs on an Arduino UNO, with no Wi-Fi and no app, and the full code is below.

A smart plant monitor is one of the most useful first Arduino projects: it sits on the windowsill and tells you, at a glance, when your plant is thirsty, too cold or in the dark. This guide builds the complete system step by step, starting with the screen and adding one sensor at a time, so you can test each part as you go. You also learn how to calibrate the soil sensor for your own pot, which is the step most plant monitors skip. Want to check your plant from your phone instead? Jump to Build the Wi-Fi version.

What you need

  • From the UNO R3 Starter Kit: the UNO R3 board and USB cable, breadboard and jumper wires, 1602 LCD display, 10 kΩ potentiometer, DHT11 module, 1 green LED, 1 red LED and 3 resistors of 220 Ω
  • From the 45-in-1 Sensor Kit: the soil moisture module with its fork probe, and the photoresistor module
  • A plant in a pot, and a glass of water for calibrating
  • The free Arduino IDE with the DHT sensor library by Adafruit (install it from the Library Manager and say yes when it asks to add Adafruit Unified Sensor)

If your LCD has no pins, solder 16 pins from the 40-pin male header in the kit first, so it plugs into the breadboard. Ask an adult to help if you're new to soldering. Never used the LCD before? Try Show text on the 1602 LCD first.

The four readings of the plant monitor: soil moisture from the soil module, temperature and humidity from the DHT11 and light from the photoresistor module, with the default warning limits.
What the monitor measures and when the red LED comes on.

Step 1: Build the screen

Wire the LCD and the potentiometer first, using the LCD rows of the wiring table. Upload the sketch from Full code and turn the potentiometer slowly until the text is sharp. With no sensors connected yet, the bottom line shows "Air sensor err": that's expected, and it proves the screen and the sketch work.

Step 2: Add the sensors

Now wire the DHT11 to pin 7, the soil module to A0 (with its VCC on pin 8) and the photoresistor module to A1. Within a couple of seconds the bottom line changes to temperature, humidity and light, for example 21.5C 48% L62%. Breathe gently on the DHT11 and the humidity goes up; cover the photoresistor with your hand and the light value drops.

Step 3: Calibrate the soil sensor

Every soil sensor and every pot reads a little differently, so the sketch needs two numbers from your own sensor:

  1. Open Tools → Serial Monitor at 9600 baud.
  2. Hold the fork in the air and write down the "soil raw" number. That is DRY.
  3. Put only the metal fork in a glass of water and write down the new number. That is WET.
  4. Type both numbers into the sketch and upload again.
Calibrating the soil sensor: a DRY reading with the fork in the air, a WET reading with the fork in water, and map() turning readings between them into 0 to 100 percent.
Step 3 in pictures. Use your own DRY and WET numbers.

Step 4: Set your plant's limits

Change WATER_BELOW, TOO_COLD, TOO_HOT and TOO_DARK near the top of the sketch to suit your plant. A cactus can go much drier than a fern, and a basil plant on a cold windowsill needs warmth more than water. A good way to find the right soil value: water the plant, wait an hour and note the %, then watch how far it drops before the leaves start to droop, and set WATER_BELOW a little above that.

Step 5: Move it to the plant

Push the fork into the soil next to the plant, keeping the module, the wires and the UNO dry. Put the photoresistor where the leaves get their light, and keep the DHT11 out of direct sun and away from the wet soil. After uploading, you can power the UNO from a USB phone charger, so it runs without a computer.

Six LCD screens from the sketch: OK, WATER!, COLD, HOT, DARK and Air sensor err, each with the green or red LED that lights up.
What the LCD shows in each situation, with example numbers.

Full code

// Plant monitoring system: soil moisture, temperature, humidity and light on a 1602 LCD.
// Green LED = all good. Red LED = the plant needs something (see the top line).
#include <LiquidCrystal.h>
#include <DHT.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);   // RS, E, D4, D5, D6, D7
DHT dht(7, DHT11);

const int SOIL_POWER = 8;    // powers the soil module only while measuring
const int SOIL_PIN = A0;     // soil module AO
const int LIGHT_PIN = A1;    // photoresistor module S
const int GREEN_LED = 9;
const int RED_LED = 10;

// Calibrate these two for your own sensor (step 3)
int DRY = 1000;   // reading with the fork in the air
int WET = 400;    // reading with the fork in a glass of water

// Your plant's limits (step 4)
const int WATER_BELOW = 30;      // soil moisture in %
const float TOO_COLD = 10.0;     // °C
const float TOO_HOT = 30.0;      // °C
const int TOO_DARK = 15;         // light in %

int readSoil() {
  digitalWrite(SOIL_POWER, HIGH);   // power on, wait, read, power off
  delay(100);
  int raw = analogRead(SOIL_PIN);
  digitalWrite(SOIL_POWER, LOW);
  Serial.print("soil raw ");
  Serial.print(raw);
  return constrain(map(raw, DRY, WET, 0, 100), 0, 100);
}

void setup() {
  Serial.begin(9600);
  pinMode(SOIL_POWER, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
  lcd.begin(16, 2);
  dht.begin();
  lcd.print("Plant monitor");
  delay(2000);
}

void loop() {
  int soil = readSoil();
  int light = map(analogRead(LIGHT_PIN), 0, 1023, 100, 0);   // bright = high %
  float temp = dht.readTemperature();
  float hum = dht.readHumidity();
  bool airOk = !isnan(temp) && !isnan(hum);

  Serial.print(" = ");
  Serial.print(soil);
  Serial.print(" %   light ");
  Serial.print(light);
  Serial.println(" %");

  // The most urgent problem wins
  const char* status = "OK";
  if (soil < WATER_BELOW) status = "WATER!";
  else if (airOk && temp < TOO_COLD) status = "COLD";
  else if (airOk && temp > TOO_HOT) status = "HOT";
  else if (light < TOO_DARK) status = "DARK";
  bool ok = (status[0] == 'O');
  digitalWrite(GREEN_LED, ok ? HIGH : LOW);
  digitalWrite(RED_LED, ok ? LOW : HIGH);

  lcd.clear();
  lcd.print("Soil ");
  lcd.print(soil);
  lcd.print("% ");
  lcd.print(status);
  lcd.setCursor(0, 1);
  if (airOk) {
    lcd.print(temp, 1);
    lcd.print("C ");
    lcd.print(hum, 0);
    lcd.print("% L");
    lcd.print(light);
    lcd.print("%");
  } else {
    lcd.print("Air sensor err");
  }
  delay(2000);   // a new reading every 2 s (the DHT11 can answer about once a second)
}

Wiring

Breadboard wiring diagram: 1602 LCD with contrast potentiometer, DHT11 on pin 7, photoresistor module on A1, soil moisture module powered from pin 8 with AO to A0, green LED on pin 9 and red LED on pin 10.
Breadboard view. Check each connection against the wiring table below.
From To
LCD VSS, RW and K GND
LCD VDD 5V
LCD V0 Middle pin of the potentiometer (outer pins to 5V and GND)
LCD RS, E UNO pins 12, 11
LCD D4, D5, D6, D7 UNO pins 5, 4, 3, 2
LCD A (backlight +) 220 Ω resistor, then 5V
DHT11 S, +, − UNO pin 7, 5V, GND
Soil module VCC UNO pin 8 (not 5V: the sketch switches it on only to measure)
Soil module GND, AO GND, UNO A0 (DO is not used)
Photoresistor module S, +, − UNO A1, 5V, GND
Green LED long leg 220 Ω resistor, then UNO pin 9 (short leg to GND)
Red LED long leg 220 Ω resistor, then UNO pin 10 (short leg to GND)

Modules from different makers can label and order their pins differently. Always follow the labels printed on your module.

FREE

Build the LCD part of this project in EEMENTOR Lab

Wire it yourself in your browser before you touch a real wire. No sign-up, nothing to install.

The parts for this circuit laid out in EEMENTOR Lab, ready to wireBuild it yourself
  1. Wire the parts using the wiring table above. Pins with no wire show red.
  2. The Lab’s LCD needs no contrast potentiometer or backlight resistor: wire VSS, V0, RW and K to the ground symbols, and A to 5V.
  3. Press Run and watch the text appear on the LCD.
  4. Want the whole project? Add the other parts from the parts list, wire them from the table, then paste this lesson’s sketch into the Code tab and press Compile & Run.

EEMENTOR Lab is free and in beta. Results are a guide; a real build can differ slightly. About the Lab

How it works

Soil moisture: the fork is a resistive sensor. Water carries electricity, so the wetter the soil, the more current flows between the two prongs and the lower the reading on A0. map() turns your DRY and WET readings into 0 to 100 %. The sketch powers the module from pin 8 only for a moment while it measures, because a fork that carries current all day corrodes quickly in wet soil.

Air: the DHT11 measures temperature to about ±2 °C and humidity to about ±5 %, which is plenty for a plant. It answers about once a second, so the sketch reads it every 2 seconds. If a reading fails, isnan() catches it and the screen shows "Air sensor err" instead of a wrong number.

Light: the photoresistor's resistance falls in bright light. The module turns that into a voltage on A1, and the sketch flips it so bright light gives a high %.

The status: the sketch checks the problems in order of urgency, so if the soil is dry and it's also dark, the screen says "WATER!" first. Any problem switches the green LED off and the red LED on.

Build the Wi-Fi version

The UNO has no Wi-Fi, so this monitor shows its readings on the spot. To check your plant from anywhere and get an alert on your phone, build the same idea on an ESP32 from the ESP32 IoT Starter Kit:

Optional: water the plant automatically

The 2-channel relay module in the UNO R3 Starter Kit can switch a small pump on when the soil is dry. A pump isn't in our kits, so this part is optional. Our automatic mini greenhouse shows the relay wiring and adds timers, so the watering can never run for too long and flood the pot. On the ESP32, Build an automatic plant watering system with Blynk also checks that the water tank isn't empty.

Common problems

  • The LCD lights up but shows no text, or only boxes: turn the potentiometer slowly from one end to the other. Then check RS, E and D4 to D7.
  • "Air sensor err" all the time: check that the DHT11's S pin goes to pin 7 and that the DHT sensor library is installed. Keep the 2-second delay at the end of the sketch.
  • Soil always shows 0 % or 100 %: you haven't calibrated yet, or DRY and WET are swapped. Repeat Step 3.
  • The soil reading drifts after a few weeks: the metal fork slowly corrodes in wet soil. Powering it only while measuring (pin 8) slows this down. Clean the fork and calibrate again.
  • Light is high in the dark: some photoresistor modules count the other way. Swap the 100 and 0 in the map() line for light.
  • The UNO resets or the screen flickers: a weak USB charger can't power the LCD backlight and the sensors together. Use a charger rated at least 1 A.

FAQ

How does an Arduino plant monitoring system work?

Sensors measure the soil moisture, air temperature, humidity and light around the plant. The Arduino reads them every few seconds, compares them with limits you set for your plant, and shows the values and a status such as "WATER!" on an LCD, with a red LED as a warning.

Can the plant monitor water the plant by itself?

Yes, with a relay and a small pump. The relay is in the UNO R3 Starter Kit; the pump isn't in our kits. Our automatic mini greenhouse shows how a relay switches the watering on and off safely.

Can I see the readings on my phone?

Not with the UNO, which has no Wi-Fi. Build it on an ESP32 instead: our Arduino Cloud plant monitor and Blynk plant monitor send the same kind of readings to an app.

Which soil moisture value is right for my plant?

There's no single number, because every pot and soil reads differently. Water the plant, wait an hour and note the %, then watch how far it drops before the leaves droop, and set the limit a little above that.

How long does the soil moisture sensor last?

A resistive fork corrodes slowly in wet soil. Because this sketch powers it only while measuring, it lasts much longer than one that is always on. Clean it when the readings drift and calibrate again.

Related lessons