The following sketch should be used for detecting smoke, based on the output captured from the MQ2 gas sensor's analog output pin. As always, avoid connecting the devices to the Arduino pins while loading the sketch.
The following code can be downloaded from the location mentioned in Chapter 1, Boot Camp. Here is the code for the smoke detector (analog I/O technique):
//**********************************************************/ // Step-1: CONFIGURE VARIABLES //**********************************************************/ int smokePin = A5; // Analog Pin number A5 // for connecting the smoke // sensor. int buzzerPin = 8; // Digital Pin number 8 // for connecting the buzzer. //**********************************************************/ ...