Document Information

Document Title Using the MQ Library
Document Number & Revision 401 - 0003 - 1.0
Release Date March 17, 2019
Documente Status Original Document, no ammendments
Document Update 19 April 2021 :Product update with library specifications information.

Contact»

Lead in

The MQ sensor range

What you need:
  • Latest version of MikroC for PIC installed
  • The MQ LIbrary ZIP file
  • A Devboard that suports a Clickboard
  • One or more MQ Sensor
Note
  • Provided the MQ Sensor is tied to circuitry similar to that found on a ClickBoard, any MQ sensor properly supported can be used.This topic is an intermediate topic requireing some knowledge of soldering, reading a circuit diagram and connecting various components.
  • The PIC16F690 does not have the program stack to support the library, a stack of 16 levels or more is reccomended.

Introduction

MQ Sensors are fairly well know in DIY and open source circles as an inexpensive way to measure the presence of chemicles in our ambient environment. The sensors have found there way into the heart of many projects and are available as modularised breakout boards from many suppliers.

The Sensor to choose . . .

Depending on your application, the following sensors are available.
Sensor Description Heater Voltage Clickboard
MQ-2 Methane, Butane, LPG, smoke 5v Yes
MQ-3 Alcohol, Ethanol, smoke 5v Yes
MQ-4 Methane, CNG Gas 5v Yes
MQ-5 Natural gas, LPG 5v Yes
MQ-6 LPG, butane gas 5v Yes
MQ-135 Air Quality (Benzene, Alcohol, smoke) 5v Yes

How the library helps

If you are using a clik board, then the code is supplied from Mikro in separate projects. If then you need to use more than one sensor, you would have to 1) combine the code or 2) reflash the device with the different projects if you were just testing. What the library very simply does is combine all the samples into a single library, and you select in software which sensor is in the respective slots.

The MQ Sensor library project takes the following libraries AirQuality click, CO Click, LPG Click, Alcohol Click, and combines them into a single project. We claim no ownership of the code, as we have used the existing code provided by Mikroe. By default, the EasyPIC v7 will need an LCD and atleast one of the Mikroe Click boards inserted into slot 1. The code preseumes 5Vdc, but you can change this to 3v3 if required. You will need a a MikroC for PIC license to be able to compile the code if you make any changes. To change the device, you then send a value over the comport to the PCB and it changes the device that it is reading.

Command Sensor
0 AirQuality click
1 CO Click
3 Alcohol Click
2 LPG Click

Get The Library

The library is freely available from the folloing location:

MQ Sensor Library©

Libstock Library: Download Here

Mikroe supplies Click Boards, which support the MQ Sensor range. The library combines multiple code samples into a single library making coding easier. Once the device (PIC18F45K22)* has been flashed, the user communicates using the USART to change device selection for the appropriate Click board.

* : The library has been tested with a PIC18F45K22. Deviations will require testing or additional device configuration.