O'Reilly logo

Internet of Things Programming with JavaScript by Ruben Oliva Ramos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Measuring the level of water in a recipient

Somtimes, we need to measure the level of water in a recipient, or if you want to see the level of water in a tank, it is a requirement to measure the levels of water that it has; so in this section, we will explain how to do this.

The sensor is Normally Open. When the water is over the limit, the contact opens, and it sends a signal to the Arduino board. We use pin number 2, which is a digital input:

Measuring the level of water in a recipient

We declare the variables and const in the program:

const int buttonPin = 2;     // the number of the input sensor pin 
const int ledPin =  13;      // the number of the LED pin 

We also define the states of the digital ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required