Overall, the general steps to interface the Arduino with a sensor device, as outlined in Chapter 4, Day 2 - Interfacing with Sensors, will be followed once again in this chapter. However, you will notice that for the smoke detector, we do not require an Arduino library. The reason is because the smoke detector's output can be directly read via an analog pin or via a digital pin.
For building the smoke detector project the following parts will be required:
- Arduino Uno R3
- USB connector
- 1 bread board
- 1 MQ2 gas sensor
- 1 Piezo Buzzer
- 1 pc. 100 ohms resistor
- Some male-to-male jumper wires
- Some female-to-male jumper wires
First, let us inspect the method of using the digital pin; after that we will see the method of using the analog pin. Just so you know, it may be a little difficult to trigger smoke detection using the digital pin method, compared to the analog pin method in this chapter. So, make sure the smoke density is high by using at least four to five incense sticks at a time.
Make sure there are no loose connections in the breadboard setup. Otherwise the prototype will not work. If the buzzer still does not work, then the source of smoke should be held very close to the sensor's wire mesh.
The smoke sensor will become a little hot as it stays powered on. It is normal for the MQ2 smoke sensor to become slightly warm as it stays on. Remember not to use this setup for too long. The MQ2 gas detector needs large amounts of current and it is best to use an external power supply for long duration use.
The circuit connections for building a smoke detector prototype using its digital output pin are explained and shown in the following figure 2:
Arduino Uno pin |
MQ2 gas sensor pin |
Digital I/O Pin 2 |
D0 |
5V |
VCC |
GND |
GND |
The Piezo Buzzer interfacing details are provided in the following for reference. This is the same as what we have already done in the previous chapters:
Arduino Uno pin |
Piezo Buzzer pin |
Digital I/O pin 8 (via 100 Ohms) |
Positive terminal (longer leg) |
GND |
Negative terminal (shorter leg) |
Notice how the sensor pin D0 has been connected to Arduino Uno's digital pin number D2 for this setup for using the digital I/O method depicted in the preceding figure.