How to Build a Gas Sensor to detect alcohol, ethanol, smoke in the air using a MQ-3 using ESP32, ESP8266 or Raspberry Pi Pico W for Alexa
In this section, we’ll guide you through building an gas sensor using an ESP32, Raspberry Pi Pico W or ESP8266. You’ll then be able to monitor the alcohol concentration in the air through Amazon Alexa and receive push notifications via the Sinric Pro app when the sensor detects a certain level.
Prerequisites :
- ESP32, ESP8266 x 1.
- MQ-3 x 1.
- Jumper Wires.
Quick introduction to MQ-3
The MQ-3 is a semiconductor gas sensor used in a variety of applications to detect alcohol concentrations in air. It is a low-cost, high-sensitivity sensor that is easy to use. The MQ-3 is based on the principle of tin dioxide (SnO2) semiconductor gas sensing. When alcohol molecules are present in the air, they are adsorbed onto the surface of the SnO2. This adsorption causes the conductivity of the SnO2 to change, which can be measured as an electrical signal. The MQ-3 is sensitive to a wide range of alcohol concentrations, from 0.05 ppm to 5000 ppm. It is also sensitive to other gases, such as ammonia, benzene, and toluene, but it is most sensitive to alcohol.
The MQ3 sensor requires a power supply of 5V and consumes about 800mW of current. The digital output can be connected to a ESP32, ESP8266 or Pico W to measure the alcohol concentration.
How to calibrate the sensor ?
Leave it powered on for 24-48 hours to burn it in and stabilize.
Specification sheet: MQ-3
Wiring
MCU | A0 Pin | VCC Pin |
---|---|---|
ESP32 | 34 (Analog ADC1_CH6) | 5V |
ESP8266 | A0 | 5V/VIN |
Pico W | GP26 (ADC0) | 5V |
Note: on ESP32, ADC2 (GPIO04, GPIO02, GPIO15) is unstable when Wi-Fi is being used.
Let’s verify that the sensor is wired correctly and working.
Reading when not exposed to alcohol (around 760):
When exposed to Jack Daniel’s Single Barrel Tennessee Whiskey (around 850):
Step 1 : Connect to Sinric Pro
Step 1.1 : Creating a custom device type for Gas Sensor.
Sinric Pro does not have a built-in device type for Gas Sensor so we are going to create a custom device type for Gas Sensor using Device Template feature.
- Alcohol Detected/Not Detected.
Note: You can use the device template import feature mentioned below to skip creating the full template.
-
Login to your Sinric Pro account and goto Device Templates
-
Click Add Device Template. Enter name and description as Gas Sensor and select Gas Sensor as device type
- Click Capabilities.
Here we must select the features of our Gas Sensor. We want to know whether Alcohol is Detected, Not-Detected. So let’s drag a Mode and Push Notification capability.
-
What’s Mode capability?
Mode capability can be use to represents a value out of list of predefined values. eg: current wash cycle mode of a washing machine.
-
What’s Push Notification capability?
Notification capability provides the ability to send a push notification message from the code.
Click on Configure button and setup the two capabilities like below.
Click on Save to save.
Click on Save to save the template.
Now you can see the template we just created.
Import an existing template?
If you are feeling lazy setup all the Modes values, you can use the import feature.
Paste this Template:
-
Login to your Sinric Pro account, go to Devices menu on your left and click Add Device button (On top left).
-
Enter the device name Gas Sensor, description Gas Sensor and select the device type as Gas Sensor from Your Device Templates.
-
Click Others tab and Click Save
-
Next screen will show the credentials required to connect the device you just created.
-
Copy the Device Id, App Key and App Secret Keep these values secure. DO NOT SHARE THEM ON PUBLIC FORUMS !
-
Click on Code Generator to Generate the code. Click on Download to download the code.
Step 2 : Connect to Sinric Pro
Step 2.1 Install Sinric Pro Library
2.2 Complete Code
Now you should be able to see the alcholol detected status and water level via Alexa, Sinric Pro App
Alexa, What’s the alcholol (mode name) in Gas Sensor (device name)
Troubleshooting
-
Google Home or SmartThings are not supproted.
-
Please refer to our Troubleshooting page for more details.
This document is open source. See a typo? Please create an issue