{"id":1016,"date":"2018-04-06T11:41:10","date_gmt":"2018-04-06T08:41:10","guid":{"rendered":"https:\/\/oss-it.su\/?p=1016"},"modified":"2019-08-12T18:00:08","modified_gmt":"2019-08-12T15:00:08","slug":"%d0%b8%d1%81%d0%bf%d0%be%d0%bb%d1%8c%d0%b7%d0%be%d0%b2%d0%b0%d0%bd%d0%b8%d0%b5-%d0%b4%d0%b0%d1%82%d1%87%d0%b8%d0%ba%d0%b0-%d0%b2%d0%bb%d0%b0%d0%b6%d0%bd%d0%be%d1%81%d1%82%d0%b8-%d0%bf%d0%be%d1%87","status":"publish","type":"post","link":"https:\/\/oss-it.su\/en\/1016","title":{"rendered":"Using the YL-100 Soil Moisture Sensor"},"content":{"rendered":"<p>You can find a cheap Chinese soil moisture sensor labeled YL-100. But it&#8217;s hard to find working instructions on how to use it. This article intends to fill this gap.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1012 aligncenter img-responsive\" src=\"https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_front.jpg\" alt=\"\" width=\"800\" height=\"238\" srcset=\"https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_front.jpg 800w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_front-300x89.jpg 300w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_front-768x228.jpg 768w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_front-750x223.jpg 750w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>First of all, it should be noted that this YL-100 is an analogue of the SparkFun Soil Moisture Sensor (<a href=\"https:\/\/github.com\/sparkfun\/Soil_Moisture_Sensor\">here it is its source materials, instructions, 3D models<\/a>). The YL-100 differs from the original SparkFun, probably only in the order of the location of the contacts. Usually the YL-100 sensor is sold with the following description: &#8220;3Pin Soil Hygrometer Detection Module Moisture Sensor Analog Output Arduino&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1011 aligncenter img-responsive\" src=\"https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_back.jpg\" alt=\"\" width=\"800\" height=\"237\" srcset=\"https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_back.jpg 800w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_back-300x89.jpg 300w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_back-768x228.jpg 768w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_back-750x222.jpg 750w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>The sensor requires a voltage on the VCC and GND terminals. The value from the OUT terminal will depend on the power supply voltage (3.3 to 5 volts is recommended). Below, the connection diagram and sketch for Arduino will be described, when the voltage to the sensor will be applied for 10 milliseconds, only at the moment of receiving the readings-such a scheme will protect the probe from premature oxidation. With a constant supply of power to the sensor &#8211; the probe will quickly become corroded.<\/p>\n<p>It is also strongly recommended after connecting the contacts to the sensor &#8211; it is good to damp-proof the electronic part and the switching point, when working in constant dampness this will prolong the life of the device:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1015 aligncenter img-responsive\" src=\"https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_waterproof.jpg\" alt=\"\" width=\"800\" height=\"326\" srcset=\"https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_waterproof.jpg 800w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_waterproof-300x122.jpg 300w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_waterproof-768x313.jpg 768w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_waterproof-750x306.jpg 750w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>This is the scheme of connection YL-100 sensor to the Arduino Uno with power supply on demand:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1010 aligncenter img-responsive\" src=\"https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100.png\" alt=\"\" width=\"1071\" height=\"798\" srcset=\"https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100.png 1071w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100-300x224.png 300w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100-768x572.png 768w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100-1024x763.png 1024w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100-750x559.png 750w\" sizes=\"auto, (max-width: 1071px) 100vw, 1071px\" \/><\/p>\n<p>And this is the appropriate sketch for Arduino IDE, connecting any third-party libraries is not required:<\/p>\n<p><code>\/*<br \/>\n*  YL-100 sensor Example<br \/>\n*  Based on \"Soil Mositure Basic Example\" by SparkFun Electronics, Joel Bartlett<br \/>\n*  Released under the MIT License(http:\/\/opensource.org\/licenses\/MIT)<br \/>\n*\/<br \/>\nint mositure = 0; \/\/ Value to store the humidity value<br \/>\nint YL100OUT = A0; \/\/ Variable for the number of the analog pin to which the sensor is connected<br \/>\nint YL100VCC = 2; \/\/ Variable for pin number for sensor power supply<br \/>\nvoid setup()<br \/>\n{<br \/>\nSerial.begin(9600); \/\/ Open the serial bus via USB<br \/>\npinMode(YL100VCC, OUTPUT); \/\/ Set the power pin to the output<br \/>\ndigitalWrite(YL100VCC, LOW); \/\/ Set the power level to LOW after power on<br \/>\n}<br \/>\nvoid loop()<br \/>\n{<br \/>\nSerial.print(\"Soil moisture = \"); \/\/ Print the output line prefix<br \/>\nSerial.println(readYL100()); \/\/ Get the moisture value from the function and print it<br \/>\ndelay(5000); \/\/ Delay in 5 seconds before the next data retrieval<br \/>\n}<br \/>\nint readYL100() \/\/ Function of reading data from the sensor<br \/>\n{<br \/>\ndigitalWrite(YL100VCC, HIGH); \/\/ Turn on the sensor power<br \/>\ndelay(10); \/\/ Delay of 10 milliseconds<br \/>\nmositure = analogRead(YL100OUT); \/\/ Read the value from the sensor pin OUT<br \/>\ndigitalWrite(YL100VCC, LOW); \/\/ Turn off the power<br \/>\nreturn mositure; \/\/ Return the read value<br \/>\n}<\/code><\/p>\n<p>In the Arduino IDE, you can check the performance of the sensor immediately after it is downloaded through the built-in Serial Monitor.<\/p>\n<p>The sensor readings will depend primarily on the applied voltage, as well as on the type of soil and the oxidation level of the contacts.<\/p>\n<p>A value of &#8216;0&#8217; means that the sensor is not in the soil, the commutation is broken or the soil has reached an absolute dryness (which is unlikely). With a voltage of 5 volts, the maximum value of the sensor can be about 800 (when immersed in water), at 3.3 volts &#8211; already about 500.<\/p>\n<p>That is, each individual sensor installation requires calibration. If it is necessary to standardize the output values \u200b\u200b(for example, to bring them to the usual kind of humidity percentages), you can use the <a href=\"https:\/\/www.arduino.cc\/reference\/en\/language\/functions\/math\/map\/\">built-in map() function<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1014 aligncenter img-responsive\" src=\"https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_soil.jpg\" alt=\"\" width=\"600\" height=\"800\" srcset=\"https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_soil.jpg 600w, https:\/\/oss-it.su\/wp-content\/uploads\/2018\/04\/yl100_soil-225x300.jpg 225w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can find a cheap Chinese soil moisture sensor labeled YL-100. But it&#8217;s hard to find working instructions on how to use it. This article intends to fill this gap.<\/p>\n","protected":false},"author":1,"featured_media":1013,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[23,22],"class_list":["post-1016","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-system","tag-arduino","tag-hardware"],"_links":{"self":[{"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/posts\/1016","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/comments?post=1016"}],"version-history":[{"count":6,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/posts\/1016\/revisions"}],"predecessor-version":[{"id":1077,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/posts\/1016\/revisions\/1077"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/media\/1013"}],"wp:attachment":[{"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/media?parent=1016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/categories?post=1016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oss-it.su\/en\/wp-json\/wp\/v2\/tags?post=1016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}