Alcohol Detector: ESP-WROOM-02 & MQ-3 Sensor
|
With an ESP-WROOM-02 and an MQ-3 alcohol sensor you can easily make a portable alcohol detector. It will be a simpler implementation of the earlier project “Arduino breathalyzer: DIY alcohol tester with MQ-3 gas sensor and OLED display“. We also use the findings from the earlier blog “WEMOS D1 Esp-Wroom-02 and Arduino IDE“.


Alcohol detector in 6 steps
If you start from scratch then you must go through the steps below, but you probably did the first (two) before:
- Install the Arduino IDE
- Install the Arduino core for ESP8266
- Install the Thingpulse library
- Install the Brzo I2C library
- Connect the sensor
- Upload the alcohol detector sketch
If all this is successful then you have a good starting point for your own version of this project. We start by installing the Arduino IDE.


Install the Arduino IDE
We use the Arduino IDE to program the ESP8266 microcontroller. If you have not yet installed it, you can read here how to do that:
- Linux: Install or upgrade to the latest Arduino IDE on Linux
- Windows: Installing the Arduino IDE on Windows 10
Install the Arduino core for ESP8266
To add support for the ESP8266 microcontroller to the Arduino IDE, we install the “Arduino core for ESP8266 WiFi chip“.
- Go to menu File > Preferences, paste the URL “https://arduino.esp8266.com/stable/package_esp8266com_index.json” in the “More Board Managers URLs” box.
- Then go to the menu Tools > Board “xxx” > Board Management… and search for “ESP8266”. Then click on “install” at “esp8266 by esp8266 community”.
For a more detailed description, read the chapter “Installing the ESP8266 Arduino Core” in the blog “ESP8266 NodeMcu and Arduino IDE on Linux” The procedure is the same for Windows and Linux.
Install the Thingpulse library
You can install the Thingpulse library in two ways. If you want to do it manually, download the ZIP file from github. Then in the Arduino IDE go to Sketch > Use library > Add .ZIP library > choose file and select the file you just downloaded.
You can also install the library via “Library Management”. To do this, go to Sketch > Use library > Manage libraries and search for “ESP8266 and ESP32 Oled Driver for SSD1306 display“. Then click on the “Install” button.


Install the Brzo I2C Library
Install the “Brzo I2C” library in the same way. Manually, by downloading the ZIP file from GitHub and using Sketch > Use library > Add .ZIP library > choose file.
Or through “Library Management” via Sketch > Use Library > Manage Libraries, then search for “Brzo I2C” and click on the “install” button.
Connect the sensor
Then it’s time to connect the sensor to the ESP. Make sure the ESP is turned off. You connect the sensor with three wires: AD from the sensor to A0 from the ESP for the analog signal. VCC and GND of the sensor on 5V and GND of the ESP for the power supply.
MQ-3 Sensor | ESP-WROOM-02 |
AD | A0 |
DD | (not connected) |
GND | GND |
VCC | 5V |
Upload the alcohol detector sample sketch
If all of the above is successful then you can now upload the sample sketch below to the ESP-WROOM-02.
/* Alcohol detector example sketch https://oneguyoneblog.com */ #include "SSD1306Brzo.h" // Include OLED Library SSD1306Brzo display(0x3c, 5, 4); // Initialize OLED display int analogPin = A0; // Analog input is A0 void setup() { display.init(); // Initialise the display } void drawData() { // Fuction to draw the text display.setTextAlignment(TEXT_ALIGN_LEFT); display.setFont(ArialMT_Plain_16); int analogValue = analogRead(analogPin); // Read the analog sensor input (0-1023) int percentage = map(analogValue, 0, 1023, 0, 100); // Map sensor value (0-1023) to percentage (0-100) display.drawProgressBar(0, 24, 100, 5, percentage); // Draw the percentage bar (x,y,width,height,value) display.drawString(0, 0, "Alcohol: " + String(percentage) + "%"); // Print percentage display.drawString(0, 48, "ADC: " + String(analogValue)); // Print value of analog input (ADC) } void loop() { display.clear(); // Clear OLED display drawData(); // Draw the text display.display(); // Write the buffer to the display }


Improve the alcohol detector
Like most projects on this blog, this is just a basis for your own project. You can add and improve a lot yourself. A few suggestions:
- A timer on the screen that displays the warm-up time for the sensor (for example, 3 minutes)
- Use the WiFi functionality of the ESP8266 so that you can read the data with your phone
- Optimize the sketch to save energy so that the battery lasts longer
- Etc. etc.
If you have made a nice alcohol detector yourself, please let us know in the comments section below!