Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Soil Moisture Sensor
Introduction: Soil moisture sensors are important tools for monitoring and managing irrigation in agricultural and gardening applications. These sensors provide real-time data on the moisture content of the soil, allowing users to optimize watering schedules and prevent overwatering or underwatering. In this article, we will explore the functionality of soil moisture sensors and provide examples of Arduino code for utilizing these sensors in various applications.
Project: For this project, we will create a soil moisture monitoring system using an Arduino board and a soil moisture sensor. The objective is to measure the moisture level of the soil and display the results on an LCD screen. Additionally, we will implement an automatic watering system that turns on a water pump when the soil moisture drops below a certain threshold.
List of Components:
Examples: Example 1: Reading Soil Moisture Levels
// Soil Moisture Sensor Pin
const int soilMoisturePin = A0;
void setup() {
Serial.begin(9600); // Initialize Serial communication
}
void loop() {
int moistureLevel = analogRead(soilMoisturePin); // Read analog value from sensor
Serial.print("Moisture Level: ");
Serial.println(moistureLevel); // Print moisture level to Serial Monitor
delay(1000); // Delay for stability
}
This code reads the analog value from the soil moisture sensor connected to pin A0 and prints the moisture level to the Serial Monitor.
Example 2: Automatic Watering System
// Soil Moisture Sensor Pin
const int soilMoisturePin = A0;
// Water Pump Pin
const int waterPumpPin = 2;
void setup() {
pinMode(waterPumpPin, OUTPUT); // Set water pump pin as OUTPUT
}
void loop() {
int moistureLevel = analogRead(soilMoisturePin); // Read analog value from sensor
if (moistureLevel < 500) {
digitalWrite(waterPumpPin, HIGH); // Turn on water pump if moisture level is below threshold
} else {
digitalWrite(waterPumpPin, LOW); // Turn off water pump if moisture level is above threshold
}
delay(1000); // Delay for stability
}
This code reads the soil moisture level and turns on the water pump connected to pin 2 if the moisture level drops below the threshold (500 in this example).