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 alcohol with a sensor


In this section, we will build a very cool project: Your very own Alcohol Breath Analyser. To do that, we are going to use a simple Arduino Uno board along with an ethanol gas sensor:

The following diagram shows the connection of the sensor with the Arduino:

We are now going to write the code for the project. Here, we are simply going to go over the most important parts of the code.

You can now either copy the code inside a file called Sensor_alcohol.ino, or just get the complete code from the folder for this project:

int readings=0; 
void setup(){ 
Serial.begin(9600); 
} 
 
void loop(){ 
lectura=analogRead(A1); 
Serial.print("Level of alcohol= "); 
Serial.println(readings); 
delay(1000); 
} 

When it doesn't detect alcohol, we can see the number of values that the Arduino reads:

If it detects alcohol, we see values from the analog read from Arduino as shown in the following screenshot: