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 flow sensor to calculate the volume of water


We need to take automatic measurements from the water that we're using in the home. For this project, we will use a sensor to perform this reading and make the reading of measurement automatic.

To make this project, we need the following materials:

Flow Water Sensor and Arduino UNO board:

Hardware connections

Now we have the connections for out flow sensor. We can see that it has three pins -- the red pin is connected to +VCC 5 volts, the black one is connected to GND, and the yellow pin is connected to pin number 2 of the Arduino board as seen in the following image:

Reading the sensor signal

An interrupt is used for the pulses generated by the passage of water to be accounted as follows:

attachInterrupt(0, count_pulse, RISING); 

The interruption is of type RISING counts the pulses that pass from a low state to a high:

Function for counting pulses: 
 
voidcount_pulse() 
{ 
pulse++; 
}