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

Reading and counting pulses with Arduino


In this part of the code, we explain that it counts the signals from the sensor using an interrupt, executes, and we have configured it as RISING, so it counts the pulses from digital signal zero to digital signal one:

int pin = 2; 
volatile unsigned int pulse; 
constintpulses_per_litre = 450; 
 
void setup() 
{ 
Serial.begin(9600); 
 
pinMode(pin, INPUT); 
attachInterrupt(0, count_pulse, RISING); 
} 
 
void loop() 
{ 
pulse=0; 
interrupts(); 
delay(1000); 
noInterrupts(); 
 
Serial.print("Pulses per second: "); 
Serial.println(pulse); 
} 
 
voidcount_pulse() 
{ 
pulse++; 
} 

Open the Arduino Serial Monitor, and blow air through the water flow sensor using your mouth. The number of pulses per second will be printed on the Arduino Serial Monitor for each loop, as shown in the following screenshot: