Arduino Project: Automatic Plant Watering System with Soil Moisture Sensor and OLED Display file EB4Pj8TTywgP2qk9WVNkaF
Arduino Project: Automatic Plant Watering System with Soil Moisture Sensor and OLED Display file EB4Pj8TTywgP2qk9WVNkaF

Arduino Project: Automatic Plant Watering System with Soil Moisture Sensor and OLED Display


1. Introduction

In this project, we will create an automatic plant watering system using an Arduino, a soil moisture sensor, a water pump, and an OLED display. This system will monitor the soil moisture level and water the plant when the soil becomes dry. The OLED display will show the moisture level in real-time.

This project has practical applications in smart gardening, helping to maintain the right soil moisture level for plants. It’s a great example of how IoT and automation can simplify everyday tasks.


2. Learning Objectives

By the end of this project, you will learn:

  • How to interface a soil moisture sensor with an Arduino
  • How to control a water pump using a relay module
  • How to display data on a 0.96-inch OLED screen
  • How to implement conditional logic for automation
  • Basic concepts of data visualization in embedded systems

3. Tools and Components

Hardware:

  • Arduino Uno or similar (e.g., Arduino Nano)
  • Soil Moisture Sensor (with analog output)
  • 0.96-inch OLED Display (I2C)
  • Relay Module (1-channel)
  • Mini Water Pump (5V or 12V)
  • Power supply (for the water pump)
  • Jumper wires
  • Breadboard
  • Small tubing for water delivery (optional)
  • Plant pot with soil and a plant for testing

Software:

  • Arduino IDE
  • Adafruit GFX and Adafruit SSD1306 libraries for OLED display

4. Background/Definitions

4.1 Arduino

The Arduino is an open-source microcontroller platform widely used for building electronics projects. It’s easy to program using the Arduino IDE and supports numerous sensors and modules.

4.2 Soil Moisture Sensor

A soil moisture sensor measures the water content in the soil. It provides an analog output that can be read by the Arduino to determine the moisture level. Lower readings indicate dry soil, while higher readings indicate wet soil.

4.3 OLED Display

An OLED display is a compact, high-contrast screen that is often used in embedded systems for displaying text and graphics. It communicates with the Arduino over the I2C protocol.

4.4 Relay Module

A relay module is used to control high-power devices like water pumps using a low-power signal from the Arduino. It acts as a switch that the Arduino can control electronically.


5. Step-by-Step Guide

Step 1: Circuit Wiring

Here’s how to wire the components to the Arduino:

  • Soil Moisture Sensor
    • VCC → 5V on Arduino
    • GND → GND on Arduino
    • A0 → A0 on Arduino
  • OLED Display (I2C)
    • VCC → 5V on Arduino
    • GND → GND on Arduino
    • SCL → A5 on Arduino
    • SDA → A4 on Arduino
  • Relay Module
    • VCC → 5V on Arduino
    • GND → GND on Arduino
    • IN → Digital Pin 7 on Arduino
  • Water Pump
    Connect the water pump to an external power source through the relay module. Ensure the relay is wired in series with the pump’s power line.

Step 2: Arduino Code

Here’s the complete Arduino code for this project:

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // Reset pin not used
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

const int soilMoisturePin = A0;
const int relayPin = 7;
int moistureLevel = 0;
int threshold = 400; // Adjust this threshold based on your soil and sensor calibration

void setup() {
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH); // Turn off the pump initially
Serial.begin(9600);

if (!display.begin(SSD1306_I2C_ADDRESS, 0x3C)) {
Serial.println("OLED initialization failed");
while (true);
}

display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
}

void loop() {
moistureLevel = analogRead(soilMoisturePin);

Serial.print("Soil Moisture Level: ");
Serial.println(moistureLevel);

display.clearDisplay();
display.setCursor(0, 0);
display.print("Moisture Level: ");
display.println(moistureLevel);

if (moistureLevel < threshold) {
digitalWrite(relayPin, LOW); // Turn on the pump
display.println("Watering...");
} else {
digitalWrite(relayPin, HIGH); // Turn off the pump
display.println("No Watering");
}

display.display();
delay(2000); // Delay for 2 seconds before reading again
}

6. Testing and Debugging Tips

  1. Calibrate the Soil Moisture Sensor:
    Test the sensor in both dry and wet soil to determine its range and adjust the threshold value in the code accordingly.
  2. Check the Relay Module:
    Ensure that the relay clicks when activated. If not, check the wiring and power supply.
  3. OLED Display Not Working?
    Double-check the I2C connections and ensure you have the correct I2C address in the code (0x3C for most displays).
  4. Water Pump Issues:
    Make sure the pump’s external power supply matches its voltage and current requirements.

7. Extensions

Take this project further with these ideas:

  • Add Wi-Fi Connectivity: Use an ESP8266 or ESP32 to monitor soil moisture and control the pump remotely via a smartphone app.
  • Temperature and Humidity Sensor: Add a DHT11 or DHT22 sensor to monitor environmental conditions.
  • Data Logging: Store moisture level readings on an SD card for long-term analysis.
  • Solar Power: Make the system fully autonomous by powering it with a solar panel and battery.

8. Conclusion

This automatic plant watering system is a practical introduction to automation and embedded systems. By combining sensors, relays, and displays, you’ve created a smart solution to help plants thrive with minimal effort. Keep experimenting and expanding the project to develop a complete smart garden system!