Experiment using a Soil Moisture Sensor and a Relay
Last updated
Last updated
This project utilizes an Arduino Uno development board along with a soil moisture sensor and a relay module to create an automated soil moisture control system. The system turns on the water pump connected to the relay if the soil moisture sensor detects a moisture level below a specified threshold. This README provides a comprehensive guide to set up and use the system effectively.
Arduino Uno
Soil moisture sensor
Relay module
Jumper wires
Water pump or similar device with appropriate power source
LED (Optional)
Ensure to connect the components as shown in the circuit diagram:
Connect the VCC and GND of the soil moisture sensor to the 5V and GND pins of the Arduino Uno.
Connect the analog output of the soil moisture sensor to the A5 pin of the Arduino Uno.
Connect the IN pin of the relay module to pin 7 of the Arduino Uno.
Connect the relay module's VCC and GND to the 5V and GND of the Arduino Uno.
Connect the water pump to the relay module.
Connect the positive leg of the LED to pin 2 of the Arduino Uno and the negative leg to the GND via a current-limiting resistor.
Upload the following code to the Arduino Uno using the Arduino IDE:
Connect the Arduino Uno to your computer via USB.
Open the Arduino IDE and paste the code above into a new sketch.
Select the appropriate board and port from the Tools menu.
Click the upload button to upload the code to the Arduino Uno.
Once the code is uploaded, the system will continuously monitor the soil moisture level detected by the sensor. If the moisture level is below the threshold (900), the relay will activate, turning on the water pump. If the moisture level is above the threshold, the relay will deactivate, turning off the water pump. The LED will provide a visual indication of the soil moisture status.
Ensure all connections are secure and correct.
Check the power supply for the Arduino Uno and the relay module.
Use the Serial Monitor in the Arduino IDE to debug and monitor the moisture readings from the soil moisture sensor.
If the water pump turns on when the moisture level is above the threshold, switch the LOW
written for the relay to HIGH
and vice versa (i.e., change digitalWrite(RELAY_PIN, LOW)
to digitalWrite(RELAY_PIN, HIGH)
and digitalWrite(RELAY_PIN, HIGH)
to digitalWrite(RELAY_PIN, LOW)
).
Adjust the Moisture Threshold: If the soil moisture level detected by the sensor is not suitable for your plants, adjust the threshold value in the code. Change the value 900
in the condition if (moisture < 900)
to the desired threshold that matches your soil and plant requirements.
Install the Arduino IDE from the official .