Book Image

Internet of Things Programming with JavaScript

Book Image

Internet of Things Programming with JavaScript

Overview of this book

The Internet of Things is taking the tech world by storm, and JavaScript is at its helm. This book will get you to grips with this exciting new technology. Where do Node.js, HTML5 and Windows 10 IoT Core come in with JavaScript and IoT? Why Raspberry Pi Zero rather than Arduino? How do you configure and build an IoT network from scratch? All your IoT JavaScript questions are answered in this book.
Table of Contents (15 chapters)
Internet of Things Programming with JavaScript
Credits
About the Author
www.packtpub.com
Customer Feedback
Preface

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...