Skip to Content

HCHO Sensor SFA40 with Arduino

HCHO Sensor SFA40 with Arduino

The SFA40 Formaldehyde (HCHO) Sensor from DFRobot is a compact gas sensing module designed to measure formaldehyde (HCHO) concentration in air.

The sensor is based on the Sensirion SFA40 chip and provides precise measurements in a range from 0 to 1000 ppb. The SFA40 sensing technology is designed for low cross-sensitivity. As a result, common household substances such as alcohol, perfume, or citrus vapors are less likely to trigger false readings.

The module also integrates environmental compensation through an onboard temperature and humidity sensor, which helps maintain stable and accurate measurements under varying environmental conditions.

The sensor board communicates with microcontrollers through an I²C interface, allowing straightforward integration with platforms such as Arduino, ESP32, or Raspberry Pi.

In this tutorial you will learn how to connect the SFA40 Sensor to an Arduino UNO and how to read data from the sensor.

Required Parts

You will need a Gravity: SFA40 Formaldehyde (HCHO) Sensor by DFRobot. As for the microcontroller, I used an Arduino UNO for this project, but any other Arduino or ESP32 will work as well.

Gravity: SFA40 Formaldehyde (HCHO) Sensor

Arduino

Arduino Uno

USB Data Sync cable Arduino

USB Cable for Arduino UNO

Dupont wire set

Dupont Wire Set

Half_breadboard56a

Breadboard

Makerguides is a participant in affiliate advertising programs designed to provide a means for sites to earn advertising fees by linking to Amazon, AliExpress, Elecrow, and other sites. As an Affiliate we may earn from qualifying purchases.

Hardware of SFA40 HCHO Sensor

The sensor module is based on the Sensirion SFA40 formaldehyde sensing element. This element uses electrochemical sensing technology to detect formaldehyde molecules in the surrounding air.

In an electrochemical gas sensor, a chemical reaction occurs at an electrode surface when the target gas is present. This reaction produces a small electrical signal that is proportional to the concentration of the gas. The sensor electronics convert this signal into a digital measurement value.

The sensing system is optimized specifically for formaldehyde (HCHO). The internal chemistry and filtering structures are designed to minimize reactions with other volatile organic compounds. This high selectivity allows the sensor to distinguish formaldehyde from many common interfering gases.

The sensor provides a fully calibrated output. Calibration is performed during manufacturing and stored inside the device. The user does not need to perform additional calibration during normal operation.

Measurement Range and Accuracy

The SFA40 sensor measures formaldehyde concentrations in a range from 0 to 1000 parts per billion (ppb). This range covers typical indoor concentrations as well as elevated levels that may occur in poorly ventilated environments or in rooms with new furniture and building materials.

The output value is reported directly in parts per billion. This simplifies data processing on microcontrollers because no additional conversion or scaling is required.

Electrical Characteristics

The sensing element itself operates with a supply voltage between 1.62 V and 3.6 V. The Gravity sensor module includes additional circuitry that allows operation with either 3.3 V or 5 V supply when connected to microcontroller platforms.

Power consumption is optimized for continuous monitoring applications. The average current consumption is approximately 80 µA when operating in a measurement mode with a sampling frequency of about 2 Hz. Peak current can reach up to 2 mA during measurement cycles.

Physical Design and Module Integration

The SFA40 sensing element itself has a very compact package size of approximately 13 mm × 10 mm × 2.4 mm. The Gravity SEN0661 module integrates this sensing element on a larger breakout board. The board size is approximately 32 mm × 22 mm. It includes the required voltage regulation and interface circuitry for microcontroller platforms.

The module also provides a standard Gravity 4-pin connector, which simplifies wiring and allows plug-and-play connection to development boards. You can find the pinout of the connector below:

Pinout of Gravity SFA40 Sensor Board
Pinout of Gravity SFA40 Sensor Board

The sensor contains a protective vent membrane on the sensing chamber. This membrane allows gas diffusion while protecting the internal sensing elements from dust and contaminants. Do not remove this membrane or expose it to organic solvents!

Protective membrane of SFA40 Sensor

Environmental Operating Conditions

The module is designed to operate in a wide range of environmental conditions. The supported operating temperature range extends from −40 °C to +125 °C. The sensor can operate in relative humidity levels between 0 % and 100 % as long as condensation does not occur. The sensing element includes internal algorithms for temperature compensation.

Technical Specification

The following table summarizes the technical specification of the SFA40 Formaldehyde (HCHO) Sensor:

ParameterSpecification
Sensor TypeElectrochemical formaldehyde (HCHO) sensor
Sensing ElementSensirion SFA40
Measurement Range0 to 1000 ppb (parts per billion)
Detection Limit< 20 ppb (typical)
Accuracy±20 ppb or ±20% of measured value (typical)
Cross-Sensitivity to Ethanol< 0.3%
InterfaceI²C digital interface
I²C Address0x5D
Operating Voltage (Sensor)1.62 V – 3.6 V
Operating Voltage (Module)3.3 V – 5 V
Average Current Consumption~80 µA
Peak CurrentUp to ~2 mA during measurement
Measurement Update RateUp to ~2 measurements per second
Operating Temperature−40 °C to +125 °C
Operating Humidity0% – 100% RH (non-condensing)
Module Dimensions~32 mm × 22 mm
Sensor Package Size~13 mm × 10 mm × 2.4 mm
Output UnitFormaldehyde concentration in ppb
CalibrationFactory calibrated

