Skip to main content
ESPBoards

ESP32 MiCS-4514 Dual Gas Sensor

The MiCS-4514 is a dual gas sensor capable of detecting oxidizing gases (e.g., NO₂) and reducing gases (e.g., CO, NH₃). It provides analog outputs for gas concentration, making it ideal for air quality monitoring, HVAC systems, and industrial safety applications.

Jump to Code Examples

Arduino Core Image
ESP-IDF Image
ESPHome Image
PlatformIO Image
MicroPython Image

Quick Links

MiCS-4514 Dual Gas Sensor Datasheet ButtonMiCS-4514 Dual Gas Sensor Specs ButtonMiCS-4514 Dual Gas Sensor Specs ButtonMiCS-4514 Dual Gas Sensor Specs Button

MiCS-4514 Price

Normally, the MiCS-4514 Dual Gas Sensor costs around 25$ per piece.
The prices are subject to change. Check current price:

Amazon com

Amazon de logo

Aliexpress logo

About MiCS-4514 Dual Gas Sensor

The MiCS-4514 is a dual-sensor device designed for gas detection in air quality monitoring and industrial applications. It can detect oxidizing gases like NO₂ and reducing gases like CO, NH₃, CH₄, ethanol, and hydrogen. The sensor has two independent sensing elements, each with its own heater and sensitive layer, allowing for simultaneous detection of oxidizing and reducing gases. The analog voltage output is proportional to the gas concentration, which can be read by an ADC in a microcontroller.

MiCS-4514 Sensor Technical Specifications

Below you can see the MiCS-4514 Dual Gas Sensor Technical Specifications. The sensor is compatible with the ESP32, operating within a voltage range suitable for microcontrollers. For precise details about its features, specifications, and usage, refer to the sensor’s datasheet.

  • Protocol: Analog
  • Operating Voltage: 5V DC
  • Power Consumption: 56 mW (typical)
  • Detection Range (CO): 1–1000 ppm
  • Detection Range (NO₂): 0.05–10 ppm
  • Detection Range (NH₃): 1–500 ppm
  • Response Time: < 15 seconds (typical)
  • Output Type: Analog voltage
  • Dimensions: 14mm × 14mm × 8mm

MiCS-4514 Sensor Pinout

Below you can see the pinout for the MiCS-4514 Dual Gas Sensor. The VCC pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND pin is the ground connection and must be connected to the ground of your ESP32!

The MiCS-4514 pinout is as follows:

  • Pin 1 (Vcc): Power supply input (5V).
  • Pin 2 (GND): Ground connection.
  • Pin 3 (Reducing Gas Output): Analog voltage output for reducing gases.
  • Pin 4 (Oxidizing Gas Output): Analog voltage output for oxidizing gases.
  • Pin 5 (Heater Control): Heater control input (PWM).
  • Pin 6 (Heater Ground): Heater ground connection.

MiCS-4514 Wiring with ESP32

Below you can see the wiring for the MiCS-4514 Dual Gas Sensor with the ESP32. Connect the VCC pin of the sensor to the 3.3V pin on the ESP32 or external power supply for power and the GND pin of the sensor to the GND pin of the ESP32. Depending on the communication protocol of the sensor (e.g., I2C, SPI, UART, or analog), connect the appropriate data and clock or signal pins to compatible GPIO pins on the ESP32, as shown below in the wiring diagram.

To interface the MiCS-4514 with a microcontroller, connect Vcc to a 5V power supply, GND to ground, and the Reducing Gas Output and Oxidizing Gas Output to analog input pins on the microcontroller. For heater control, connect the Heater Control pin to a PWM-enabled digital output pin. Ensure that appropriate current-limiting resistors are used for heater operation.

The MiCS-4514 offers a compact design with low power consumption and fast response time, making it suitable for portable devices, HVAC systems, and IoT applications. Its dual-element architecture provides flexibility for multi-gas detection in a single device.

Code Examples

Below you can find code examples of MiCS-4514 Dual Gas Sensor with ESP32 in several frameworks:

Arduino Core Image

ESP32 MiCS-4514 Arduino IDE Code Example

Example in Arduino IDE

Fill in your main Arduino IDE sketch file with the following code to use the MiCS-4514 Dual Gas Sensor:

