Simple Arduino Formaldehyde Sensor


Introduction: Simple Arduino Formaldehyde Sensor

Have you ever been smoking an eCigarette and wondered "Just how bad is this for me?" Well now you can find out how bad it really is, by measuring the amount of formaldehyde your setup produces. Formaldehyde (HCHO) is produced when the extreme heat of the coils in the eCigarette touches the glycerol (VG) and propylene glycol (PG), causing them to break down into harmful chemicals like HCHO.

Now you can find out just how much formaldehyde is produced by your favorite smoking method.

Though this tutorial does not involve working with formaldehyde and you've already been inhaling it the whole time with your various smoking devices, I'd just like to say:


Step 1: Collect Parts

For this project you will need these items at minimum:

x1 Arduino board (Mega or Uno both work)

x1 Base shield

x1 Seeed HCHO Sensor

x1 computer w/ Arduino IDE

x1 USB B cable (or whichever cable the Arduino requires)

all available at

It would be recommended to add a screen so that the computer is no longer necessary after uploading the code, but I will not cover adding this yet.

Step 2: Assemble Hardware

1. Plug Base shield into Arduino

2. Use the included cable from the HCHO Sensor to plug the sensor into port A0 of the Base Shield

Step 3: (Optional) Make a Tube for Regulated Puffs

If you are using this sensor to test the formaldehyde levels in eCigarettes like I am, it would be wise to construct a tube through which to blow on the sensor at a constant distance. It would be helpful to use a tube with closed ends and thin, workable plastic. This is especially recommended if you are trying to compare devices or smoking methods, e.g. eCigarette vs. cigarette

1. Cut the tube to about an inch and a half long

2. Cut a small hole along the side of the tube near the bottom to allow air/vapor/smoke to escape

3. Cut a small hole on the bottom of the tube that will fit over sensor, as close the edge of the tube as possible (you may have to scrape the inside/outside of the tube to get it to fit over the sensor and between the other parts)

4. CAREFULLY AND GENTLY work the tube over the sensor, the small hole over the circular metal part (the actual sensor)

Step 4: Code

The sensor has the capacity to detect formaldehyde, benzene, toluene and other volatile organic compounds but I only derived the formula for formaldehyde (No formulas given, you have to look at the picture on the sensor's information page for other chemicals)

1. Plug the assembled Arduino into computer and load up Arduino IDE

2. Upload this code to the board:

// Grove HCHO Sensor

void setup() {

Serial.begin(9600); // Begin serial output


void loop() {

float Vi = 0.1;

float Vc = 4.95; // Constant voltage from pin

int sensorValue = analogRead(A0); // Read analog pin for voltage info in 10 bits

float Vf = sensorValue * 4.95 / 1023; // Voltage through pin when in presence of VOCs (formaldehyde)

Serial.print("Vi: ");

Serial.println(sensorValue * 4.95 / 1023);

Serial.print("Formaldehyde Concentration: ");

Serial.print(concentrationPPMform(Vf, Vi));

Serial.print("ppm\n"); // Print concentration data

delay(500); // Delay 0.5 seconds


float concentrationPPMform(float V, float Vstart) // Formaldehde concentration formula


float con = 212.32619543773774 * exp( -( 7.653015806367451 * (4.95 - V) * Vstart ) / ( V * (4.95 - Vstart) ) );

return con;


Step 5: Calibrate

1. Before testing, open up the Serial Window and view the output called "Vi" (in the presence of only air and no formaldehyde, this value is around 0.1V or 0.2V for me)

2. Calibrate by changing the value of Vi at the beginning of the loop in the code to the value seen in the Serial Window (use the lowest value you see)

Step 6: Test It Out

Time to see how bad smoking an eCigarette (or any other kind of smoking) really is for you

1. Connect Arduino and open the Serial Window

(If you are testing a smoking device)

2. Inhale normally from device, but try to keep most of the smoke in your mouth to minimize absorption

3. Exhale slowly into tube, letting all smoke pass through it

4. Go back through Serial Window (turn off autoscroll) and look for the highest value outputted

5. That's how bad it is for you! (My eCigarette mod blew about 180ppm formaldehyde at 4.2V on exhale, as bad as a rolled and unfiltered cigarette)

(If you simply want to check ambient air quality)

2. Do not use tube

3. Make sure to calibrate in an open air setting

4. Bring to testing area

5. Allow to sit about 5 minutes, then check the Serial Window for the value

Step 7: Resources & Product Links



    • Planter Challenge

      Planter Challenge
    • Woodworking Contest

      Woodworking Contest
    • Casting Contest

      Casting Contest

    We have a be nice policy.
    Please be positive and constructive.




    Thanks for the tutorial !

    Just can't understand how to separate formaldehyde, benzene, toluene and other volatile components ? How do I know this is formaldehyde and not toluene concentration ?

    2 replies

    unfortunately you can't really know with this equipment; we are assuming that it mainly produces formaldehyde as one of the scientific articles I have read claimed large amounts of formaldehyde in the ecigarrettes they tested (

    In that study they used outdated e-cigarettes at ridicules high voltages and thus burned the PG in them with a smoking robot. No human being would do this. It's as if you grill a steak for a couple of hours and eat that.
    Funfact, I tried your setup and found higher formaldehyde values in the rooms I don't vape in, but so low, that they are no problem. Since these rooms are facing the street, I assume it's from cars exhaust.
    The highest values I found in a bar where smoking is allowed. But that's no wonder, there is PG in normal cigarettes and there it is burned and not just evaporated as in an e-cig.

    I was reading Step 4: I don't understand "float con = 212.32619543773774 * exp( -( 7.653015806367451 * (4.95 - V) * Vstart ) / ( V * (4.95 - Vstart) ) ); "
    Where did you get it from?
    This is the chart:
    If I follow yours instruction the curve goes in the opposite direction.
    Hope you find time to help me.
    Thanks in advance.

    2 replies

    I solved for the resistances using the starting and ending voltages, hence the ratios in the equation

    That's just because the graph is flipped: in the graph on the website, the x-axis is the ppm and the y-axis is the calculated resistance divided by the starting resistance. The function you plotted from the program would be the voltage on the x-axis and the ppm on the y-axis, for simplicity

    Thanks for making this self- awaness method avaiable.