MICS6814 - Typical Resistances

Hi,

Is anyone successfully using the MICS6814 Breakout?

I’ve got it hooked up to a NodeMCU/ESP2866 (after many hours of stumbling around with code - thank god for Chris’s Arduino port of IOExpander)

However, my resistances don’t seem right compared to what others are reporting on their Enviro+

The breakout says 3-5v compatible, not sure how that works, doesn’t the sensor heaters require specific voltages? I have it on 3.3v currently.

My current reported resistances (using the formula r = (r * 56000/)(vadc - r) which I assume is correct as the PCB seems to have 3 56K resistors for the reading circuitry:

Reducing: 16K Ohms
NH3: 66K Ohms
Oxidising: 233K Ohms

Which seems to be reversed for what others report where Oxidising is typically the lowest and Reducing the highest. That would tie in with the sensor spec sheet.
Both my Oxidising and Reducing are outside the ranges the Spec Sheets says you should see at 23c 50% Hum, which is roughly what my room is at.

At the end of the day it won’t matter if the sensor is still sensitive to gas and I start to calculate a ratio to R0.

I’m currently running it with a BME280 to get some data to run regressions analysis to compensate for Temp/Hum/Baro based on the great work that @Roscoe27 has done.
Still need to get my head around that and how best to get calibration values with ESPHome/Home Assistant.

But first I wanted to check my sensor is running right.

The breakout says 3-5v compatible, not sure how that works, doesn’t the sensor heaters require specific voltages? I have it on 3.3v currently.

So the breakout board is 3-5v compatible, different microcontrollers/SBCs run at different voltages. The breakouts have a voltage regulator so it can be used with either, but it is probably running at 3v3.

My current reported resistances (using the formula r = (r * 56000/)(vadc - r)

At a glance at the library, it seems to already do that calculation before returning it to you?

Ahh cool, good to know about the voltage regulator.

I’m not using the Python library as I have it connected to an ESP2866 which is best done in C++
However I translated as best I could, and all the heavy lifting had been done by the port over of the IOExpander library (for the Microcontroller/ADC on the breakout).

But yes, I used whatever was in the Python library in my C++ one.

Here is what I cobbled together:

/***** Global Constants *****/

static const byte MICS6814_LED_R = 3;
static const byte MICS6814_LED_G = 7;
static const byte MICS6814_LED_B = 2;


static const byte MICS6814_VREF = 14;
static const byte MICS6814_RED = 12;
static const byte MICS6814_NH3 = 11;
static const byte MICS6814_OX = 13;

static const byte MICS6814_HEATER_EN = 1;

static constexpr float BRIGHTNESS = 0.5f; 
static constexpr unsigned int PERIOD = (unsigned int)(255.0f / BRIGHTNESS);  

static const bool INVERT_OUTPUT = true; //true for common cathode, false for common anode

/***** Global Variables *****/
IOExpander ioe(Wire, 0x19);

class mics6814 : public PollingComponent {
 public:
  Sensor *red_sensor = new Sensor();
  Sensor *nh3_sensor = new Sensor();
  Sensor *oxd_sensor = new Sensor();

  mics6814() : PollingComponent(60000) { }

  void setup() override {

  Serial.begin(9600);
  delay(1000);
  
  Wire.begin(D2, D1);
  
  if(!ioe.initialise())
  
  {
  while(true)
      delay(1000);
      Serial.println("Not Initialised");
  }

  ioe.setMode(MICS6814_VREF, IOExpander::PIN_ADC);
  ioe.setMode(MICS6814_RED, IOExpander::PIN_ADC);
  ioe.setMode(MICS6814_NH3, IOExpander::PIN_ADC);
  ioe.setMode(MICS6814_OX, IOExpander::PIN_ADC);

  ioe.setMode(MICS6814_HEATER_EN, IOExpander::PIN_OUT);
  ioe.output(MICS6814_HEATER_EN, LOW);

  ioe.setPwmPeriod(PERIOD);
  ioe.setPwmControl(2);  //PWM as fast as we can to avoid LED flicker

  ioe.setMode(MICS6814_LED_R, IOExpander::PIN_PWM, false, INVERT_OUTPUT);
  ioe.setMode(MICS6814_LED_G, IOExpander::PIN_PWM, false, INVERT_OUTPUT);
  ioe.setMode(MICS6814_LED_B, IOExpander::PIN_PWM, false, INVERT_OUTPUT);
  
  }

  void update() override {

  float h = fmodf(((float)millis() * 360.0f) / 10000.0f, 360.0f);
  byte r, g, b;
  HSVtoRGB(h, 100.0f, 100.0f, r, g, b);
  
  ioe.output(MICS6814_LED_R, r);
  ioe.output(MICS6814_LED_G, g);
  ioe.output(MICS6814_LED_B, b);

  float ref = ioe.inputAsVoltage(MICS6814_VREF);
  float red = ioe.inputAsVoltage(MICS6814_RED);
  float nh3 = ioe.inputAsVoltage(MICS6814_NH3);
  float oxd = ioe.inputAsVoltage(MICS6814_OX);


  red = (red * 56000) / (ioe.getAdcVref() - red);
  nh3 = (nh3 * 56000) / (ioe.getAdcVref() - nh3);
  oxd = (oxd * 56000) / (ioe.getAdcVref() - oxd);

So I have just had a big dip in the Oxidising Sensor and the other sensors showed nothing so one might assume this was gas that triggered it.

However shouldn’t the Oxidising Sensor resistance increase in the presence of gas?

The Reducing and NH3 would decrease resistance in the presence of gas.

One scenario that fits here is that the Oxidising and Reducing sensors are actually ‘swapped’.
Then also my observations are in line with the sensor spec sheet.

You’ll see in my code above that I have the Pin Numbers for the MS51 IO Expander taken from the Python MICS6814 library (both the MICS6814 library itself and from the MICS6814 ‘example’ in the IO Expander Github repo). Are we sure these are correct?

I can’t compare to the Enviro+ implementation of the MICS6814 as that uses a different ADC.

Ah, sorry, I didn’t catch that you’d rolled your own library. Honestly, I’ve no idea, and you might be better off pinging Pimoroni’s support email (support[at]pimoroni[.com]) or opening an issue on their Github, unfortunately the staff aren’t very active here. It’s hard to tell what orientation the sensor is in and where it connects to the uC because the orientation dot seems to be on the back which is, uh, an interesting approach.

Thanks Shoe, yeah I tried tracing the PCB and gave up!
I’ll ping support.

Hi!

Here’s a schematic for the breakout - indeed it looks like RED and OX pins have been swapped in our library, I’ll get that fixed. Thanks for letting us know! :)

Great, thanks Niko for the confirmation.

Hi Paul,

I’ve just started using Arduino, and I’ve been trying to get the Pimoroni MICS6814 breakout working with an ESP8266 (Wemos D1 MINI). I’ve tried all the libraries for this sensor in the Arduino IDE, and a couple of others I found on GitHub, but with no success - I only ever see sensor readings of -1.0.

It looks like you had some success? Please could you point me to the IO expander port you mention? Could I simply use your ported library above?

Thanks for your help, and have a happy Christmas!

James

Hi James,

Here is the Arduino port for the IOExpander that the MICS6814 uses:

I must admit I didn’t do much with this though it is still churning out raw numbers.
Need to get around to using R0 values to get a ratio to calculate PPM and also factor in Temp/Hum/Pressure offsets as well. I did try some regression analysis to calculate those but it wasn’t entirely successful.

I’m using ESPHome but i’m happy to send over the libs I cobbled together, shouldn’t be too difficult to adapt to Arduino.

Merry Christmas!

2 Likes

Paul,

Thanks a lot. I’ll take anything you’ve got, and perhaps we can try working on this together (although it has been a couple of decades since I wrote much C++)? I’ve been adapting an AirGradient sensor, and have extended it with a BME280 so have the pressure, temperature and humidity values available to apply offsets.

Cheers,

James

1 Like

Hello mate, I’ve been having the same issue as you, where my readings are -1 constantly, did you manage to get around this?

Hi, sorry, real life got in the way and I haven’t had time to look at this since @paulrickwood provided me with his files and info. I hope to get back to it at some point though. And I’ll be sure to post here when I’ve got something working.

1 Like

no worries, cheers lad. its a strange behaviour from the sensor.

Hi Paul,

I’m trying to get this Pimoroni sensor working with an ESP32 in Home Assistant. Do you mind sharing your code? I will certainly contibute back if I have something useful to add.

Thanks,
Eric

Can you please share working code for MIPS6814, ideally for ESP8266?

Thank you!

To be honest I have not looked at this since last December so what I said back then still holds.

Here is the code I came up with. It is for an ESP2866 running ESPHome.
If you are using that then I can share the YAML too.

If you get anywhere with it please keeps us updated here. I’ll do likewise.

MICS6814 ESP Files

Oh and sorry Eric for missing your post months ago.

Dear Paul,
I an not familiar with ESPHome :-( Are you able to write short sketch for Arduino IDE?

Thank you a lot!

Unfortunately I have never worked with Arduino.
You can probably adapt what I have or there seems to be some Grove/Seed MICS6814 Arduino libraries out there you could also adapt to this implementation.
I only cobbled this together from the work of others… I don’t really know what I am doing and it is a steep learning curve for me!

I patched Chris’ IO Expander library to add support for the MIC6814 (and opened a PR against the original repo). I’ve included examples for both ESPHome (this example includes control of the heater and RGB LED) and Arduino sketch in the repo.

@LukeCZ Here is the arduino sketch

Home Assistant via ESPHome

1 Like