logo-mobile

ROHM

ROHM
Menu
  • Arduino –
  • Raspberry Pi –
  • Trending –
  • Others –
  • About –
  • Contact –

Arduino

How to Find Out When Your Plants Need Watering with a Soil Sensor

DevicePlus Editorial Team
Published by DevicePlus Editorial Team at January 31, 2021
Categories
  • Arduino
Tags

It’s important to keep your plants watered and healthy. However, if you struggle to remember if you’ve watered them or want to get a reminder, you can build a device to help you keep track of the moisture levels in your plant’s soil using a soil sensor. This guide will show you how.

How It Works

A soil sensor features two long probes that you insert into the soil of your plant. The probes act as a resistor. Dry soil doesn’t conduct electricity very well, so resistance will be higher. As water is added, it increases the conductivity, leading to a higher voltage returning to the Arduino. By measuring this voltage, your projects can act based on how dry or wet the soil is.

This value can then be passed to your projects and used as a variable to respond to your dry plants in whatever way works best for you. For example, you could set the project to spray your plants with water. However, to keep things simple, we’ll be building a project that will switch on an LED when it detects that water levels are too low. If you see the light on, it’s time to water the plant.

One important thing to keep in mind with sensors like this is that the metal probes can get oxidized over time and lose their effectiveness. If you use them regularly, then you may need to replace the sensor every year or so. However, they’re very cheap, so this shouldn’t be too big of a deal.

What You’ll Need

For the version of the project we’re going to make, you won’t need much material beyond what comes in standard electronics kits. However, keep in mind that if you want to deploy this in your own garden, you may need to do some extra work to make sure that your project is protected from the elements.

Arduino Uno
Moisture Sensor
LED
Breadboard & wires
Arduino IDE
USB Cable

 

If you plan on putting this project outdoors or where the Arduino is likely to get splashed with water, you may also want to buy a case for it.

The Code

The code for this project is fairly simple. Copy the below script into your IDE and upload it to your board.

int sensorPin = A0;
int moistureLevel ;
int LED = 6;
int sensorValue = 0;

void setup() {
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(sensorPin);
moistureLevel = map(sensorValue,0,550,0,100);
Serial.println(sensorValue);
delay(30);

if (moistureLevel < 50) {
analogWrite(LED, HIGH);
} else {
analogWrite(LED, LOW);
}
}

Now, let’s go over each piece of the sketch before moving onto the wiring.

int sensorPin = A0;
int moistureLevel ;
int LED = 6;
int sensorValue = 0;

First, we’ll define a few variables. The sensorPin variable will read input from the moisture sensor. The moistureLevel variable will store the final moisture level after mapping it to a more usable level, and LED will store the value for pin 6. Finally, we’ll add a variable to store the value coming off the moisture sensor.

void setup() {
Serial.begin(9600);
}

The setup section is fairly simple. Essentially, we’re just starting the serial monitor so we can see the values that the sensor outputs.

sensorValue = analogRead(sensorPin);
moistureLevel = map(sensorValue,0,550,0,100);
Serial.println(sensorValue);
delay(30);

The first line here will read the output of the moisture sensor. This value here will range from 0 to 1023, so the next line remaps it from 0 to 100, just to make it a bit more manageable. That value will then be output to the serial monitor so you can monitor it live. Finally, a brief delay is added. You can adjust this based on your needs. This won’t affect much, but in any case, moisture sensors don’t to be updated super frequently anyway.

if (moistureLevel < 50) {
analogWrite(LED, HIGH);
} else {
analogWrite(LED, LOW);
}

In the last section, we’ll take the final remapped output value from the moisture sensor and use that to turn the LED on if the plant is too dry. Anything under 50 and the LED will turn on, indicating the soil is dry. Above 50 and the LED will turn off. You can adjust this number based on what you see in your serial monitor to make sure it’s accurately reflecting the moisture values in your plant.

 

The Wiring

The wiring on this project isn’t too complicated, but you can expand on it with your own actions based on the moisture sensor’s output. For our purposes, though, we’re keeping it simple with just an LED. To connect everything:

● Connect the GND pin of the moisture sensor to GND on the Arduino.
● Connect the VCC pin of the moisture sensor to 5V.
● Connect the signal pin of the moisture sensor to pin A0
● Connect the short leg of the LED to pin 6.
● Add a 220 ohm resistor after the long leg of the LED.
● Connect the other end of the resistor to GND.

When you’re done, place the moisture sensor into your potted soil and monitor the values it returns using the serial monitor. You can make adjustments to the code based on your own needs. You can also try expanding this project by adding new parts. For example, you could set up the project to automatically spray your plants if they get to dry.

DevicePlus Editorial Team
DevicePlus Editorial Team

Check us out on Social Media

  • Facebook
  • Twitter

Recommended Posts

  • Use an Arduino to find out when to turn on your humidifierUse an Arduino to find out when to turn on your humidifier
  • Lazurite Stand-Alone Watering MachineLazurite Stand-Alone Watering Machine
  • Using Sensors with the Arduino: Create a Simple Device to Detect Movement and ReactUsing Sensors with the Arduino: Create a Simple Device to Detect Movement and React
  • An Arduino Plant Monitoring & Watering DeviceAn Arduino Plant Monitoring & Watering Device
  • How To MacGyver A Laser Tripwire Using ArduinoHow To MacGyver A Laser Tripwire Using Arduino
  • Using I2C and an Arduino Uno to Work With Analogue Voltages on a Raspberry PiUsing I2C and an Arduino Uno to Work With Analogue Voltages on a Raspberry Pi
Receive update on new postsPrivacy Policy

Recommended Tutorials

  • How to integrate an RFID module with Raspberry Pi How to integrate an RFID module with Raspberry Pi
  • How to Use the NRF24l01+ Module with Arduino How to Use the NRF24l01+ Module with Arduino
  • How to Run Arduino Sketches on Raspberry Pi How to Run Arduino Sketches on Raspberry Pi
  • Setting Up Raspberry Pi as a Home Media Server Setting Up Raspberry Pi as a Home Media Server

Recommended Trends

  • SewBot Is Revolutionizing the Clothing Manufacturing Industry SewBot Is Revolutionizing the Clothing Manufacturing Industry
  • All About The Sumo Robot Competition And Technology All About The Sumo Robot Competition And Technology
  • 5 Interesting Tips to Calculating the Forward Kinematics of a Robot 5 Interesting Tips to Calculating the Forward Kinematics of a Robot
  • Go Inside the Drones That Are Changing Food Delivery Go Inside the Drones That Are Changing Food Delivery
Menu
  • Arduino –
    Arduino Beginner’s Guide
  • Raspberry Pi –
    Raspberry Pi Beginner's Guide
  • Trending –
    Updates on New Technologies
  • Others –
    Interviews / Events / Others

Check us out on Social Media

  • Facebook
  • Twitter
  • About
  • Company
  • Privacy Policy
  • Terms of Service
  • Contact
  • Japanese
  • 简体中文
  • 繁體中文
Don’t Forget to Follow Us!
© Copyright 2016-2023. Device Plus - Powered by ROHM
© 2023 Device Plus. All Rights Reserved. Muffin group

istanbul escort istanbul escort istanbul escort