How to Create a Smart Garden System with Arduino
10.12.2024 - Engine: Gemini

Guide to Building a Smart Garden System with Arduino
Components:
- Arduino Uno or compatible board
- Moisture sensor
- Temperature sensor
- Relay
- Water pump
- Power supply (9V or 12V)
- Wires and breadboard
Sensors:
Moisture Sensor:
- Detects soil moisture and outputs an analog value.
- Example: Capacitance Soil Moisture Sensor
Temperature Sensor:
- Measures ambient or soil temperature and outputs digital or analog value.
- Example: DS18B20 Digital Thermometer
Watering Control:
Relay:
- Switches the water pump on and off.
- Example: 5V 1-Channel Relay Module
Water Pump:
- Pumps water to the garden.
- Example: Mini Water Pump
Wiring:
Sensors:
- Connect moisture sensor to analog pin A0.
- Connect temperature sensor to digital pin 2.
Relay:
- Connect relay coil to digital pin 4.
- Connect relay common contact to GND.
- Connect relay normally closed contact to water pump.
Power Supply:
- Connect power supply to Arduino Vin and GND.
Programming:
Code:
// Sensor calibration
const int moisture_dry = 250;
const int moisture_wet = 1000;
const int temperature_min = 15;
const int temperature_max = 30;
// Arduino pins
const int moisture_pin = A0;
const int temperature_pin = 2;
const int relay_pin = 4;
void setup() {
Serial.begin(9600);
pinMode(relay_pin, OUTPUT);
}
void loop() {
// Read sensor data
int moisture = analogRead(moisture_pin);
float temperature = readTemperature(temperature_pin);
// Check watering criteria
bool waterNeeded = false;
if (moisture < moisture_dry || temperature > temperature_max || temperature < temperature_min) {
waterNeeded = true;
}
// Turn watering on or off
if (waterNeeded) {
digitalWrite(relay_pin, HIGH);
} else {
digitalWrite(relay_pin, LOW);
}
// Print data
Serial.print("Moisture: ");
Serial.print(moisture);
Serial.print(", Temperature: ");
Serial.println(temperature);
// Wait 100ms
delay(100);
}
// Temperature reading function
float readTemperature(int pin) {
byte data[12];
OneWire oneWire(pin);
oneWire.reset();
oneWire.write(0xCC); // Skip ROM
oneWire.write(0x44); // Start temperature conversion
delay(750);
oneWire.reset();
oneWire.write(0xCC); // Skip ROM
oneWire.write(0xBE); // Read scratchpad
for (byte i = 0; i < 12; i++) {
data[i] = oneWire.read();
}
return data[1] << 8 | data[0];
}
Operation:
- Upload the code to the Arduino.
- Place the sensors in the garden.
- Connect the water pump.
- Monitor watering via the serial monitor or LED indicator.
Tips:
- Calibrate sensors for your specific garden type.
- Adjust the watering intervals based on the needs of your plants.
- Use a Wi-Fi or Ethernet shield to monitor and control the garden remotely.