Professional Documents
Culture Documents
FeaturedWrite an Instructable
Login | Sign Up
ClassesContestsForumsAnswersTeachers
Autodesk: Make Anything
Arduino Soil Moisture Sensor by innovativetom in sensors
Download 6 Steps Share Favorite I Made it! Collection
Introduction: Arduino Soil Moisture Sensor
***Edit***
This Instructable is old. I have not had the time to update any of the information.
You will find a lot of GREAT information in the comments please read them after
reading the instructions.
Intro
In this instructable I will show you how to connect the an Arduino Nano and a
moisture sensor. The information will then be displayed with 5 LEDs. This is very
easy build and I would class it as a beginner project.
1 - Breadboard (http://www.ebay.com/itm/171705651308?ssPageName=ST...
5 - LEDs
5 - 1k resistors
~8 - Assortment of jumpers.
Step 2: Arduino
The Code:
<p>/* </p><p>Innovativetom.com
Flower Pot Soil Mosture Sensor</p><p>A0 - Soil Mosture Sensor
D2:D6 - LEDS 1,2,3,4,5</p><p>LED1 - Green
LED2 - Green
LED3 - Green
LED4 - YELLOW
LED5 - RED</p><p>Connect the Soil Mosture Sensor to anolog input pin 0,
and your 5 led to digital out 2-6</p><p>*/
int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;</p><p>int mostureSensor = 0;</p><p>void setup() {
// Serial Begin so we can see the data from the mosture sensor in our serial
input window.
Serial.begin(9600);
// setting the led pins to outputs
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
}</p><p>// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(mostureSensor);
// print out the value you read:</p><p> Serial.println(sensorValue);
***Edit***
Connect the cathode or (-) lead from the LED to the Arduino.
**Here you must put a 1k resistor between anode (+) and the positive rail.
Connect the anode or (+) lead from the LED to the + positive rail of the beadboard.
**
Step 4: Wiring
From the arduino ground pin connect a short jumper to the blue rail on the
breadboard.
From the arduino 5v Pin we connect a short jumper to the red rail on the
breadboard.
Connect the ground to the ground rail, power to the power rail.
Connect the "AC" Labeled pin on the moisture sensor to analog input 0 pin on the
Arduino.
*note, the moisture sensor I have has two outs one labeled "AC" and one labeled
"DC". The "AC", is a serial signal 0-5 volts that when fully dry it outputs 5
volts, when fully wet, 0 volts. The "DC", is configured with the trim pot and is
brought high when the moisture level reaches a desired point.
Code On Github
Innovative Tom
eBay Link
Comments
Post a comment
Be nice! We have a be nice comment policy.
Please be positive and constructive. I Made it! Add Images Post Comment
AniqaEReply2017-11-21
What are the units of output readings ? Help please
joyangReply2016-02-26
Hi! Nice work. How did you select the sensor value ranges? And what is the unit of
measurement? Are the output values voltages or some capacitance values?
AniqaEjoyangReply2017-11-21
Did you find your answer ?
here's the photos, didn't use a resistor, but did use a arduino uno.
https://github.com/johnantoni/arduino/tree/master/moisture-5-leds
her
So_FARAwayJohnG623Reply2017-10-28
Hey! Thanks for posting the pictures, I just have a question, did you use the code
provided or did you change it?
JohnG623So_FARAwayReply2017-10-30
I modified some of the code, have all the source code on github
https://github.com/johnantoni/arduino
documented it all to make it easy, let me know if you get into any problems
happy to help
twitter.com/johnantoni
amit_123456Reply2017-10-30
can anyone help me in uploading this program in arduino as this is showing some
error
So_FARAwayDavidP788Reply2017-10-23
Hey! Thank you for posting the pictures, I'm new to this and was very cofused as I
also only have a adruino uno. I was just wondering if you used the code provided or
if you wrote your own, if you did, would it be possible for you to post it, as my
code somehow doesn't seem to be working.
WirelessGuyNReply2017-07-23
Trying to lean on the experience of others who've been through this before...
Does anyone know if there are samples outthere for interfacing the TE215 sensor
with the analog input of something like the NodeMCU?
I'd like ot take continual readings and ship it up to a server for collection.
I have somehting of a sample for doing this with a temp sensor but not something
like this one. I'll include the temp info below. I guress I'm kind of lost with the
mV value to temp conversion, although I guess I could just pick somehting random
for dry versus wet.
Sample:
DougL56WirelessGuyNReply2017-09-27
> Does anyone know if there are samples outthere for interfacing the TE215 sensor
with the analog input of something like the NodeMCU?
Sensor: https://www.banggood.com/Soil-Hygrometer-Humidity-...
The analog output from this particular sensor only varies from about 4.5v dry to
2.5v immersed in a glass of water, so the corresponding analogRead values from A0
have a more limited range than 0..1024.
The only change in your code would be to include the NodeMCU pin definitions:
#ifndef D1
#define D0 16
#define D1 5
#define D2 4
#define D3 0
#define D4 2
#define D5 14
#define D6 12
#define D7 13
#define D8 15
#define D9 3
#define D10 1
#endif
nk23Reply2017-06-06
Just want to know ,how can we transmit this data from the sensor ?what are the
communication options available?
Thanks in advance.
NK
karpadaReply2017-05-31
// Simpler led control
#include <SoftwareSerial.h>
#include <BlynkSimpleStream.h>
WidgetLED led1(V1);
WidgetLED led2(V2);
WidgetLED led3(V3);
WidgetLED led4(V4);
WidgetLED led5(V5);
int a;
int humiditya;
void setup()
// Debug console
DebugSerial.begin(9600);
Blynk.begin(Serial, auth);
void loop(){
Blynk.run();
a = analogRead (A0);
lcd.print(0,0, a);
lcd.print(0,1, humiditya);
if (a >= 820)
led1.on();
led2.on();
led3.on();
led4.on();
led5.on();
led1.on();
led2.on();
led3.on();
led4.off();
led5.off();
led1.on();
led2.on();
led3.off();
led4.off();
led5.off();
led1.on();
led2.off();
led3.off();
led4.off();
led5.off();
led1.off();
led2.off();
led3.off();
led4.off();
led5.off();
delay(2000);
lcd.clear();
SteveB15Reply2015-04-12
Nice job but it does need a few simple refinements to make it practical...
Add 1K resistors to the LEDs and correct the code so that the red LED will light.
The probe only needs to be on while a reading is taken, so poll the probe for one
second every half hour by driving it from a digital pin. In my example code I used
D7. This greatly improves power consumption and extends the life of the probe by
several orders of magnitude since damage by electrolysis will be insignificant. If
you want to check after watering, just press reset for a new reading.
Here's my modified code with probe polling:
/*
Innovativetom.com
stevebrace.co.uk
LED1 - Green
LED2 - Green
LED3 - Green
LED4 - YELLOW
LED5 - RED
*/
int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int probe = 7;
int mostureSensor = 0;
void setup() {
// Serial Begin so we can see the data from the mosture sensor in our serial input
window.
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(probe, OUTPUT);
void loop() {
digitalWrite(probe, HIGH);
delay(1000);
Serial.println(sensorValue);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(probe, LOW);
MaddisonA1SteveB15Reply2017-03-23
COULD YOU PLEASE SEND ANY PHOTOS YOU HAVE OF THIS SETUP. thanks
ABHINAV REDDYSteveB15Reply2015-05-23
Can u give me the code if I want to place relay instead of led.plz. // ........ Is
that the part of coding
SteveB15ABHINAV REDDYReply2015-05-23
Abhinav, just use the code as is but drive the relay from your desired digital pin
through a transistor. Don't forget to place a reverse bias diode across the relay
coil to protect against back EMF.
ABHINAV REDDYSteveB15Reply2015-05-23
Thanks
//power the probe etc
Is that the part of code,which transistor should I use
JasonEdinburghABHINAV REDDYReply2015-05-24
if you use a relay module like this then it has the transistor and diode already
http://img.dxcdn.com/productimages/sku_319093_1.jp...
I found with mine that it was a LOW signal that caused the relay to engage. (not a
high signal as I expected). It also needed just under 5v to work. Read the
datasheet info on whichever module you use.
froKoJasonEdinburghReply2017-01-01
Yep, and "active low" relays are way more common than "active high" ones.
OleP1SteveB15Reply2016-11-24
It's abselutt critical to turn off the moisture sensor.
If you only have 1 or 2 sensor you can get away with using a digital pin as power.
Im new to both coding and arduino, but for anyone intereseted her is my setup
https://github.com/oleost/WaterSystemArduino
AdeVSteveB15Reply2016-02-28
You could save a bunch of code by using a switch() statement with "fall-through" to
set your LEDs... I haven't tested this code, so it might need debugging, but here's
what I'd do:
switch(sensorValue) {
case >= 820:
digitalWrite(led5, HIGH);
// normally we'd put "break;" here to exit the select
case >= 615:
digitalWrite(led4, HIGH);
case >= 410:
digitalWrite(led3, HIGH);
case >= 250:
digitalWrite(led2, HIGH);
case >= 0:
digitalWrite(led1, HIGH);
}
By excluding the break; after each case statement, the code "falls through" and
runs all the other cases as well. But it only runs from the first case that
matches, so if the sensor value was 255 for example, the first matching case is
"case >= 250", so LED2 comes on. The code falls through from there & also turns
led1 on. Since all LEDs were turned off at the start, leds3, 4 and 5 remain off.
HTH!
DaveS101SteveB15Reply2016-01-06
hey steve instead of using delay would it not be better to use a blink without
delay method as not to tie up the processor if it is in the middle of a delay you
lose all other functions till the delay is over, way better to time it with
millis(); function then you can respond to interrupts like button pushes or sensor
inputs it is always best to not use delay
setup
long previousMillis = 0;
main loop
previousMillis = currentMillis;
else
DaveS101DaveS101Reply2016-01-06
//working program you can use more millis(); timers for the sensor delays i
//just //did not have time to work it up yet i can post it later but the odds
of //hitting the delay during a button push are 1 in 500 with 2ms delay i
consider //this acceptable i have not noticed any trouble from it
int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int probe = 8;
int sensorValue = 0;
long previousMillis = 0;
void setup()
{
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(probe, OUTPUT);
//get and display startup reading before main loop to the serial monitor
digitalWrite(probe, HIGH);
delay(1000);
int sensorValue = analogRead(moistureSensor);
Serial.println(sensorValue);
digitalWrite(probe, LOW);
void loop()
{
digitalWrite(probe, HIGH);
delay(2); //super small delay may need to be higher depending on your arduino or
launchpad board you are using some take 200 miliseconds to get accurate analog
reading
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(probe, LOW);
}
}
SteveB15DaveS101Reply2016-01-06
Thanks for taking the time to make, not only constructive criticism, but also
posting your solution. This is exactly the kind of input we like!
abdullahh52Reply2017-02-27
Where would you get those specific resistors from?
mohini jenaReply2017-02-05
Can anyone make water sensor without using transistor??
ChhitKReply2017-02-02
Can you tell me about the unit of sensorValue? Do you know about the ISO unit of
soil moisture?
BreadboredReply2016-11-21
Hello Tom
The AC and DC you refer to are in fact AO and DO (Analogue Output and Digital
Output).
AlexanderS230Reply2016-11-17
I want to built this Project and connect it with a little monitor, but i wonder
what the Lifespan of the Sensor is. If you check the Moisture every half an hour.
PekY1Reply2016-11-10
Hello everyone mind helping out this amateur here, does anyone know how much power
it needs to run this set-up? I wanted to power this set-up using a micro hydro
generator, i have calculated the amount of watts my generator is able to produce
but i have no idea if its enough to power it up =(
JonathanM257Reply2016-11-07
Hi !! My sensor is showing 870 value when not in the water :s Someone knows why
plz? :s
PekY1emirbyildizReply2016-10-20
Hello, do you mind showing a photo with the water pump motor and solar panel?? my
group is having a project based on it and it would greatly help alot if we could
see it!
emirbyildizPekY1Reply2016-10-21
Dear PekY1, it is my pleasure. I will upload photos today.
PekY1emirbyildizReply2016-10-21
Thank you very much!!!
Jorge DominicGReply2016-07-31
what is the range of this soil sensor
CarlG50Jorge DominicGReply2016-09-20
0 to 1000 idealy but i had 250 - 1023 (1000+ means disconnected)
I was using at the time the sensor YL-69 which comes with the relay YL-38
Gideon RossouwvReply2016-08-30
Hi, thanks for this. I needed to know how to use the sensor. Thanks to you I do
now!
Steven_SmartyReply2016-08-21
Can I make this project with Arduino Uno?
MattW37Reply2016-06-12
Hi, mostly new to this but I think some errors posted in the code when you copied,
unless its just the uno that has problem but it appears that html paragraph code
was placed throughout which causes problems in the compiler (<p>)
mojoj1Reply2016-05-24
hello, what is the function of those LED? why is there too many? and if the plant
is lack of water, what signal will the arduino gives and what if there is too much
water or the water is enough already? please help me, im new in this arduino.
An accountReply2016-04-22
I'm using a moisture sensor for a project. Thanks for the awesome tutorial!
d_jackReply2016-04-13
Hi all, great setup you have here. Firstly I am new to a lot of this and have
forgotten a lot of what I used to know so hopeing someone can help with a problem I
have. I have built a watering system using this ....
http://www.ebay.com/itm/391289602060?_trksid=p2055119.m1438.l2649&ssPageName=STRK
%3AMEBIDX%3AIT I have kept it basic just using this board to switch solenoids
directly. I have also used one of these boards as a floatless switch to turn on a
drain pump in a sump in case of flooding however as soon as the level drops past
the probe it starts a nasty echo pulsing the pump on and off till the level drops
clear enough not to retrigger the sensor. What I want to do as add an electrolytic
to the output transister on the board that switches the relay to give me 2-5
seconds of run on to let the water clear the probe. Could someone please suggest a
simple way to do this and component values? Thankyou in advance! Dave
hunsnowboarderReply2016-04-13
Nice instructable. Maybe switch case would be more practical instead of if/elseif.
More Comments
About This Instructable
253,543views
227favorites
License:
author
innovativetom
Innovative Tom
Follow77
Bio: As a young lad Tom spent most of his days at the heels of his father, working
in their shop, also known as the basement ... More
More by innovativetom:
WiFi Bathroom Humidity Sensor W/Fan Control, App & AutomationTable Top Tiki Torch!
Recycle Your Beat Up Tiki Torch.How to Mount a Poster or Print to Plywood Panel
robot
Newsletter
Let your inbox help you discover our best projects, classes, and contests.
Instructables will help you learn how to make anything!
enter email
I'm in!
About Us
Who We Are
Advertise
Contact
Jobs
Help
Find Us
Facebook
Youtube
Twitter
Pinterest
Google+
Resources
For Teachers
Residency Program
Gift Premium Account
Forums
Answers
Sitemap
Terms of Service|Privacy Statement|Legal Notices & Trademarks|Mobile Siteautodesk
2017 Autodesk, Inc.