NederlandsKlik deze knop voor de Nederlandstalige website

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“.

Pay attention to the + and – when placing the battery in the ESP-WROOM-02. If you put the battery the wrong way, you will damage the module!

Alcohol Detector Project
Alcohol Detector Project

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:

  1. Install the Arduino IDE
  2. Install the Arduino core for ESP8266
  3. Install the Thingpulse library
  4. Install the Brzo I2C library
  5. Connect the sensor
  6. 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.

Alcohol detector: MQ-3 sensor 
Alcohol detector: MQ-3 sensor

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:

ESP-Wroom-02 ESP8266+0,96inch OLED+18650 Batterijhouder
Tested and recommended by OneGuyOneBlog.com:

ESP-Wroom-02 ESP8266+0,96inch OLED+18650 Batterijhouder

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“.

  1. Go to menu File > Preferences, paste the URL “https://arduino.esp8266.com/stable/package_esp8266com_index.json” in the “More Board Managers URLs” box.
  2. 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.

Wemos D1 ESP-WROOM-02 OLED library
Wemos D1 ESP-WROOM-02 OLED library

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
}
Wemos D1 ESP-WROOM-02
Wemos D1 ESP-WROOM-02

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!

VNG Systems

ESP-Wroom-02 ESP8266+0,96inch OLED+18650 Batterijhouder
Tested and recommended by OneGuyOneBlog.com:

ESP-Wroom-02 ESP8266+0,96inch OLED+18650 Batterijhouder

Add a Comment

Your email address will not be published. Required fields are marked *