# Soil Moisture Sensor (LCD, RTC, SD Logger, Temperature)

35,299

404

33

As my projects evolved in my mind there comes a time to make the ideas come true and so the project below became reality. Its an Arduino based soil moisture sensor, with 16,x2 LCD, real time clock (which keeps time even if the power supply is disconnected), temperature sensor and SD data logger.

It can be very helpful with a bachelor's degree or master's degree biotechnology/biology/botanics/plant keeping projects.

The idea of the project is to build a moisture sensor, both portable and stationary (with 9V battery or supplied with a standard adjustable charger). Its going to take very short measurments every X miliseconds, depending from how you will set it. Why the measurments need to be short? Becouse there is a problem which need to be solved and got solved in an article:

https://www.instructables.com/id/Have-a-Bumper-Crop... ----- By: Robert M / ArduinomasteR

who improved my first instructable which im very grateful for:

https://www.instructables.com/id/Arduino-LCD-Soil-M... ----- By: Wojciech Marczak / WojciechM3

Those two articles became the base for my idea, how to improve it and make it even better

So the idea to make the probes last longer is to let the current only flow in a short time (2x 30 miliseconds in our case) and to turn it off for a set amount of time, for example 1,800,000 milisecounds = (30x60x1000) = 30 minutes. To set this value you need to change the delay at the very end of a project.ino file.

However, since we have the sensor which takes the measurements every X miliseconds, now we need map the values. The values will vary from 1000 and something about stable 400, However the lower the measurment the lesser is the resistance, and since the probes check the resistance between two bolts we need to make Value of 400 or similar to be humidity 100% and a bigger resistance, 1000 or above means the humidity is 0% So we need to map the values of 1000 --> 400 to be humidity 0 ---> 100%

All of those things will be done in the next steps of this instructable.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Gathering Parts

You will need:

- Arduino Uno (for example)

- Real-Time Clock (RTC) DS3231 with battery

- MicroSD + SD adapter / SD Card

- SD Module

- 16x2 LCD

- YL-69 Soil moisture sensor

- Wires

- Potentiometer, i useed 47k , but thats only because i couldnt find any 10-20k Ohm potentiometer in my parts collection

You can buy all of these really cheaps, since all of those are made in china as a mass production.

## Step 2: Connect the Parts

Now you need to connect the parts, as its shown on the picture. However every SD Card Module is a bit different, every LCD is different and every RTC is different, you need to check the manufacturer papers to be sure that you're connecting all of the cables in the correct way.

LCD:

In my sitiation, the proper way of connection is shown on the schematic and a picture (there are the name of pin outputs).

The proper way of connection in my case is:

(1) VSS < ------------------------ > Ground, GND rail on the prototype board

(2) VDD < ------------------------ > +5V rail on the prototype board

(3) V0 < ------------------------ > To potentiometer middle leg (regulated output)

(4)RS < ------------------------ >Pin 10 on Arduino board

(5) RW < ------------------------ > Ground, GND rail on the prototype board

(6) E < ------------------------ > Pin 9 on Arduino board

(7) D0 < ------------------------ > NOT CONNECTED

(8) D1 < ------------------------ > NOT CONNECTED

(9) D2 < ------------------------ > NOT CONNECTED

(10) D3 < ------------------------ >NOT CONNECTED

(11) D4 < ------------------------ > Pin 7 on Arduino board

(12) D5 < ------------------------ > Pin 6 on Arduino board

(13) D6 < ------------------------ > Pin 5 on Arduino board

(14) D7< ------------------------ > Pin 3 on Arduino board

(15) A < ------------------------ > +5V rail on the prototype board

(16) K < ------------------------ > Ground, GND rail on the prototype board

SD Card Logger:

The schematic of connection:

GND < ------------------------ > Ground, GND rail on the prototype board

+5V < ------------------------ > +5V rail on the prototype board

CS < ------------------------ > Pin 4 on Arduino board

MOSI < ------------------------ > Pin 11 on Arduino board

SCK < ------------------------ > Pin 13 on Arduino board

MISO < ------------------------ > Pin 12 on Arduino board

YL-69 board:

We are only going to use 3 pins:

- VCC < ------------------------ > Pin 2 on Arduino board

- GND < ------------------------ > Ground rail on the prototype board line

- A0 < ------------------------ > Analog Pin A0

