Building a smoke detector

The smoke detector device prototype will be built using a MQ2 series gas detector module and a Piezo Buzzer. The MQ2 series sensor is a general-purpose gas sensor: it can be used for sensing different types of gases (including LPG); today, we will use this sensor for detecting smoke.

As we have seen in the earlier chapters, a Piezo Buzzer is a small acoustic device that is capable of emitting sounds at various frequencies. In this example, we will write the corresponding Arduino sketch for detecting smoke and then buzzing the Piezo Buzzer five times at one second intervals. After completing Chapter 11, Day 9 - Long Range Wireless Communications which deals with GSM communications, you may use the GSM module with this chapter to send an SMS or dial a number automatically as soon as smoke gets detected. Wouldn't that be awesome!?

Apart from building a compound device prototype, both the MQ2 gas sensor and the Piezo Buzzer have been chosen in this example to demonstrate the usage of 5 volt tolerant peripheral devices with the Arduino Uno board.

MQ2 series smoke detectors and most Piezo Buzzers commercially available in the market operate in a voltage range that can tolerate 5 volts. Therefore, both these devices can be connected directly with the Arduino Uno pins for prototyping purposes. If the external device operates at a lower voltage as compared to Arduino Uno then directly connecting the input lines of the external device may result in some damage to the lower voltage device.

Caution:
The Arduino Uno signal pins can provide a maximum current of 40 mA and the 5V pin can provide a varying range of current depending upon the power source. As a rule of thumb to start with, do not try to extract more than 200 mA from the 5V pin. Beyond these limits damage will usually start to happen to the main board. The smoke detector setup, as a whole (~160 mA for the MQ2 heater element + ~30 mA for the Buzzer + some inefficiencies in the circuit), will consume almost around 200 mA.
Therefore, for long-term usage, the MQ2 smoke detector module should be powered from a separate power source to be safe, as it requires relatively large amounts of current. The example in this chapter is for short-term prototyping purpose only. If you intend to use the MQ2 smoke detector for a long period of time then do not power it from Arduino's 5V pin. You will learn how to use a separate power source in the next chapter.

On the other hand, the Piezo Buzzer has a rated maximum current of 30 mA. Hence a 100K resistor must be used as a protection while connecting the Piezo Buzzer to an Arduino Uno pin. The reason for adding a resistor was covered in Chapter 3, Day 1 - Building a Simple Prototype.

A typical MQ2 gas sensor, as shown in the following figure:

Figure 1: MQ2 gas sensor

The MQ2 gas sensor has four pins (some have three), but in this book, we will use the one that comes with four pins. The markings on the gas sensor are very obvious in this case. Pause for a moment and try to think which pins from the gas sensor should get connected to which pin on the Arduino board. Let us see how much we have understood so far.

You got it right! The Vcc pin needs to be connected to Arduino's 5V pin, whereas the GND pin should be connected to Arduino's GND pin. You may either use the digital pin D0 or the analog pin A0. The D0 pin may be connected to any digital pin on the Arduino board, while the A0 pin can be connected to any of Arduino's analog pins.

Let us try to attempt one more time and see whether we can recall how to read values for sensors. We can easily use the digitalRead() method to read the value on a digital pin, while we can use the analogRead() method to read the value on an analog pin.

Fundamental:
The input pins of a 5-volt device can be directly connected to Arduino's GPIO pins. This is because when the Arduino Uno pin transmits a signal at 5 volts, the signal can be tolerated and properly received and processed by the device attached to the Arduino.
If the external device operates at a lower voltage as compared to Arduino Uno then directly connecting the input lines of the external device may result in permanent damage to the external device.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.238.20