In this tutorial, we are going to interface an MQ2 Smoke Sensor with Surilli Basic M0. The changing analog values from the MQ2 Smoke Sensor will be visualized on the Serial Monitor of Arduino IDE.
What Is an MQ2 Smoke Sensor?The MQ series of gas sensors use a small heater inside with an electro-chemical sensor. They are sensitive for a range of gasses and are used indoors at room temperature. The MQ-2 Gas Sensor module is useful for gas leakage detecting in home and industry.
The MQ-2 smoke sensor is sensitive to smoke and to the following flammable gases:
- LPG
- Butane
- Propane
- Methane
- Alcohol
- Hydrogen
The resistance of the sensor is different depending on the type of the gas.The smoke sensor has a built-in potentiometer that allows you to adjust the sensor sensitivity according to how accurate you want to detect gas.
A0: Analog pin
D0: Digital pin
GND: Ground pin
VCC: Voltage pin
How Does It Work?The relationship between voltage and gas concentration is the following:
- The greater the gas concentration, the greater the output voltage.
- The lower the gas concentration, the lower the output voltage.
The output can be an analog signal (A0) that can be read with an analog input of the Surilli or a digital output (D0) that can be read with a digital input of the Surilli.
While in this project we will be using analog output.
Note: Don't touch the sensor. It will be very hot.
Required Hardware:- Surilli Basic M0
- MQ2 Smoke Sensor
- Connecting wires
- Arduino IDE software
Connections between Surilli Basic M0 and MQ2 Smoke Sensor:
Surilli Basic M0 --> MQ2 Smoke Sensor
- USB Pin (5V) (Surilli Basic M0) --> VCC Pin (MQ2 Smoke Sensor)
- A0 Pin (Surilli Basic M0) --> A0 Pin (MQ2 Smoke Sensor)
- GND Pin (Surilli Basic M0) --> GND Pin (MQ2 Smoke Sensor)
Make sure you have selected the right port, board and processor for the Surilli as shown in the picture below and it is programmable (compile and upload “Blink” from File>Examples>Digital>Blink onto your Surilli to check if everything is working fine).
Step 2: CircuitryThe circuitry is quite simple. Its mostly the programming. Follow the figure below to set up your hardware.
Step 3: Upload and Burn Code Onto Surilli
- Now you have completed setting up your hardware and Arduino IDE. Copy and paste the Arduino sketch given below into your Arduino IDE and hit upload.
- After the Arduino Code has been uploaded, the changing analog values of the MQ2 Smoke Sensor will be visualized on the Serial Monitor of Arduino IDE.
const int gasPin = A0; // GAS sensor output pin to Surilli Basic M0 analog A0 pin
void setup()
{
SerialUSB.begin(115200); // Initialize serial port - 115200 bps
}
void loop()
{
SerialUSB.println(analogRead(gasPin));
delay(1000); // Prints value every 1 sec.
}
Results:In my case, the analog values of MQ2 Smoke Sensor on the Serial Monitor of Arduino IDE were recorded as follows:
Note: You can make the necessary changes / modifications in the Arduino code according to your requirements and see how it reacts to different values and logic.
That’s all for now. If you have any queries, visit surilli.io or contact our support.
Comments