#include <Wire.h>

const int reducingGasPin = 19; // Analog input for reducing gas
const int oxidizingGasPin = 18; // Analog input for oxidizing gas
const int heaterPin = 5; // Digital output for heater control

void setup() {
Serial.begin(9600);

// Configure heater pin
pinMode(heaterPin, OUTPUT);
digitalWrite(heaterPin, HIGH); // Turn on the heater
}

void loop() {
int reducingGasValue = analogRead(reducingGasPin);
int oxidizingGasValue = analogRead(oxidizingGasPin);

// Convert analog values to voltage
float reducingGasVoltage = reducingGasValue * (5.0 / 1023.0);
float oxidizingGasVoltage = oxidizingGasValue * (5.0 / 1023.0);

Serial.print("Reducing Gas Voltage: ");
Serial.print(reducingGasVoltage);
Serial.println(" V");

Serial.print("Oxidizing Gas Voltage: ");
Serial.print(oxidizingGasVoltage);
Serial.println(" V");

delay(1000);
}

This Arduino sketch interfaces with the MiCS-4514 sensor using GPIO19 and GPIO18 for reducing and oxidizing gas outputs. GPIO5 controls the heater, which is turned on during setup. The analog readings are converted to voltage and printed to the Serial Monitor every second.

Connect your ESP32 to your computer via a USB cable, Ensure the correct Board and Port are selected under Tools, Click the "Upload" button in the Arduino IDE to compile and upload the code to your ESP32.

ESP-IDF Image

ESP32 MiCS-4514 ESP-IDF Code Example
Example in Espressif IoT Framework (ESP-IDF)

If you're using ESP-IDF to work with the MiCS-4514 Dual Gas Sensor, here's how you can set it up and read data from the sensor. Fill in this code in the main ESP-IDF file:

#include <stdio.h>
#include "driver/adc.h"
#include "esp_adc_cal.h"
#include "driver/gpio.h"

#define REDUCING_GAS_CHANNEL ADC1_CHANNEL_7 // GPIO19
#define OXIDIZING_GAS_CHANNEL ADC1_CHANNEL_6 // GPIO18
#define HEATER_PIN GPIO_NUM_5
#define DEFAULT_VREF 1100

void app_main(void) {
// Configure heater pin
gpio_pad_select_gpio(HEATER_PIN);
gpio_set_direction(HEATER_PIN, GPIO_MODE_OUTPUT);
gpio_set_level(HEATER_PIN, 1); // Turn on the heater

// Configure ADC
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(REDUCING_GAS_CHANNEL, ADC_ATTEN_DB_11);
adc1_config_channel_atten(OXIDIZING_GAS_CHANNEL, ADC_ATTEN_DB_11);

esp_adc_cal_characteristics_t *adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars);

while (1) {
uint32_t reducing_raw = adc1_get_raw(REDUCING_GAS_CHANNEL);
uint32_t oxidizing_raw = adc1_get_raw(OXIDIZING_GAS_CHANNEL);

uint32_t reducing_voltage = esp_adc_cal_raw_to_voltage(reducing_raw, adc_chars);
uint32_t oxidizing_voltage = esp_adc_cal_raw_to_voltage(oxidizing_raw, adc_chars);

printf("Reducing Gas Voltage: %d mV\n", reducing_voltage);
printf("Oxidizing Gas Voltage: %d mV\n", oxidizing_voltage);

vTaskDelay(pdMS_TO_TICKS(1000));
}
}

This ESP-IDF example reads analog voltages from the MiCS-4514 sensor using GPIO19 and GPIO18 for reducing and oxidizing gases. GPIO5 is used to control the heater. The ADC values are converted to millivolts and printed to the console every second.

Update the I2C pins (I2C_MASTER_SDA_IO and I2C_MASTER_SCL_IO) to match your ESP32 hardware setup, Use idf.py build to compile the project, Use idf.py flash to upload the code to your ESP32.

ESPHome Image

ESP32 MiCS-4514 ESPHome Code Example

Example in ESPHome (Home Assistant)

Fill in this configuration in your ESPHome YAML configuration file (example.yml) to integrate the MiCS-4514 Dual Gas Sensor