We are not going to use D0, its a digital output, there is no need to us to use it in this project and we... won't use it.

RTC DS 3231 + battery

Battery is needed to keep time when the main power source is disconnected. The pins we will use are:

- SCL < ------------------------ > SCL (on Arduino board)

- SDA < ------------------------ > SCA (on Arduino board)

- VCC < ------------------------ > +5V rail on the prototype board line

- GND < ------------------------ > Ground, GND rail on the prototype board

Potentiometer

Its use to set the proper current value to adjust the LCD display. If there is no letters show on the LCD and you're sure they should, manipulate the potentiometer and it will appear if its connected properly.

## Step 3: Set the Time

When you use your RTC for the first time you need to set it up. You won't need it later, but the first setup is needed and crutial. To set the time you're going to need Sodaq DS3231 library.

You can get it thru "add library" option in arduino program. Just click add library and type "3231" And you ll have it shown. You need to install it now.

However:

If there is no Sodaq DS3231 library to install use this link to GitHub:

https://github.com/SodaqMoja/Sodaq_DS3231

DateTime dt(2011, 11, 10, 15, 18, 0, 5);

in that order:

"year, month, date, hour, min, sec and week-day(starts from 0 and goes to 6)"

with the correct ones.

You only need to do it once. If thats done, the time is set.

## Step 4: Code

If everthing is connected you need the code! And thats why i prepared a file with the sketch and a HUGE amount of comments about what are we doing in the different sections. I also decided to take the measurements of the temperature, since an DS3231 have also an abbility to measure the temperature, so it would be a waste not to use it, when we can also dump it into SD card.

There is also another library you need to install, in "DS3231.rar"

Standard Project version is made to cooperate with serial monitor and SD card, which means it wont work without serial monitor connected. Its not the greatest idea, when you want your device to be portable, thats why i made another sketch, which doesnt require serial monitor to be opened and doesn't use it for anything. That makes the code simplier, so thats also nice. Portable.rar includes the code for a portable version, which doesnt use Serial Port, as it's not needed in portable version.

Important part of the code are the lines which effects with 3 letters in the right-bottom part of the screen. Those letters are :

- "I" from "initialized", indicates that the SD card is present

- "E" from "Error", indicates that the card is NOT present

- "F" from "False", indicates that the file is NOT available, but the card is present.

Those 3 letters are written, to help you diagnose the problem if it occures.

## Step 5: Add the Power Supply.

You also need the proper power supply, and the choice depends from the future use of your device.

You can use:

- 9V battery with the connection wires.

The choice of your power supply is a very important point of the project, if you plan it to be a stationary device much better decision would be to use adjustable charger. However if you want it portable, the battery is your only choice. However there is also another trick to be used with the portable devices, also given to us by:

https://www.instructables.com/id/Have-a-Bumper-Crop... ----- By: Robert M / Arduinomaster

The trick is to dim the LCD if its not needed, you can check our his short code to get howto dim the screen. I didnt use it, because i decided thats not necessary for my project, however that might be a next point of interest in makeing the device work better in the portable version. For my Master's thesis i need it stationary, and thats how i build it. However its important to note, that it CAN be portable.

## Step 6: SD Cards Selection

I found out that some of the SD cards dont want to work properly with my model of SD Card module.

From the expirience i can answer for at least two questions.

1. Do all of them work? No, they dont. Some cards just dont want to cooperate with us. I found out that the ones which dont want to cooperate are SDHC. Normal SD cards (also microSD in SD standard) works just fine, but that might be true just for my cards. Some of the cards work good, other cards dont work at all or work, but you can't save anything on them and the data crush everytime you attempt to unplug the SD card from the SD module.

2. Is there any difference if its SD card or a microSD + adapter? No. As far as my expirience shows there is completly no difference. Both work for me. However, as my favorite teacher says:

"However you can't always belive in lifetime expirience, because a lifetime expirience show us that always someone else who dies. And we know that is only partly true, because there will be our day one day" S. Michalkiewicz

And with that positive accent i would like to end This instructable. Once again big thanks to Arduinomaster for an oppurtunity for a cooperation.

Build it, use it!:)

## Step 7: Continue!

I'm going to continue the work as my project is still evolving, there is still a PCB and a wooden box needed, stay tuned!

## Step 8: PCB | EXPERIMENTAL, NOT FINISHED YET (MIGHT NOT WORK!)

