<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>day67 &amp;mdash; Gerrit Niezen</title>
    <link>https://gerritniezen.com/tag:day67</link>
    <description>Maker of open-source software and hardware.</description>
    <pubDate>Sat, 02 May 2026 10:31:13 +0000</pubDate>
    <image>
      <url>https://i.snap.as/aMPXpIot.png</url>
      <title>day67 &amp;mdash; Gerrit Niezen</title>
      <link>https://gerritniezen.com/tag:day67</link>
    </image>
    <item>
      <title>Hydroponics: Measuring moisture levels and water levels</title>
      <link>https://gerritniezen.com/hydroponics-measuring-moisture-levels-and-water-levels?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[Moisture sensor&#xA;&#xA;To know when I need to water my seedlings in the propagator, I got an analogue capacitive soil moisture sensor for £3.67 (including P&amp;P).&#xA;&#xA;The pinout is a simple three-wire interface, with Vcc, ground and the analogue output pin. To read the values, I just needed to do the following in Espruino:&#xA;&#xA;const moistureSensorPin = A5;&#xA;const airMoisture = 955;&#xA;const waterMoisture = 670;&#xA;&#xA;pinMode(moistureSensorPin, &#39;analog&#39;);&#xA;&#xA;const moisture = Math.round(analogRead(moistureSensorPin)  1000);&#xA;const moisturePercent = Math.round(map(moisture, airMoisture, waterMoisture, 0, 100));&#xA;console.log(Moisture is ${moisture} ~ ${moisturePercent} %);&#xA;&#xA;if (moisturePercent &lt; 16) {&#xA;  console.log(&#39;Needs more water&#39;);&#xA;  // TODO: alarm notification&#xA;}&#xA;&#xA;To get airMoisture and waterMoisture, I took readings from the sensor when it was dry and placed in a glass of water respectively. The map() function I got from the Arduino libraries:&#xA;&#xA;function map(x, inmin, inmax, outmin, outmax) {&#xA;  // from https://www.arduino.cc/reference/en/language/functions/math/map/&#xA;  return (x - inmin)  (outmax - outmin) / (inmax - inmin) + outmin;&#xA;}&#xA;&#xA;I place the sensor directly under the rockwool cubes of the seedlings to measure the moisture content.&#xA;&#xA;Water level sensor&#xA;&#xA;To detect the height of the water level sensor, I&#39;m using a VL53L0X LIDAR sensor, that uses a laser and time-of-flight measurements to accurately measure distances between 50mm and 1200mm. It&#39;s pretty amazing that they can fit a laser and a detector into a package that&#39;s barely larger than a grain of rice.&#xA;&#xA;The sensor uses an I2C interface, so I connected the pins as follows:&#xA;&#xA;SDA pin to Espruino B3&#xA;SCL pin to Espruino B10&#xA;GND pin to ground&#xA;VIN pin to Espruino 3.3V&#xA;X pin to Espruino 3.3V (maybe not necessary)&#xA;&#xA;To set it up in Espruino, you just do:&#xA;&#xA;  I2C2.setup({ sda: B3, scl: B10 } );&#xA;  laser = require(&#34;VL53L0X&#34;).connect(I2C2);&#xA;&#xA;To then perform a measurement, you do:&#xA;&#xA;// measure water level&#xA;const distance = laser.performSingleMeasurement().distance;&#xA;if (distance   20) {&#xA;  console.log(distance, &#39;mm&#39;);&#xA;  // TODO: minimum water level notification&#xA;}&#xA;&#xA;---&#xA;I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting https://100daystooffload.com.&#xA;&#xA;#100DaysToOffload #day67 #hydroponics&#xA;&#xA;iComment on this post/i&#xD;&#xA;div id=&#34;cusdis_thread&#34;/div]]&gt;</description>
      <content:encoded><![CDATA[<h2 id="moisture-sensor" id="moisture-sensor">Moisture sensor</h2>

<p>To know when I need to water my seedlings in the propagator, I got an <a href="https://www.ebay.co.uk/itm/223412528258">analogue capacitive soil moisture sensor for £3.67 (including P&amp;P)</a>.</p>

<p>The pinout is a simple three-wire interface, with Vcc, ground and the analogue output pin. To read the values, I just needed to do the following in Espruino:</p>

<pre><code class="language-js">const moistureSensorPin = A5;
const airMoisture = 955;
const waterMoisture = 670;

pinMode(moistureSensorPin, &#39;analog&#39;);

const moisture = Math.round(analogRead(moistureSensorPin) * 1000);
const moisturePercent = Math.round(map(moisture, airMoisture, waterMoisture, 0, 100));
console.log(`Moisture is ${moisture} ~ ${moisturePercent} %`);

if (moisturePercent &lt; 16) {
  console.log(&#39;Needs more water&#39;);
  // TODO: alarm notification
}
</code></pre>

<p>To get <code>airMoisture</code> and <code>waterMoisture</code>, I took readings from the sensor when it was dry and placed in a glass of water respectively. The <code>map()</code> function I got from the Arduino libraries:</p>

<pre><code class="language-js">function map(x, in_min, in_max, out_min, out_max) {
  // from https://www.arduino.cc/reference/en/language/functions/math/map/
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
</code></pre>

<p>I place the sensor directly under the rockwool cubes of the seedlings to measure the moisture content.</p>

<h2 id="water-level-sensor" id="water-level-sensor">Water level sensor</h2>

<p>To detect the height of the water level sensor, I&#39;m using a <a href="https://www.espruino.com/VL53L0X">VL53L0X LIDAR sensor</a>, that uses a laser and time-of-flight measurements to accurately measure distances between 50mm and 1200mm. It&#39;s pretty amazing that they can fit a laser and a detector into a package that&#39;s barely larger than a grain of rice.</p>

<p>The sensor uses an I2C interface, so I connected the pins as follows:</p>
<ul><li>SDA pin to Espruino B3</li>
<li>SCL pin to Espruino B10</li>
<li>GND pin to ground</li>
<li>VIN pin to Espruino 3.3V</li>
<li>X pin to Espruino 3.3V (maybe not necessary)</li></ul>

<p>To set it up in Espruino, you just do:</p>

<pre><code class="language-js">  I2C2.setup({ sda: B3, scl: B10 } );
  laser = require(&#34;VL53L0X&#34;).connect(I2C2);
</code></pre>

<p>To then perform a measurement, you do:</p>

<pre><code class="language-js">// measure water level
const distance = laser.performSingleMeasurement().distance;
if (distance &gt; 20) {
  console.log(distance, &#39;mm&#39;);
  // TODO: minimum water level notification
}
</code></pre>

<hr/>

<p>I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting <a href="https://100daystooffload.com">https://100daystooffload.com</a>.</p>

<p><a href="https://gerritniezen.com/tag:100DaysToOffload" class="hashtag"><span>#</span><span class="p-category">100DaysToOffload</span></a> <a href="https://gerritniezen.com/tag:day67" class="hashtag"><span>#</span><span class="p-category">day67</span></a> <a href="https://gerritniezen.com/tag:hydroponics" class="hashtag"><span>#</span><span class="p-category">hydroponics</span></a></p>

<p><i>Comment on this post</i>
<div id="cusdis_thread" id="cusdis_thread"></div></p>
]]></content:encoded>
      <guid>https://gerritniezen.com/hydroponics-measuring-moisture-levels-and-water-levels</guid>
      <pubDate>Mon, 28 Sep 2020 13:35:12 +0000</pubDate>
    </item>
  </channel>
</rss>