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.
//**********************************************************/
// Step...