{"id":23847,"date":"2016-07-14T11:56:03","date_gmt":"2016-07-14T11:56:03","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=23847"},"modified":"2019-04-02T10:23:32","modified_gmt":"2019-04-02T10:23:32","slug":"guide-for-soil-moisture-sensor-yl-69-or-hl-69-with-the-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/guide-for-soil-moisture-sensor-yl-69-or-hl-69-with-the-arduino\/","title":{"rendered":"Guide for Soil Moisture Sensor YL-69 or HL-69 with Arduino"},"content":{"rendered":"<p>The soil moisture sensor or the hygrometer is usually used to detect the humidity of the soil. So, it is perfect to build an automatic watering system or to monitor the soil moisture of your plants.<!--more--><\/p>\n<p>The sensor is set up by two pieces: the electronic board (at the right), and the probe with two pads, that detects the water content (at the left).<\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-23849\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor.jpg?resize=350%2C368&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"moisture sensor\" width=\"350\" height=\"368\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor.jpg?w=600&amp;quality=100&amp;strip=all&amp;ssl=1 600w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor.jpg?resize=143%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 143w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor.jpg?resize=285%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 285w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor.jpg?resize=76%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 76w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor.jpg?resize=209%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 209w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor.jpg?resize=95%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 95w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor.jpg?resize=226%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 226w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor.jpg?resize=395%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 395w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor.jpg?resize=463%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 463w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor.jpg?resize=566%2C595&amp;quality=100&amp;strip=all&amp;ssl=1 566w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/p>\n<p>The sensor has a built-in potentiometer for sensitivity adjustment\u00a0of the digital output (D0), a power LED and a digital output LED, as you can see in the following figure.<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-23499\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/06\/labeled-sensor.png?resize=650%2C323&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"labeled sensor\" width=\"650\" height=\"323\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/06\/labeled-sensor.png?w=650&amp;quality=100&amp;strip=all&amp;ssl=1 650w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/06\/labeled-sensor.png?resize=150%2C75&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/06\/labeled-sensor.png?resize=300%2C149&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/06\/labeled-sensor.png?resize=80%2C40&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/06\/labeled-sensor.png?resize=220%2C109&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/06\/labeled-sensor.png?resize=201%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 201w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/06\/labeled-sensor.png?resize=280%2C139&amp;quality=100&amp;strip=all&amp;ssl=1 280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/06\/labeled-sensor.png?resize=479%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 479w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>You can also read this guide for the <a href=\"https:\/\/randomnerdtutorials.com\/guide-for-rain-sensor-fc-37-or-yl-83-with-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Rain Sensor FC-37 or YL-83 with Arduino<\/a>.<\/p>\n<h2>How does it work?<\/h2>\n<p>The voltage that the sensor outputs changes accordingly to the water content in the soil.<\/p>\n<p>When the soil is:<\/p>\n<ul>\n<li><strong>Wet:\u00a0<\/strong>the output voltage decreases<\/li>\n<li><strong>Dry:\u00a0<\/strong>the output voltage increases<\/li>\n<\/ul>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-23851 size-full\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=1104%2C601&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"soil moisture sensor\" width=\"1104\" height=\"601\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?w=1104&amp;quality=100&amp;strip=all&amp;ssl=1 1104w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=150%2C82&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=300%2C163&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=768%2C418&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=1024%2C557&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=80%2C44&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=220%2C120&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=184%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 184w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=276%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 276w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=437%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 437w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=750%2C408&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=895%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 895w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/soil-moisture-sensor-e1467578282801.png?resize=1093%2C595&amp;quality=100&amp;strip=all&amp;ssl=1 1093w\" sizes=\"(max-width: 1104px) 100vw, 1104px\" \/><\/p>\n<p>The output can be a digital signal (D0) LOW or HIGH, depending on the water content. If the soil humidity exceeds a certain predefined threshold value, the modules outputs LOW, otherwise it outputs HIGH. The threshold value for the digital\u00a0signal can be adjusted using the potentiometer.<\/p>\n<p>The output can be a analog\u00a0signal and so you\u2019ll get a value between 0 and 1023.<\/p>\n<h2>Example: Soil Moisture Sensor with the Arduino<\/h2>\n<p>This is a simple example for you to understand how you can use the soil moisture sensor in your projects with Arduino.<\/p>\n<p>In this example, you\u2019ll read the analog sensor\u00a0output values using the Arduino and print those readings in the Arduino IDE serial monitor.<\/p>\n<h3>Parts required<\/h3>\n<p>For this example, you\u2019ll need the following components:<\/p>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/soil-moisture-sensor-yl-69-hl-69\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x YL-69 moisture sensor\u00a0<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino UNO<\/a>\u00a0\u2013 read\u00a0<a href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best Arduino Starter Kits<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x\u00a0Breadboard<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">2x 220 Ohm Resistors<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/3mm-5mm-leds-kit-storage-box\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Red LED<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/3mm-5mm-leds-kit-storage-box\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Green LED<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper wires<\/a><\/li>\n<\/ul>\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n<h3>Pin Wiring<\/h3>\n<p>Wiring your sensor to the Arduino is pretty simple:<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"283\">Pin<\/td>\n<td width=\"283\">Wiring to Arduino Uno<\/td>\n<\/tr>\n<tr>\n<td width=\"283\">A0<\/td>\n<td width=\"283\">Analog Pins<\/td>\n<\/tr>\n<tr>\n<td width=\"283\">D0<\/td>\n<td width=\"283\">Digital Pins<\/td>\n<\/tr>\n<tr>\n<td width=\"283\">GND<\/td>\n<td width=\"283\">GND<\/td>\n<\/tr>\n<tr>\n<td width=\"283\">VCC<\/td>\n<td width=\"283\">5V<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Schematics<\/h3>\n<p>To complete the project, follow these schematics:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-23855\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=834%2C393&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"moisture sensor fritzing\" width=\"834\" height=\"393\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?w=2012&amp;quality=100&amp;strip=all&amp;ssl=1 2012w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=150%2C71&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=300%2C141&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=768%2C362&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=1024%2C482&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=80%2C38&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=220%2C104&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=212%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 212w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=280%2C132&amp;quality=100&amp;strip=all&amp;ssl=1 280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=505%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 505w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=750%2C353&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=975%2C459&amp;quality=100&amp;strip=all&amp;ssl=1 975w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor-fritzing.jpg?resize=1190%2C561&amp;quality=100&amp;strip=all&amp;ssl=1 1190w\" sizes=\"(max-width: 834px) 100vw, 834px\" \/><\/p>\n<h3>Code<\/h3>\n<p>Upload the following sketch to your Arduino board:<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n \n All the resources for this project:\n http:\/\/randomnerdtutorials.com\/\n \n*\/\n\nint rainPin = A0;\nint greenLED = 6;\nint redLED = 7;\n\/\/ you can adjust the threshold value\nint thresholdValue = 800;\n\nvoid setup(){\n  pinMode(rainPin, INPUT);\n  pinMode(greenLED, OUTPUT);\n  pinMode(redLED, OUTPUT);\n  digitalWrite(greenLED, LOW);\n  digitalWrite(redLED, LOW);\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  \/\/ read the input on analog pin 0:\n  int sensorValue = analogRead(rainPin);\n  Serial.print(sensorValue);\n  if(sensorValue &lt; thresholdValue){\n    Serial.println(&quot; - Doesn't need watering&quot;);\n    digitalWrite(redLED, LOW);\n    digitalWrite(greenLED, HIGH);\n  }\n  else {\n    Serial.println(&quot; - Time to water your plant&quot;);\n    digitalWrite(redLED, HIGH);\n    digitalWrite(greenLED, LOW);\n  }\n  delay(500);\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/soil_moisture_sensor_arduino.ino\" target=\"_blank\">View raw code<\/a><\/p>\n<p>Open the Arduino IDE serial monitor to see the values. Then, try your sensor in a wet and in a dry soil and see what happens.<\/p>\n<p>When the analog value goes above a certain threshold, a red LED will turn on (indicates that the plant needs watering), and when the value goes below a certain threshold, a green LED will turn on (indicates that the plant is ok).<\/p>\n<h2>Wrapping Up<\/h2>\n<p>The moisture sensor allows to monitor the water content in the soil. This is useful if you want to build an automatic watering system. You can also use it to just monitor your plants soil moisture.<\/p>\n<p>I hope you\u2019ve found this guide useful. Have you used this sensor in any of your projects?<\/p>\n<p>Let me know by leaving a comment below.\u00a0Share this post with a friend that also likes electronics.<\/p>\n<p>Thanks for reading,<\/p>\n<p>Rui<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The soil moisture sensor or the hygrometer is usually used to detect the humidity of the soil. So, it is perfect to build an automatic watering system or to monitor &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Guide for Soil Moisture Sensor YL-69 or HL-69 with Arduino\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/guide-for-soil-moisture-sensor-yl-69-or-hl-69-with-the-arduino\/#more-23847\" aria-label=\"Read more about Guide for Soil Moisture Sensor YL-69 or HL-69 with Arduino\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":23849,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[267,302,269,264,215],"tags":[],"class_list":["post-23847","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino-project","category-0-guide","category-guide-project","category-project","category-sensors"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/07\/moisture-sensor.jpg?fit=600%2C631&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/23847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=23847"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/23847\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/23849"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=23847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=23847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=23847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}