sensor:
- platform: adc
pin: GPIO19
name: "Reducing Gas Voltage"
update_interval: 1s
- platform: adc
pin: GPIO18
name: "Oxidizing Gas Voltage"
update_interval: 1s

gpio:
- platform: output
pin: GPIO5
id: heater_control

interval:
- interval: 1s
then:
- output.turn_on: heater_control

This ESPHome configuration uses GPIO19 and GPIO18 for the reducing and oxidizing gas outputs of the MiCS-4514 sensor, and GPIO5 to control the heater. The analog values are updated every second and displayed as sensors.

Upload this code to your ESP32 using the ESPHome dashboard or the esphome run command.

PlatformIO Image

ESP32 MiCS-4514 PlatformIO Code Example

Example in PlatformIO Framework

For PlatformIO, make sure to configure the platformio.ini file with the appropriate environment and libraries, and then proceed with the code.

Configure platformio.ini

First, your platformio.ini should look like below. You might need to include some libraries as shown. Make sure to change the board to your ESP32:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200

ESP32 MiCS-4514 PlatformIO Example Code

Write this code in your PlatformIO project under the src/main.cpp file to use the MiCS-4514 Dual Gas Sensor:

#include <Arduino.h>

const int reducingGasPin = 19; // Analog input for reducing gas
const int oxidizingGasPin = 18; // Analog input for oxidizing gas
const int heaterPin = 5; // Digital output for heater control

void setup() {
Serial.begin(115200);

// Configure heater pin
pinMode(heaterPin, OUTPUT);
digitalWrite(heaterPin, HIGH); // Turn on the heater
}

void loop() {
int reducingGasValue = analogRead(reducingGasPin);
int oxidizingGasValue = analogRead(oxidizingGasPin);

float reducingGasVoltage = reducingGasValue * (3.3 / 4095.0);
float oxidizingGasVoltage = oxidizingGasValue * (3.3 / 4095.0);

Serial.print("Reducing Gas Voltage: ");
Serial.print(reducingGasVoltage);
Serial.println(" V");

Serial.print("Oxidizing Gas Voltage: ");
Serial.print(oxidizingGasVoltage);
Serial.println(" V");

delay(1000);
}

This PlatformIO example reads analog voltages from GPIO19 and GPIO18 for the reducing and oxidizing gas outputs of the MiCS-4514 sensor. GPIO5 is used to control the heater. The values are converted to voltage and printed to the Serial Monitor every second.

Upload the code to your ESP32 using the PlatformIO "Upload" button in your IDE or the pio run --target upload command.

MicroPython Image

ESP32 MiCS-4514 MicroPython Code Example

Example in Micro Python Framework

Fill in this script in your MicroPython main.py file (main.py) to integrate the MiCS-4514 Dual Gas Sensor with your ESP32.

from machine import ADC, Pin
import time

# Pin definitions
reducing_adc = ADC(Pin(19)) # Analog input for reducing gas
oxidizing_adc = ADC(Pin(18)) # Analog input for oxidizing gas
heater_pin = Pin(5, Pin.OUT) # Digital output for heater control

# Configure ADC
reducing_adc.atten(ADC.ATTN_11DB)
oxidizing_adc.atten(ADC.ATTN_11DB)

# Turn on the heater
heater_pin.on()

while True:
reducing_voltage = reducing_adc.read() * (3.3 / 4095)
oxidizing_voltage = oxidizing_adc.read() * (3.3 / 4095)

print(f"Reducing Gas Voltage: {reducing_voltage:.2f} V")
print(f"Oxidizing Gas Voltage: {oxidizing_voltage:.2f} V")
time.sleep(1)

This MicroPython script uses GPIO19 and GPIO18 for reading reducing and oxidizing gas voltages from the MiCS-4514 sensor. GPIO5 controls the heater. The ADC values are scaled to voltage and printed every second.

Upload this code to your ESP32 using a MicroPython-compatible IDE, such as Thonny, uPyCraft, or tools like ampy.

Conclusion

We went through technical specifications of MiCS-4514 Dual Gas Sensor, its pinout, connection with ESP32 and MiCS-4514 Dual Gas Sensor code examples with Arduino IDE, ESP-IDF, ESPHome and PlatformIO.