I also decided that it needs a PCB to connect everything with minimal use of wires. I decides so because i have a lot of PCB's and only a few wires. And there is no sense in buying a new breadboard and wires, when i can make a PCB. Unfortunately for me, but good for you is that i have only single sided PCB's, so we have to use some wires connected from the bottom of my PCB.

This are the projects of the PCB, As a ,fzz (Fritzing project file), Exported as PDF in PCB.rar in different layers, normal one with and without marked connections (needed because of that the PCB i have is only single sided) and a black on white to print that on

## Step 9: Arduino Nano PCB Version.

I also made a PCB project for Arduino Nano. Mind to properly connect the arduino and the modules to the board, because its very important not to connect anything wrong to the PCB. Double-check everything before assembly!

## Step 10: Plywood Box

Well, we also need to storage our device somewhere, thats why we need a siutable box.I decided to make a plywood box with a frame for LCD and a sensor comeing out from our box on its right side. First of all you need to decide what size of a box are you looking for. Im willing to use 15x10,9 cm PCB, so i obciously need to have at least that much space inside the box. Later i ll add the schematics of the plywood cuts.

## Step 11: End of the Project

As for the end of this instructable, I would like to share the final version of my device. Photos included;)

Participated in the
Digital Life 101 Challenge

## Recommendations

• ### Internet of Things Class

22,781 Enrolled

## 33 Discussions

hello , i am doing the same project as you said in the blog can you please help me with the errors like as:
exit status 1
no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)'
and exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560

Hi, good work
I want you to help me with similar project adding to the your project the humidity sensor to be able to collect data
Best regards

It already collects data and store them on SD card.

sir,

im just a novice on this arduino project.

i just wanna ask if the codes given in this project can also be used in

Arduino Nano?
4 replies

sir.. im already making this project.. tnks to you..
but its a half bake..
coz i dont know how to adjust the time just like what you written above.. what part of the program i that i should change or adjust..could you give example please?

by the way.. can 4gb or 8gb SD card can be used in this project? coz i have a problem on mounting the SD card.. it cant be detected in the SD module

Everything is explained in the instructable.

"

To set the time you're going to need Sodaq DS3231 library.

You can get it thru "add library" option in arduino program. Just click add library and type "3231" And you ll have it shown. You need to install it now.

However:

If there is no Sodaq DS3231 library to install use this link to GitHub:

https://github.com/SodaqMoja/Sodaq_DS3231

If you still need help, contact me in private message.

I have done with the project. When it comes to the output soil containing more water content let's say showing 27% when it comes to dry soil is showing 85% what's wrong with this.sir,please answer my question as i am doing this as my major project for my course

2 replies

You need to have something wrong in the values mapping section of the arduino code.

soil = constrain(soil, 400, 1000); // We get the values between 400 and 1000, thats why we need to map the values
soil = map(soil, 400, 1000, 100, 0); // to make lower numbers a bigger percent, and to map them im range of 1 to 100.

Arduino reads the low moisture as ~1023 and high as around 300-400. Thats why we need to map the values, so they will vary between 0-100 % and 100% is 300-400 value and 0% is around 1000 (1023). Its a simple convertion of values to get what we aim to :) So thats probably the section that is wrong. What method u made it with? Breadboard of PCB?

I had done first with bread board and than I did in pcb. Finally got the output. Can you please help me about the temperature values and what is the temperature shown on the lcd.as i want to show my project to my professor

This should help, borrowed from youtube, for the moment i dont have enough time to make a video tutorial

I don't know how to code...so pls help ..

produce hot water of course ..from 50 to 65 degreecelsius

really nice project, we need a similar one to test umidity, temperatures , oxygen and water flux for a new project related to produce water from brushwood

mario

my mail mario.zacrom@gmail.com

Nice project!

But, bear in mind that at low frequency,

youll be seeing the ionic conductivity of the soil,

not just the water content.

To see only the water content,

one must look at the permittivity ( capacitance) of the water only.

The capacitance of the water and the ionic conductivity

give crossover frequencies from 250K to 4MHz.

Eg. you need to measure >>4MHz to see only the water.

Hmmm . . .

What do you want to measure? Air humidity, temperature? light? For all of them answer is yes

will I need to change anything? light isn't important but the humidity and temp is, I need to be very accurate with the temp.