Friday, 27 November 2015

Sketch for MQ-7 Carbon Monoxide Sensor

Right, in this post I'm going to share with you a Arduino sketch, by using the sketch you can get reading from the MQ-7 Carbon Monoxide Sensor and control many things as you like.

Before I share the sketch with you let me tell you what did I do when I got this sensor on my hand. Actually I bought this sensor by mistake. I wanted natural gas sensor which can detect the quality of the air so that it can tell me when the air gets polluted. Any way after getting this sensor I started looking for the sketch, so after some search I found a link on the Arduino website which was linked to another site, and when I clicked on it my Avast (antivirus software) didn't let me go (probably because of some kind of virus site). Then I have found another site with the sketch, but this time I didn't quite understand the sketch. So I opened my soil moisture sensor sketch and after making some changes I was able to get reading from this sensor, still I'm not sure how accurate is this but you can try it by yourself and have a look.

I think it works fine as I've tried it and got good result. :)

The sketch
int led = 5;
void setup() {
// initialize serial communication at 9600 bits per second:
 pinMode(led, OUTPUT);

void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);

if (sensorValue >=200){
    digitalWrite(led, HIGH);
  else {
    digitalWrite(led, LOW);

What does this sketch do?
Well, it measures level of the carbon monoxide in the air and turns the LED on when it reaches 200 or above. You can change it to what ever level you want and add more things to control with this sensor.

Things you need:
  • 1x MQ-7 Carbon Monoxide Sensor.
  • 1x Arduino board (in this case I've used Arduino Nano).
  • 1x LED.
  • 1x 10k Ohm resistor (just to make the LED a bit dimmer).
  • Few jumper wires.
This sketch gets readings twice a second if you want more then lower the number "delay(500);"
 according to your needs.

I hope this helps you. Thanks for reading. :)

No comments:

Post a Comment