Parallax Carbon Monoxide Sensor on Fio 6

We’ve been struggling with connecting the Parallax Carbon Monoxide (CO) break-out board for a while now. We finally have it functioning properly and safely. We’ll cover initializing the sensor, circuit setup, configuring pulse width modulation, adding signal lights and voltage monitoring for shutting down the device in case the separated CO power supply drops below a threshold.

Parts list:
Parallax Carbon Monoxide (CO) break-out board
5V Voltage regulator
– Arduino Fio
– FTDI break-out board
– NPN transistor
Code on github

Before we begin keep in mind that the CO sensor requires more than enough current to destroy the pin of your Arduino to which it is connected. You never want to connect the wires supplying power to the CO sensor to your Arguino. Having said that, although we have successfully setup our sensor to record CO readings it is possible that our instructions are wrong/incomplete and could destroy your sensor, Arduino, computer, home or life. We bear no responsibility if you follow the directions below.

Prepping the Parallax CO break-out board

If you are interested in getting values/readings from this sensor you will need to collect readings from pin TP1. I soldered a wire to TP1 in order to do so. If however you simply want to use the sensor as an alarm when the CO level goes above a certain value then you can use the ALR pin located next to the HSW (Heat Switch), +5V, GND pin. I won’t cover it here but I suggest reading the documentation regarding the sensitivity/stability potentiometer labelled Set Point (Don’t just start turning the screw!).

The following directions in this post, if ambiguous, refer to the newer Parallax GAS SENSOR MODULE (GSM).

The newest version of Parallax's carbon monoxide sensor break-out board has different wording up top. It heats the coils when the heat switch is put to ground rather than pulled up to 5V like the previous versions.

The newest version of Parallax’s carbon monoxide sensor break-out board has different wording up top. It heats the coils when the heat switch is put to ground rather than pulled up to 5V like the previous versions.

Older Parallax carbon monoxide break-out board pins

Older/pull-up model of Parallax’s carbon monoxide break-out board (Notice the lettering – Gas Sensor Board)

48h Sensor cooking

The documentation clearly states that you need to clean your sensor before use. This requires a 48 hour full power ‘cooking’ of the sensor. I found a broken/cut USB cable, isolated the red/black cables, soldered the ends stiff and powered my bread-board rail with 5V. To heat the CO coil this version/model of the break-out board you need to put the heat switch (HSW) pin to ground (GND). Previous models required the pin be connected to 5V so figure out which version you have and pin accordingly.

5V USB cable powering the 48h cleanse of the CO sensor

5V USB cable powering the 48h cleanse of the CO sensor. Activation through grounding of HSW pin.

The heat, which you can clearly feel by touching the sensor, burns off coating on the components that applied during manufacturing. If you take readings during the purge/burning you can see them change.

Readings from the first 70 minutes (of 48 hours) of cooking the sensor to clean it.

Readings from the first 70 minutes (of 48 hours) of cooking the sensor to clean it.

Important points about the CO sensor

There are four important points to keep in mind regarding the sensor:

  • The sensor should be cooked at full power (5V) for 48 hours before regular use.
  • Preceding each data collecting session you must do a 500 second purge to clean/heat the sensor to operational levels. Longer if possible.
  • Once purged you will only get one accurate reading every 150 seconds (2.5 minutes).
  • The regular cycle requires 60 seconds of 5V heating followed by 90 seconds of 1.4V before taking a reading and restarting the cycle.

Using an Arduino Uno

If you are using an Arduino Uno your life will be much easier. You will not require the NPN transistor. The HSW pin can be directly connected to a Pulse Width Modulation (PWM) pin on your Arduino. To heat the board you simply need to set the pin to LOW/0. During the lower heating state proceeding your reading, the coil requires an average of 1.4V. We can obtain this by heating the device at 5V for 71/255th of the time. This means the pin needs to be grounded/LOW/0 for 184/255th of the time. So set your PWM pin to 184 using analogWrite(). I will explain the value of 71 and PWM more below. Setting the pin to INPUT mode should turn off the heating completely according to the documentation. We haven’t used an Uno but this should work so… best of luck.

You will also need to change our library code written for the Fio below as we are using a more complex circuit which requires us to use HIGH to power the heater with full 5V.

Basic Uno setup

  • As you are using two power sources you need to join the Uno’s GND to 5V PS GND powering the GSM.
  • Connect your 5V PS and GND to the GSM.
  • Connect an Uno PWM pin (#5 for example) to the HSW pin of the GSM.
  • Finally connect the TP1 pin that you soldered to the GSM to an analogue pin such as A0.

We have also created an optional voltage monitor which we detail further down. This will be connected to another analogue pin (A1). You’ll need a couple resistors to create the voltage splitter – if you don’t care about monitoring see the API to see how you can disable it. Finally you can provide an LED connected to a digital pin (#13 default) to show you when the GSM coil is being heated. That’s it.

Fio setup

The Fio follows the same directions as the Uno with the added complexity of the HSW pin of the GSM. In bullet points let’s restate the main connection points then go into explaining how our HSW circuit works. The following connections/steps are needed.

  • Get a 5V power supply (PS) – we use a 3.7V Li-Ion batterie connected to voltage regulator.
  • Connect the Fio GND to the 5V GND.
  • Connect the 5V and GND to the GSM.
  • From the GSM connect TP1 pin to the Fio (A7).
  • Connect the GSM HSW pin to the collector of an NPN transistor.
  • Connect the Fio digital pin (#11) through a 10K ohm resistor to the base of the same NPN transistor.
  • Now connect the NPN emitter to GND.
  • The voltage splitter, to monitor the 5V PS, requires two resistors.
  • From 5V connect the 10k ohm resistor to a 4.7k ohm resistor which goes to GND.
  • At the junction of the two resistor connect a wire to an analogue pin on the Fio (A1).
CO breadboard

Note that the LED is only in place to show the current flow. The resistor connected to A7 is not necessary.

NPN transistor

The GSM draws 5V whenever the HSW pin is connected to GND. During the 60 second purge stage we set the PWM pin to HIGH/255. This means the pin is consistently at 3.3V allowing current to flow from the NPN collector to emitter to GND.

When needing to power the GSM at 1.4V for the second stage proceeding the reading, we use the PWM of the pin. We set the pin to 71. Why 71? Well 71/255 = 0.278. This 0.278 can be interpreted as 27.8%, meaning the pin is powered to 3.3V for 27.8% of the time – or 0.278 of a second. By opening the NPN transistor 27.8% of the time, we allow the GSM to be powered by 5V for about a quarter of a second. If we average the 5V-27.8% and 0V-72.2% (5 * 0.278) we get the average voltage passing through the GSM: 1.39V

Using the PWM pins enables us to get the average required voltage of ~1.4V through the GSM in this manner.

Voltage divider

Because the GSM will continue to provide readings even when the GSM power supply fails we wanted to be able to constantly measure the input voltage. This way we know when our GSM readings become unreliable. We cannot connect our GSM power supply directly to our Fio (but Uno is okay – with a resistor) so we need to split off some voltage.

Rather than explain it I will refer you to Wikipedia’s voltage divider page.

We designed our voltage splitter to function with a maximum voltage of 10V – although only 5V should ever pass through. This means that 10V would split 3.3V to our Fio and the rest to GND. More typically, with the 5V PS we will receive 1.67V into our analogue pin. The Fio translates this, where 3.3V is 1023 and 0V is 0, into a reading of about 512. When this reading falls below 500 we can send a signal that the GSM PS should be shut off and that our CO readings are likely to be incorrect.

Code

We updated a library to make using the Parallax sensor board with a CO sensor easier.

Using the library to setup is simple. Pass the appropriate pins and the initial purge duration to the constructor. The important point is the regular calling of the Power_cycle function so the library can turn on/off the heater and collect readings.

#include "COS_MQ7.h"

// Pin definitions
#define ACTIVE_MONOX_LED_PIN 13
#define ACTIVE_MONOX_PIN 11
#define READ_MONOX_PIN A7
#define READ_COPSV_PIN A1

// Variable initializations
int reading, voltage;

// Create CO sensor object
// Last parameter is the duration of initial purge in seconds,
// a negative value sets to purge to default: 500 seconds
COS_MQ7 MQ7(ACTIVE_MONOX_LED_PIN,
 ACTIVE_MONOX_PIN,
 READ_MONOX_PIN,
 READ_COPSV_PIN, -1);

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

void loop() {
  // The main important function that you must call repeatedly
  // to allow states to change and correct operation
  // Call every 1-5 seconds
  MQ7.Power_cycle();
  
  // for testing/info
  Serial.print(MQ7.Get_state());
  Serial.print(',');
  Serial.print(MQ7.Get_Voltage_reading());
  Serial.print(',');
  Serial.println(MQ7.Get_current_CO_reading());
  
  if(MQ7.Get_state() == 4) {
    // This is the only reading you want to keep
    voltage = MQ7.Get_CO_reading();
  }
  
  // Check CO unit power supply
  if(MQ7.Get_Voltage_reading() < 400) {
    Serial.println("CO sensor power supply voltage is too low.");
    // do something such as turn on an LED or shutdown etc...
  }
  
  // wait a second (shouldn't be too much longer than 5-10 seconds)
  delay(1000);
}

Conclusion

Hopefully you can now enjoy a functioning CO sensor. I highly recommend you use the sensor for long term ambient measurements. The sensor requires around 5-10 minutes before the readings become somewhat stable. I encourage you to do some controlled tests to see how long it takes your readings to stabilize.

Part of the reason we had such a hard time getting this module functioning was the sever lack of comprehensive information regarding setting up the Parallax GSM board with the MQ-7 sensor. We hope to have filled this void. If you have any question please let us know and we will try and further clarify our instructions.

Happy CO measuring.

6 thoughts on “Parallax Carbon Monoxide Sensor on Fio

  1. Reply Tyler Caspar Mar 30,2014 01:33

    Great guide. With the lack of detailed knowledge about these components on calibration and setup your guide definitely helps. We are doing this project with an uno so I will update later. What do you mean when you say you only get one accurate reading every 150 seconds after you complete the 48 “burn”? How is this different than the 90 second reading after the 60 second cycling for regular operation?

    • Reply serialc Mar 30,2014 11:17

      Hi Tyler,

      The 48 hour burn is a one-time thing to do when you purchase the CO sensor. Removes coatings from manufacture or something I believe.

      During regular use, each time you turn on/power the sensor you need to give it some time (default is 500 seconds but more is better) to bring the sensor to operational temperature and burn off anything attached to the coil when it was off.

      So I turn on my fio/uno, focusing strictly on the CO sensor, the CO coil heater is set to full 5V for 500 seconds or whatever. After this is complete I am ready to begin my actual sensing cycle consisting of stages. Stage A) 60 seconds of 5V heating to clean the coil, followed by, B) 90 seconds of 1.4V, C) take the reading, and restart the cycle.

      So yes you only take one reading after 150 seconds: 60 seconds of cleaning the coil, 90 seconds of letting CO accumulate on the coil.

      Does that answer your questions?
      Cyrille

  2. Reply Tyler Caspar Apr 3,2014 17:03

    Yes definitely answered my question. So we set everything up and took two 150 sec cycle readings with an initial 500sec warm up. The data was sorted and graphed. The first graph is without adding any CO.

    http://i1285.photobucket.com/albums/a583/tycaspar/FirstReading_zps1138dafa.jpg

    It looks like the purge phase decreases the CO sensor readings until it reaches its minimum value, and then slowly increases at a semi-predictable rate around 4.3 increments per second.

    The second reading
    http://i1285.photobucket.com/albums/a583/tycaspar/SecondReading_zps38e75fbf.jpg

    shows the the same as the first graph, but at around 55 seconds we directly added CO at 150ppm to the sensor. As you can see the jump in value to 890 i guess corresponds to the ppm value.
    My question is why didn’t it jump to the max value of 1024 for an analog read. My guess is because the max value reading of the sensor isn’t 150ppm but something greater.

    Next experiment will be in a chamber with nitrogen to get a 0 baseline and then 150ppm. Will update.

    • Reply serialc Apr 3,2014 20:08

      Hi Tyler,

      Did you calibrate your sensor for a certain CO reading? The readings need to be adjusted for humidity as well. We don’t have access to a chamber with a fixed CO level. How are you achieving this? I’m loving the graphs. The second reading is definitely maxing out the sensor.
      So to back track a bit, the reading you’re getting is resistance – CO requires more work to calculate.
      You need to calculate a base resistance value at 100 ppm of CO. Resistance of other readings divided by your base (100 ppm) reading will relate logarithmically to a CO ppm level. See https://github.com/Trefex/arduino-airquality/blob/master/documentation/MQ-7.pdf for details. Note the significant fluctuations in readings based on humidity (and therefore temp) on page 3.

      Cheers,
      Cyrille

  3. Reply RobinHood Apr 28,2017 00:23

    “you need to join the Uno’s GND to 5V PS GND powering the GSM”

    I’m sorry but I don’t understand what you mean by “5V PS GND”…
    In order to power both arduino and sensor with one regulator, what should you do ?
    Thank you for this post, the only one that truly helped me with the parallax !!

    • Reply serialc Apr 28,2017 12:10

      Hi RobinHood,

      When you merge multiple power sources you need to merge the GNDs otherwise very strange things happen. As GND is relative, you need to merge them to insure things work as expected. Alternatively you may get current flowing in the opposite direction.

      The section you are asking about supposes TWO power sources. The UNO’s power, used for low power needs, and a second higher powered source to heat the CO2 coil. The UNO’s GND and the GND of this second power supply for the CO2 need to be connected.

      Does that help?
      Cyrille

Leave a Reply