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:
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 signals:
// variables will change: intbuttonState = 0; // variable for reading the pushbutton status
We configure the signals of the program, inputs, and outputs:
void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input...