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

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:

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

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:

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.

Attachments

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:

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

Attachments

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!

Attachments

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

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

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

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?

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

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:

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