Arduino Soil Probe Using DS18B20 and DIY Moisture Hardware




Introduction: Arduino Soil Probe Using DS18B20 and DIY Moisture Hardware

About: Ugly pirate roaming the seas in search of Treasure.

As a fanatical gardener or a professional farmer, knowing the environmental conditions of our soil is invaluable. Obviously, we can't measure the number of worms or pieces of organic humus, but we can measure temperature and moisture content really easily.

This is not a difficult project and what you end up with is a very swanky looking bit of kit that will impress most people until you put it in the soil and it gets completely covered in dirty, sticky mud!

Step 1: Parts

  1. Resin that is used for pasting onto glass fibre
  2. Resin hardener.
  3. 6mm 316 grade stainless steel rod.
  4. DS18B20 temperature probe with water proof cable attached.
  5. 35 mm OD stainless steel tube
  6. 3mm bolts and nuts x 2
  7. 3mm wire terminals x 2
  8. Twin core cable
  9. Arduino uno

Step 2: Fabrication

I have been developing these devices for a year or so now and the use of liquid resin is incredibly effective and produces a very professional looking results.

Following the photos above:

  1. Use a 32mm hole saw to cut out a steel and a plywood disc to hold the sensor probes in place during fabrication.
  2. Flatten and drill the ends of the probes to 3mm for the electrical connections.
  3. Attach the cables.
  4. Drill three holes in the plywood disc for the two long probes on the outside and the short DS18B20 probe in the middle.

Next is a three stage process for applying the resin:

  1. Insert the plywood about 1/4 way up the body of the main tube and pour in a small amount of resin and hardener, making sure that there is plenty of space between all the electrical contacts.
  2. After the resin has set hard, turn the assembly upside down and fill the tube with resin around the three probes.
  3. After this batch of resin has set, turn it back upright and fill the top of the tube with resin.

Now test the device for short circuits with a multimeter.

Step 3: Test and Calibrate the Probe Using Arduino

The DS18B20 is easy to set up, but the wiring is counter intuitive and there are two different ways to wire it which can create more confusion.

Download and install the Dallas Temperature library (search the interweb for latest version). Then use the oneWireSearch program to find your probe's address.

Copy and paste the address into the main code in the next step.


Run the main code and immerse the soil probe in very, very wet soil - it should be a thick goo type liquid. The soil should be the same as the soil you want to monitor and it will have various salts in it that conduct electricity when wet. When the soil is dry, the conductivity dramatically reduces to almost zero.

If you look at my code, I have used a value of 0.102 to multiple against the analogue pin reading, but every soil type will be different. The probe should read 'zero' in the air or in dry soil. Extra sensitivity can be created by deciding at what point soil is actually dry, so we could just measure to that point rather than to 'absolutely bone dry', however, I have not done this in this example, just to keep it simple.

Step 4: Arduino Uno Code for Soil Probe

The code is mostly fairly straight forward but it's important to pulse the moisture probe rather than supplying a constant voltage. For one, this saves energy, but most importantly, it helps prevent the electrodes from corroding too quickly. In this example, power for the device is pulsed from pin 9.

<font color="#555555" face="Arial" style="background-color: rgb(255, 255, 255);"> </font>#include <DallasTemperature.h>

#include <OneWire.h>     

// Search for these include files on the internet and download the latest version as a zip file.
#define ONE_WIRE_BUS_PIN 10
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);
DeviceAddress Probe01 = { 0x28, 0x7C, 0x8A, 0x5D, 0x05, 0x00, 0x00, 0xFD  };  // This is the value that we got from the one wire search.
// The value above will be different for every single DS18B20 temp sensor ever made. Dont' try and use mine as it won't work!
int sensorPin = A0;    
int sensorValue = 0;  // variable to store the value coming from the moisture sensor
unsigned long moistureValue = 0;
float tempsoil;
int moisturePowerPin = 9; 
void setup() {
  pinMode(moisturePowerPin, OUTPUT);
  sensors.begin();                       // Temperature sensors DS18B20.
  sensors.setResolution(Probe01, 10); 
  Serial.println("Printing soil temperature and moisture content .......");
  delay (1000);
void loop() {
  sensors.requestTemperatures();         // DS18B20 library function call.
  Serial.print("Probe01 soil temp:  ");
  digitalWrite(moisturePowerPin, HIGH);              // Powers up the moisture sensor for 0.1 seconds to prevent corrosion.
  sensorValue = analogRead(sensorPin)*0.102;         // The sensor is calibrated by multiplying by 0.102.
  Serial.print("Moisture sensor:    "); Serial.print(sensorValue); Serial.println(" %");
  delay (100);
  digitalWrite(moisturePowerPin, LOW);
  delay (10000);
void printSoilTemperature(DeviceAddress deviceAddress) // function that prints the soil temperature.
float temp = sensors.getTempC(deviceAddress);
tempsoil = temp;
   if (tempsoil == -127.00) 
   Serial.print("Error getting temperature  ");
   Serial.print(tempsoil);    Serial.println(" degrees C");

Step 5: Final

The next thing to do would be to transmit the data to somewhere nice and warm and dry where we can sit leisurely drinking coffee and gaze in adoration at our work. I certainly don't want to be constantly having to walk over to the soil probe to look at a tiny LCD screen - I'm far too lazy for that!

This soil probe is connected to a full blown GPRS weather station module which will be featured in a separate Instructable - just as soon as I retrieve the rain gauge data from a black hole in the Arduino's memory system!

Watch this space for more weather station Instructables including testing a proper professional anemometer and wind vane and maybe even a weather station development printed circuit board.



    • Tiny Home Contest

      Tiny Home Contest
    • Metalworking Contest

      Metalworking Contest
    • Water Contest

      Water Contest

    10 Discussions

    Have you tried removing the

    delay (100);

    line and moving the line

    digitalWrite(moisturePowerPin, LOW);

    directly after the analogRead line?

    Doing so should further diminish the power consumption / corrosion rate without affecting the measurements

    1 reply

    My, my. You really did your research :-)

    I actually had not expected a drift.

    We'll get to the perfect sensor yet

    nOT REALLY LOOKED INTO IT MUCH, BUT I'm AWARE IT COULD BE A PROBLEM. Sorry - hit caps lock button - I'm not really after a super accurate results, but, just for fun, I'm going to go over to capacitance probes which will be designed and built in the dark months of winter. I guess they will be temp dependant too?

    > I'm going to go over to capacitance probes which

    > will be designed and built in the dark months of winter.

    Here's mine:

    After reading it, just to wet your appetite before jumping into designing one, I'd be willing to send you one of my spare probes and a controller board - the rest of the components will be up to you (I don't want to take any responsibility for any eventual faulty parts I bought from chinese. Haven't has any problems until now, but one never knows). The only thing I want in return is an "I built it" comment.

    PM me with your postal address if you want to have a go.

    > I guess they will be temp dependant too?

    Unfortunately, yes, though less than what I gather about the resistive probes.

    See here:

    I didn't compensate for temperature variation in my built, but they did the job for me.

    I didnt see where the metal disk you made was used. At the top I presume, where the cables come out. but why 3 holes then?

    2 replies

    Yes, sorry, this is a bit vague. There's two disks, one made in wood and the other in metal and they could easily both have been wood in hind sight. The metal one could indeed have just had 2 holes in it as it just supports the ends of the moisture probes during fabrication and is then removed. The wooden disk has 3 holes, two for the moisture probes and one for the temperature probe and gets permanently embedded in the resin.

    yes, thanks, I sort of figured that. I was thinking maybe leave the metal one in place, attached to the resin, for a nice finish :-)

    very professional look. Those bolts will last for quite a while especially when only doing intermittent measuring