Installing the DFRobot_SFA40 Library

We are going to use the DFRobot_SFA40 Library for reading data from the SFA40 Sensor. To install it go to the github repo of the library, click on the green “<> Code” button and then “Download ZIP” as shown below:

This downloads the DFRobot_SFA40 Library as ZIP file (DFRobot_SFA40-master.zip) to your computer.

Next open a new Sketch, go to Sketch -> Include Library -> Add .ZIP Library … to install the downloaded ZIP library (DFRobot_SFA40-master.zip):

Connecting SFA40 Sensor to Arduino UNO

The SFA40 Sensor uses the I2C interface for communication and is easy to connect. Start by connecting VCC to 5V and GND to ground. Then simply connect the I2C interface: SDA–SDA and SCL–SCL as shown below:

Connecting SFA40 Sensor to Arduino UNO
Connecting SFA40 Sensor to Arduino UNO

Code for reading data from SFA40 Sensor

The following code demonstrates how to interface the SFA40 sensor with an Arduino board. The sensor measures temperature, humidity, and formaldehyde concentration in parts per billion (ppb). The readings are printed to the Serial Monitor every second.

// https://github.com/DFRobot/DFRobot_SFA40  V 1.0.3
// www.makerguides.com

#include "DFRobot_SFA40.h"

DFRobot_SFA40 SFA40;

void display(const char* text, float value, const char* unit) {
  Serial.print(text);
  Serial.print(value, 1);
  Serial.print(" ");
  Serial.println(unit);
}

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

  while (SFA40.begin() != 0) {
    Serial.println("Could not find sensor!");
    delay(1000);
  }

  SFA40.startMeasurement();
}

void loop() {
  uint8_t status = SFA40.readMeasurementData();

  if (status == 0) {
    Serial.println("\n----------------------------");
    display("Temperature: ", SFA40.temperatureC, "C");
    display("Temperature: ", SFA40.temperatureF, "F");
    display("Humidity   : ", SFA40.humidity, "%RH");
    display("HOCO       : ", SFA40.HCHO, "ppb");
  } 

  delay(1000);
}

Imports

At the beginning, the code includes the library for the SFA40 sensor. This library contains all the necessary functions to communicate with the sensor and retrieve measurement data.

#include "DFRobot_SFA40.h"

Object Initialization

Next, an object named SFA40 of the class DFRobot_SFA40 is created. This object will be used to interact with the sensor throughout the program.

DFRobot_SFA40 SFA40;

Display Function

The display() function is a helper function designed to print sensor readings to the Serial Monitor in a formatted way. It takes three parameters: a text label, a floating-point value, and a unit string. The value is printed with one decimal place.

void display(const char* text, float value, const char* unit) {
  Serial.print(text);
  Serial.print(value, 1);
  Serial.print(" ");
  Serial.println(unit);
}

Setup Function

The setup() function initializes serial communication at 115200 baud to enable data output to the Serial Monitor. It then attempts to initialize the sensor by calling SFA40.begin(). If the sensor is not found, it prints an error message every second until the sensor is detected. Once the sensor is successfully initialized, it starts continuous measurement mode with SFA40.startMeasurement().

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

  while (SFA40.begin() != 0) {
    Serial.println("Could not find sensor!");
    delay(1000);
  }

  SFA40.startMeasurement();
}

Loop Function

Inside the loop() function, the code reads the latest measurement data from the sensor by calling SFA40.readMeasurementData(). This function returns a status code, where 0 indicates a successful read. If the read is successful, the program prints a separator line and then uses the display() function to output temperature in Celsius and Fahrenheit, relative humidity, and formaldehyde concentration (HCHO) in parts per billion. Finally, the program waits for 1 second before repeating the process.

void loop() {
  uint8_t status = SFA40.readMeasurementData();

  if (status == 0) {
    Serial.println("\n----------------------------");
    display("Temperature: ", SFA40.temperatureC, "C");
    display("Temperature: ", SFA40.temperatureF, "F");
    display("Humidity   : ", SFA40.humidity, "%RH");
    display("HOCO       : ", SFA40.HCHO, "ppb");
  } 

  delay(1000);
}

Output Example

The following example shows the output on the Serial Monitor:

----------------------------
Temperature: 22.1 C
Temperature: 71.8 F
Humidity   : 43.2 %RH
HOCO       : 39.0 ppb

Conclusion

In this tutorial you learned how to use the SFA40 Formaldehyde (HCHO) Sensor with an Arduino UNO. The sensor can be easily used with other microcontrollers such as an ESP32 as well.

If you are looking for different gas sensors have a look the following posts:

If you have any questions feel free to leave them in the comment section.

Happy Tinkering 😉