Turning on the relay

Last but not least, since we want to turn on a relay that will let water flow and then turn it off, the code for turning the water on after one second and off after two seconds is as follows:

var mraa = require('mraa');
var pinD2 = new mraa.Gpio(2);
pinD2.dir(mraa.DIR_OUT);
setTimeout(function() {
pinD2.write(1);
setTimeout(function() {
pinD2.write(0);
},2000);
},1000);

After a delay of one second, you'll see the  D3 relay module LED turn on and you will also hear a click. This means that the relay connection is closed, and after two seconds it will turn off and open the connection.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.22.107