Introduction: Soil Moisture Sensor (LCD, RTC, SD Logger, Temperature)

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.

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

- Breadboard

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


Load the sketch "adjust" and change those values:

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:

- Standard adjustable charger

- 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;)

Comments

author
Angelo LawrenceL (author)2016-11-16

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?
author

Yes.

author

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

author

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


Load the sketch "adjust" and change those values"

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

author

sir.. could you help my problem sir?

author
MaheswarN (author)2016-03-28

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

author
WojciechM3 (author)MaheswarN2016-03-29

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

int soil = analogRead(potPin) ;
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?

author
MaheswarN (author)WojciechM32016-03-31

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

author
NafisN (author)2016-02-20

Any video tutorial please.

author
WojciechM3 (author)NafisN2016-02-26

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

https://www.youtube.com/watch?v=fCxzA9_kg6s

author
NafisN (author)2016-02-20

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

author
rumansa (author)2016-02-14

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

author
rumansa (author)2016-02-14

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

can you send me more info's about

please

mario

my mail mario.zacrom@gmail.com

author
alzie (author)2016-02-11

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 . . .

author
BuckCreekChick (author)2016-02-09

I need a similar tester for my eggs incubator, could this be revamp to work?

author

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

author

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.

author

What I'm building is designed to measure the soil moisture and the temperature of the air, what you need is to measure the humidity of the air, am I right? If yes, you need to change the sensors, specific sensors can be found over the internet, for example:

https://www.fasttech.com/product/1451806-dht22-am2...

So yup, there is some things which you have to change.

author
WojciechM3 (author)WojciechM32016-02-09

Or lets try the other way, do you need it to check your air humidity and temperature, as it is an egg incubator or its an egg incubator but the eggs are in the soil or sand? If the temperature is an issue, i would use something else to measure the temperature that RTC module, because i don't belive it somehow

author

the eggs are in racks, so it's the air, the humidity is what I'm looking to check, finding something accurate is my problem. I'm using a GQF cabinet Incubator with a circulating fan

author

https://www.sparkfun.com/products/10167
2% toleration, is this accurate enough? If not, then :

https://www.sparkfun.com/products/12871

Accuracy: ±0.2°C at 0°C, ±0.5°C at 100°C

author
Akin Yildiz (author)2016-02-06

very comprehensive post. are you familiar with my work, i have created many soil sensors; www.instructables.com/id/the-Plant-Doctor-family/

12246815_900302343379939_2890892495991398398_n.jpg
author
YashG (author)Akin Yildiz2016-02-09

Could you share instructions for that specific device in the photo you attached?

author
Akin Yildiz (author)YashG2016-02-09

i'm working on a new instructables post about it. please follow for updates. but in the meantime take a look at www.instructables.com/id/DIY-Smart-Plant-pot/ same wiring/components, different frame..

author
pfeerick (author)2016-02-05

Great instructable, and excellent idea to de-couple the YL-69 from the power when not measuring to prevent de-lamination and corrosion of the probes. When you get a chance, can you update the connection diagram and the instructions at Step 2 as the improved wiring is not documented there - both the diagram and written instructions still say to connect to the common power rails.

Another idea is to use galvanised nails as probes, as they are conductive (just file one end to get bare metal and solder to it), or to move away from DC, and simulate an AC supply, to completely neutralise any electron migration and prevent 'green wire corrosion'.

author
WojciechM3 (author)pfeerick2016-02-05

Is this better now ?:)

author
pfeerick (author)WojciechM32016-02-05

You've added the A0 connection for reading the sensor, but didn't you connect the moisture sensors VCC to Arduino pin 2, not the common VCC, so you could switch the power to it off when not reading it? ;)

author
WojciechM3 (author)pfeerick2016-02-06

You're absolutly right! I missed that mistake twice . I completly forgot to update the schematic with a proper connection of sensor board, its good you found that. Its updated now and connected, mistake got fixed:)

author
pfeerick (author)WojciechM32016-02-06

No worries, thanks for fixing it up so quickly :) Looks good now. And good to see the project is still evolving (the work-in-progress PCB). You might want to consider using an Arduino Nano if you're serious about doing more PCB stuff, as it is perfectly suited for this application - both in size and form.

author
arduinomaster (author)2016-02-06

Well done, great effort. Keep up the good work. And thank you for mentioning me in your instructable. I like this one, with clock and data logger and will put this on my long list to make.

About This Instructable

30,738views

403favorites

License:

More by WojciechM3:Soil Moisture Sensor (LCD, RTC, SD Logger, Temperature)Arduino LCD soil moisture sensor
Add instructable to: