Ein Blog

Gesammelte Notizen

Puck.js as ground moisture sensor

16 Mai, 2017 | IoT

I'm proud owner of some Puck.js devices.

These devices are bluetooth beacons you can programm using java script.

Here are some of the features of the devices:

For more information see the Puck.js Homepage

I used one of the oucks to create a ground humidity logger using mqtt and node red.

Parts:

1 x Puck.js (distributors or amazon)

1 x Ground moisture sensor like https://www.amazon.de/dp/B00ZR3B60I/ref=cm_sw_em_r_mt_dp_BaUgzbNGHG84Q

1 x Raspberry pi

 

For getting started with the puck.js have look at the homepage and the quick start guide.

Also you need install the EspruinoHub BLE - MQTT software as described here.

If you use Rasbian the MQTT Broker Mosqito is already installed.

After the software is installed you can connect the Puck to the moisture sensor. VCC is connected to pin D1, GND is connected to GND on the puck and the analog output A0 is connected to pin D28 of the puck.

undefined

Now open the EspruinoWeb IDE and enter this:

var ground = 0;

setInterval( function() {
digitalWrite(D1, true);
setTimeout(function () {
var val = analogRead(D28);
ground = Math.round(val * 10);
console.log("Ground; " + ground);
digitalWrite(D1, false);
}, 500);
}, 1000);

This will read the moisture value from the sensor, the values will be between 10 = very dry and 0 = really wet. To prevent corrsion of the sensor power is supplied only before the measure is done by writing high to the pin D1. The sensor needs some time to provide a releyable reading. Therefor the setTimeout function is used. In the function the analog value is read from pin D28 and then pin D1 is set to low.

You can find a complete program that anounces the moisture value here.

Using this program I created I use this node-red flow to notify me when the plant is getting dry.

undefined

The flow is available here, you'll need to fill the values for the smtp server, the email recipient and the id of the puck to make this flow working.

If you have the ui extension of node red installed you can see this.

undefined

 I use systemd to run EspruinoHub as a Service, I create a how to in another post you'll find here.