Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino-Controlled Soil Moisture Sensing with Automatic Watering System

Image of Arduino-Controlled Soil Moisture Sensing with Automatic Watering System

Circuit Documentation

Summary

This circuit is designed to monitor soil moisture levels and control a solenoid valve based on the moisture content. The system uses an Arduino UNO as the central processing unit, interfaced with a SparkFun Soil Moisture Sensor to detect the moisture level. A 1 Channel 5V Relay Module is used to control the solenoid valve, which is powered by a 12V battery through a 7805 voltage regulator. The PowerBoost 1000 Basic Terminal USB provides a stable 5V supply to the Arduino and other 5V components. A diode is used in parallel with the solenoid to protect the circuit from voltage spikes (flyback diode).

Component List

  • Arduino UNO: A microcontroller board based on the ATmega328P, featuring digital and analog I/O pins.
  • SparkFun Soil Moisture Sensor: A sensor that measures the volumetric content of water in the soil and outputs an analog signal.
  • 1 Channel 5V Relay Module: An electromechanical switch that allows control of a high-power circuit by a low-power signal from the Arduino.
  • PowerBoost 1000 Basic Terminal USB: A 5V USB boost converter for powering the circuit from the battery.
  • Solenoid Valve: An electromechanical device used to control the flow of liquid or gas.
  • Diode: A semiconductor device that allows current to flow in one direction only, used here to protect against reverse current.
  • 12V Battery (mini): A power source for the circuit, providing 12V to the voltage regulator.
  • 7805 Voltage Regulator: A component that converts a higher input voltage into a stable 5V output.

Wiring Details

Arduino UNO

  • 5V: Connected to the 5V power rail supplied by the PowerBoost 1000.
  • GND: Connected to the ground rail.
  • A0: Connected to the SIG pin of the SparkFun Soil Moisture Sensor.
  • D3: Connected to the IN pin of the 1 Channel 5V Relay Module.

SparkFun Soil Moisture Sensor

  • VCC: Connected to the 5V power rail.
  • GND: Connected to the ground rail.
  • SIG: Connected to the A0 pin on the Arduino UNO.

1 Channel 5V Relay Module

  • VCC+: Connected to the 5V power rail.
  • VCC- (GND): Connected to the ground rail.
  • IN: Controlled by the D3 pin on the Arduino UNO.
  • N.O.: Connected to one terminal of the solenoid valve.
  • COM: Connected to the anode of the diode and one terminal of the solenoid valve.

PowerBoost 1000 Basic Terminal USB

  • VBAT: Connected to the Vout pin of the 7805 voltage regulator.
  • GND: Connected to the ground rail.
  • 5.0V: Provides the 5V power rail for the circuit.

Solenoid Valve

  • pin1: Connected to the COM pin of the relay module and the cathode of the diode.
  • pin2: Connected to the N.O. pin of the relay module.

Diode

  • anode: Connected to the COM pin of the relay module.
  • cathode: Connected to pin1 of the solenoid valve.

12V Battery (mini)

  • +: Connected to the Vin pin of the 7805 voltage regulator.
  • -: Connected to the ground rail.

7805 Voltage Regulator

  • Vin: Connected to the + terminal of the 12V battery.
  • Gnd: Connected to the ground rail.
  • Vout: Connected to the VBAT pin of the PowerBoost 1000.

Documented Code

// sketch.ino
const int MOISTURE_SENSOR_PIN = A0; // Assuming the sensor SIG pin is connected to A0
const int RELAY_PIN = 3;            // Relay module is controlled by pin D3
const int MOISTURE_THRESHOLD = 40;  // Set the moisture threshold to 40%

void setup() {
  pinMode(MOISTURE_SENSOR_PIN, INPUT);
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW); // Initialize the relay to be off
}

void loop() {
  int sensorValue = analogRead(MOISTURE_SENSOR_PIN); // Read the moisture sensor value
  int moisturePercentage = map(sensorValue, 0, 1023, 100, 0); // Map the value to a percentage (assuming 0 is wet and 1023 is dry)

  // Check if the moisture level is below the threshold
  if (moisturePercentage < MOISTURE_THRESHOLD) {
    // Soil is too dry, open the solenoid (activate the relay)
    digitalWrite(RELAY_PIN, HIGH);
  } else {
    // Soil is moist enough, close the solenoid (deactivate the relay)
    digitalWrite(RELAY_PIN, LOW);
  }

  // Wait for a bit before reading again
  delay(1000); // Delay in milliseconds (1 second)
}

This code is designed to run on the Arduino UNO. It reads the moisture level from the soil moisture sensor and activates a relay to control a solenoid valve based on the moisture content. If the soil is too dry (below the threshold), the solenoid valve is opened to allow watering.