Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Internet of Things Programming with JavaScript

You're reading from  Internet of Things Programming with JavaScript

Product type Book
Published in Feb 2017
Publisher Packt
ISBN-13 9781785888564
Pages 298 pages
Edition 1st Edition
Languages
Toc

Table of Contents (15) Chapters close

Internet of Things Programming with JavaScript
Credits
About the Author
www.packtpub.com
Customer Feedback
Preface
1. Getting Started with Raspberry Pi Zero 2. Connecting Things to the Raspberry Pi Zero 3. Connecting Sensors - Measure the Real Things 4. Control-Connected Devices 5. Adding a Webcam to Monitor Your Security System 6. Building a Web Monitor and Controlling Devices from a Dashboard 7. Building a Spy Police with the Internet of Things Dashboard 8. Monitoring and Controlling Your Devices from a Smart Phone 9. Putting It All Together

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:

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime