O'Reilly logo

Learn Arduino Prototyping in 10 days by Kallol Bosu Roy Choudhuri

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Smoke detector sketch - Digital I/O method

Use the following sketch for detecting smoke, based on the output captured from the MQ2 gas sensor's digital output pin. As always, avoid connecting the devices to the Arduino pins while loading the sketch.

The following code can be freely downloaded from the location mentioned in the Boot Camp section of this book. This is how the code for the smoke detector (digital I/O technique) looks:

//**********************************************************/ // Step-1: CONFIGURE VARIABLES //**********************************************************/ int smokePin = 2;          // Digital Pin number 2 for                             // connecting the smoke sensor. int buzzerPin = 8;         // Digital Pin number 8 for                              // connecting the buzzer. //**********************************************************/ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required