ATMEGA32 and MQ135 to calculate Air Quality

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone, 

 

Firstly I must apologize for asking such a newbie question that may appear completely dumb to those frequenting these forums. My background is programming and not hardware, this in part is why I am having difficulties, as I understand that data sheets hold all the answers, but unfortunately in most cases they look like foreign language to me. Nonetheless I am trying to learn and while I am posting here I am continuing to google and read up on things as well. So please take it easy on me. I come in peace and seek knowledge.

 

Background:

I took an embedded programming class back in college. I am in California, our fires are making our air really bad right now (I am sure you have all seen on the news). I thought... hey, I still have that ATMEGA32 and breadboard, and I love tinkering, I can make my own Air Quality sensor! I ordered an MQ135 sensor, it arrived yesterday, I hooked everything up and am able to read values from the analog pin.

 

My goal: To get a local (indoor) reading in same units that a typical weather app uses. As seen here (random image from google):  https://imgur.com/a/RO3TEMY

and that follows this chart: https://imgur.com/ppW2NIN

 

The measurement is in PPM. And as far as I understand MQ135 is capable of capturing this information (this is one of those parts where I may be saying dumb things). I know MQ135 measures only a select few gases, and is unable to split out that information, instead it basically shows the highest reading based on resistance, it has no idea which gas actually caused it. And I dont care (should I?), I want to know relative to the chart above how bad the air in my house is. If its smoky outside I am ok with just assuming its the smoke thats causing the number to be what it is.

 

Now here is where I am now:

I am using Atmel Studio and ATMEL-ICE to program the ATMEGA32. I have output going to a 2x16 LCD. I am capturing analog pin's output to pin ADC4 on Atmega (I plan to introduce LEDs for ADC0 through ADC3 once I get the reading done).

 

Now, the reading I am getting from the sensor, I am not doing anything to them right now, they are just raw data, I am getting around 35. I took it outside in the smoky weather (Weather app says in my area AQI is around 130) and it actually went down to 28. Really weird :/

 

I understand that the analog is just a value with little to no meaning between 0 and 1024.

 

Where I need help:

Now I am struggling to make sense of the analog value and convert it to AQI. I understand that each sensor is different and needs to be calibrated individually, unfortunately beyond the weather app I do not have any other means of calibration, so Ill worry about that at a later stage, at this stage I need to understand how to convert the analog value to AQI. Ive googled a bunch, and came across various equations, some of which use things like Ro and Ri, I know what those stand for, but how to get those, I have no idea. I came across something that said to simply divide by 1024 then multiply by 5. Which gives me something like 0.154.... nonsensical number?

 

So, I come here in hopes of you guys nudging me in the right direction to learn, or to teach me how to do this. Unfortunately most of my googling leads to people using MQ135 with Arduino boards, Ive yet to find anyone using ATMEGA32.

I am using an old phone charger to supply power 5v 0.7A, I do not have any resistors installed between power supply and ATMEGA32, only a 0.1uf capacitor. MQ135 does have an on board variable resistor (which I have not touched). So schematic is very simply, I can draw it out if it would help.

 

Thank you!

 

Last Edited: Tue. Sep 15, 2020 - 10:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sounds like a fun project.

 

The M32 was a great chip in its day, but it is a little out of date, and hence not much code for current sensors and an old micro out there to review.

 

Perhaps you could get an Arduino Nano, for < $3 USD, and hook up the sensor and the display and run some of the code you have come across already to verify the hardware, then work on your own code and the conversion, air quality LEDs, etc.

 

A schematic is always helpful.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There's many variables to this puzzle, have you read any of the info on the net?

Did it come with a data sheet?

is it a board? I assume it is if it has a variable resistor.

 

https://www.codrey.com/electroni...

 

According to the guide, you can test this with alcohol.  Does the reading change?   

 

The MQ-135 gas sensor has an inbuilt variable resistor (sense resistor) that changes its resistance value according to the concentration of gas. If the gas concentration is high, the resistance decreases, and if the gas concentration is low, the resistance increases. The MQ-135 gas sensor basically needs only one key component as the external component – just a load resistor. 

 Adjusting the resistor adjusts the sensitivity?   

You need a schematic to determine how the board operates... is the load resistor appropriate for the output?

I assume the higher the gas concentration, the higher the current output?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I agree with JC regarding the Arduino path. Indeed, if you google "Arduino MQ135 " you will find many projects that have already addressed your project. Sure you may wish to continue with the mega32, but the approach taken by others may help your planning.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The arduino code should give a hint as to how to do the calculations. Analog.read() on the arduino is just a simple function that reads the adc. 

 

Or there's an Arduino core for the mega32.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1. Irrespective of any code. Did you perform this "burn-in" ?

Remember that at first the MQ-135 gas sensor have to be kept on continuously for its preheating time (over 24 hour) before you can actually play with it

2. You must expose the sensor to fresh air in order to set the "zero". Now from the pictures I've seen on the news; fresh air is in very short supply on the western side of USA, so you won't be able to zero the sensor.