Project Overview
This project will use an Arduino board with an ultrasonic sensor (e.g.,
HC-SR04) to measure the distance from the sensor to the tree. If the
distance falls below a certain threshold (indicating the need for water), the system will activate a water pump using a 4-channel relay module.
For each client, a convenient opportunity to purchase on the website has been created, which allows you to pick
up equipment in the selected store, get free courier delivery.
Hardware Components:
1.Arduino Uno (or any compatible Arduino board)
2.HC-SR04 Ultrasonic Sensor
3.4-channel Relay Module
4.DC Water Pump
5.External Power Supply (for the water pump, if needed)
6.Jumper Wires
7.Breadboard (optional)
8.Resistors (if needed for voltage divider)
9. 4 Channel Remot Control
10. 4 Motor & 4 wheel
If you need the components to build this project, you can visit our website Projectsrr.com to book your order or you can message us at 8302313065.
Circuit Connections:
1.HC-SR04 Ultrasonic Sensor:
VCC → 5V on Arduino
GND → GND on Arduino
Trig → Digital pin 9 on Arduino
Echo → Digital pin 10 on Arduino
2.Relay Module:
VCC → 5V on Arduino
GND → GND on Arduino
IN1 (for Relay 1) → Digital pin 3 on Arduino (Control for Water Pump)
IN2 → Digital pin 4 (Optional for additional devices)
IN3 → Digital pin 5 (Optional)
3. Water Pump:
Connect the water pump to the relay output terminals (Common and Normally Open). The relay controls the pump’s activation, switching it on or off based on the control signal.
4.Remot Control
Connect the 4-channel relay to the motor and battery.
Arduino Code:
// Pin definitions #define TRIG_PIN 9
#define ECHO_PIN 10
#define RELAY1_PIN 3 // Relay connected to the water pump
// Define distance thresholds
int distanceThreshold = 50; // Distance in cm for tree to be considered ‘dry’
long duration; int distance;
void setup() {
// Set pin modes
pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT); pinMode(RELAY1_PIN, OUTPUT);
// Initialize serial communication Serial.begin(9600);
}
void loop() {
// Trigger the ultrasonic sensor to send pulse digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW);
// Measure the pulse duration from Echo pin duration = pulseIn(ECHO_PIN, HIGH);
// Calculate the distance (in cm)
distance = duration * 0.0344 / 2; // Speed of sound is 343m/s, divided by 2 for round trip
// Print the distance to the Serial Monitor Serial.print(“Distance: “); Serial.print(distance);
Serial.println(” cm”);
// Check if the distance is less than the threshold (indicating tree is near or needs watering) if (distance > distanceThreshold) {
// If the tree is far away (needs water), turn on the pump
digitalWrite(RELAY1_PIN, HIGH); // Activate pump Serial.println(“Tree is dry! Watering the tree…”);
} else {
// If the tree is close (no need for water), turn off the pump digitalWrite(RELAY1_PIN, LOW); // Deactivate pump Serial.println(“Tree is sufficiently watered.”);
}
// Delay between readings
delay(1000); // Wait for 1 second before the next measurement
}
Code Explanation:
Ultrasonic Sensor
The sensor uses the Trig pin to send out a pulse, and the Echo pin receives the reflected pulse. The time taken for the pulse to return is measured, and using the speed of sound, the distance to the object (in this case, the tree) is calculated.
Relay and Water Pump Control:
The code checks if the distance is greater than a distanceThreshold (which represents a “dry” tree in need of watering). If the tree is far (meaning it might be dry), the relay is activated (HIGH), and the water pump turns on. If the tree is close (indicating it’s already watered), the relay is deactivated (LOW), and the pump stops.
Serial Monitor:
The distance from the sensor to the tree is printed on the Serial Monitor for debugging or observation. It also prints messages to indicate whether the tree is dry or sufficiently watered
Working Principle:
Dry Tree: When the distance from the sensor to the tree exceeds the threshold, it means the tree is far, and the water pump is activated to water the tree. Watered Tree: When the distance is within the acceptable range, indicating that the tree is close to the sensor (perhaps the tree is nearer due to the soil absorbing water), the water pump is turned off.
Circuit Diagram:
Here is a simple outline for the setup:
Ultrasonic Sensor (HC-SR04):
VCC → 5V,
GND → GND.
Trig → Pin 9,
Echo → Pin 10,
Relay Module:
VCC → 5V,
GND → GND,
IN1 → Pin 3 (Water Pump),
IN2 → Pin 4 (Optional),
IN3 → Pin 5 (Optional),
IN4 → Pin 6 (Optional),
Water Pump: Connect the water pump to the NO (Normally Open) and COM (Common) pins on the relay. The relay acts as a switch to control the power to the water pump.
Testing and Calibration:
Upload the Code: Upload the code to the Arduino board and open the Serial Monitor to observe the distance measurements. Adjust the Distance Threshold: If you want to change the threshold (distance at which the pump is activated), modify the distanceThreshold variable in the code. Observe the Pump Operation: Test the setup by adjusting the position of the ultrasonic sensor and observing the pump’s response (it should activate when the tree is “dry” or too far, and stop when the tree is “watered”).
Additional Considerations:
- Powering the Pump: Ensure that the water pump is powered by an
external power supply if it requires more current than the Arduino can provide. The relay will control the connection to this external power.
- Accuracy of Measurements: The ultrasonic sensor measures distance based on sound waves. Ensure that it is positioned properly to get aconsistent measurement. Obstacles or noise can affect the readings, so use it in an open area where possible.
- Relay Safety: If your water pump runs on AC, make sure the relay module is rated for high-voltage AC use and that proper insulation and safety protocols are followed.
-
Extensions:
- Soil Moisture Sensor: You could integrate a soil moisture sensor to further automate irrigation by measuring soil moisture along with the ultrasonic sensor’s distance reading.
- Time Scheduling: You could add a real-time clock (RTC) module to schedule irrigation times for the tree, regardless of the ultrasonic sensor readings.
- Remote Control: Add a Wi-Fi or Bluetooth module (like ESP8266 or HC-05) to control or monitor the system remotely.
Add comment