Download Print this page

AZ-Delivery MQ-135 Manual

Gas sensor module

Advertisement

Quick Links

Welcome!
Thank you for purchasing our AZ-Delivery MQ-135 Gas Sensor Module.
On the following pages, you will be introduced to how to use and set up
this handy device.
Have fun!

Advertisement

loading
Need help?

Need help?

Do you have a question about the MQ-135 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for AZ-Delivery MQ-135

  • Page 1 Welcome! Thank you for purchasing our AZ-Delivery MQ-135 Gas Sensor Module. On the following pages, you will be introduced to how to use and set up this handy device. Have fun!
  • Page 2 Areas of application Education and teaching: Use in schools, universities and training institutions to teach the basics of electronics, programming and embedded systems. Research and development: Use in research and development projects to create prototypes and experiments in the fields of electronics and computer science. Prototype development: Use in the development and testing of new electronic circuits and devices.
  • Page 3 consult a doctor. Caution: Keep the product out of the reach of children and pets to avoid accidental contact and swallowing of small parts. Note: Store the product in a safe, closed container when not in use. Attention: Avoid contact of the product with food and drinks.
  • Page 4 Table of Contents Introduction Specifications The pinout How to set-up the Raspberry Pi and Python Connecting the module with ATmega328p Sketch example Connecting Nano V3.0 as ADC for Raspberry Pi Connecting the module with Raspberry Pi Python script for MQ-135 module...
  • Page 5 Introduction The MQ-135 gas sensor module is a device that is used for sensing and measuring the concentration of gases in the air. It can detect such gases as: LPG, propane, methane, hydrogen, alcohol, smoke and carbon monoxide. Though it can detect those gases, it is not able to distinguish the difference between them.
  • Page 6 Specifications Operating voltage: Operating current: 150mA Power consumption: 900mW Load resistance: 20kΩ Heater resistance: 33Ω+5% Sensing resistance 10kΩ - 60kΩ Preheat time: Concentration scope: 200 – 10000ppm (parts per million) Output: analog, digital Dimensions: 33x21x22mm (1.3x0.8x0.9in) For the best detecting results, gas sensor has to be preheated. The best preheat time for the sensor is above 24 hours.
  • Page 7 The pinout The gas sensor module has four pins. The pinout is shown on the following image: NOTE: The Raspberry Pi does not have a digital-analog converter and can not be used to read analog voltages.
  • Page 8 How to set-up Arduino IDE If the Arduino IDE is not installed, follow the link and download the installation file for the operating system of choice. For Windows users, double click on the downloaded .exe file and follow the instructions in the installation window.
  • Page 9 For Linux users, download a file with the extension .tar.xz, which has to be extracted. When it is extracted, go to the extracted directory and open the terminal in that directory. Two .sh scripts have to be executed, the first called arduino-linux-setup.sh and the second called install.sh.
  • Page 10 Almost all operating systems come with a text editor preinstalled (for example, Windows comes with Notepad, Linux Ubuntu comes with Gedit, Linux Raspbian comes with Leafpad, etc.). All of these text editors are perfectly fine for the purpose of the eBook. Next thing is to check if your PC can detect an the microcontroller board.
  • Page 11 If the Arduino IDE is used on Windows, port names are as follows: For Linux users, for example port name is /dev/ttyUSBx, where x represents integer number between 0 and 9.
  • Page 12 How to set-up the Raspberry Pi and Python For the Raspberry Pi, first the operating system has to be installed, then everything has to be set-up so that it can be used in the Headless mode. The Headless mode enables remote connection to the Raspberry Pi, without the need for a PC screen Monitor, mouse or keyboard.
  • Page 13 Connecting the module with ATmega328p Connect the module with the ATmega328p as shown on the following image: Module ATmega Wire color 328p pin Red wire Black wire Blue wire Green wire...
  • Page 14 Sketch example #define DIGITAL_PIN 2 #define ANALOG_PIN 0 uint16_t gasVal; boolean isgas = false; String gas; void setup() { Serial.begin(9600); Serial.println("The sensor is warming up..."); delay(30000); pinMode(DIGITAL_PIN, INPUT); void loop() { gasVal = analogRead(ANALOG_PIN); isgas = digitalRead(DIGITAL_PIN); (isgas) { gas = "No"; else gas = "Yes";...
  • Page 15 Upload the sketch to the ATmega328p and open Serial Monitor (Tools > Serial Monitor). The result should look like as on the following image:...
  • Page 16 The sketch starts with defining and creating two macros called DIGITAL_PIN, ANALOG_PIN. The DIGITAL_PIN represents the digital pin of ATmega328p that is used for connecting the digital output pin of the sensor. The ANALOG_PIN represents the analog input pin of ATmega328p that is used for connecting the analog output pin of the sensor.
  • Page 17 For example: gasVal = map(input, in_min, in_max, out_min, out_max) First argument is the input value, which is in the range from the in_min to in_max. The return value is an integer number in the range from out_min to out_max. This function maps one number in the input range, to other number which is in the different range.
  • Page 18 Connecting Nano V3.0 as ADC for Raspberry Pi Because the Raspberry Pi does not have Analog to Digital Converter (ADC), the task is to make the Raspberry Pi able to read analog voltages. For this purpose ATmega328p or Nano V3.0 can be used. In order to do so, Nano V3.0 V3.0 has to be connected to the Raspbian operating system.
  • Page 19 To download and install the Arduino IDE, go to the Arduino site: and download the tar.xz file of Arduino IDE for Linux ARM 32 bits as shown on the following image: Then, extract the tar.xz file. Open file explorer in directory where tar.xz file is downloaded, right click on it, and run the option Extract Here.
  • Page 20 Open the terminal in the directory where installation files are extracted and run the following command: sh arduino-linux-setup.sh pi where pi is the name of the superuser in Raspbian. After this, to install the Arduino IDE, run the following command: sudo sh install.sh...
  • Page 21 The Arduino IDE is now installed. To run Arduino IDE, open the app: Applications Menu > Programming > Arduino IDE Before the next steps, first the pip3 and git apps have to be installed; Open the terminal and run the following command. sudo apt install python3-pip git -y The library for Python is called nanpy.
  • Page 22 After installation of the nanpy library, download a firmware by running the following command: git clone https://github.com/nanpy/nanpy-firmware.git Change the directory to nanpy-firmware by running the following command: cd nanpy-firmware And run the following command: sh configure.sh Next, copy the nanpy-firmware directory into: Arduino/libraries directory.
  • Page 23 Connecting the module with Raspberry Pi Connect the module with the Nano V3.0 as shown on the following image: Module pin Nano Wire color V3.0 pin Red wire Black wire Blue wire Green wire...
  • Page 24 Next, connect the Nano V3.0 via USB cable to the Raspberry Pi and open the Arduino IDE in the Raspbian operating system. Check if Arduino IDE can detect the USB port on which the Nano V3.0 is connected: Tools > Port > dev/ttyUSB0 Then, go to: Tools >...
  • Page 25 In the Blink.py script write the following lines of code: from nanpy import (ArduinoApi, SerialManager) from time import sleep ledPin try: connection1 SerialManager() ArduinoApi(connection=connection1) except: print('Failed to connect to the Arduino') print('[Press CTRL + C to end the script!]') a.pinMode(ledPin, a.OUTPUT) Setup Arduino try: while...
  • Page 26 Save the script by the name Blink.py. To run the script, open the terminal in the directory where the script is saved and run the following command: python3 Blink.py The result should look like as on the following image: To stop the script press ‘CTRL + C’ on the keyboard. The LED connected to the digital pin 13 of the Nano V3.0 should start blinking every second.
  • Page 27 The script starts with importing two libraries, the nanpy library functions, and the time. Then, the variable called ledPin is created and initialized with number 13. The number 13 represents the number of the digital pin on which LED is connected (on-board LED of the Nano V3.0).
  • Page 28 In the indefinite loop block, the LED is first turned ON for a second, and then turned OFF for a second. This is called blinking the LED. The time interval of a single blink can be changed in the following line of code: sleep(1) Where number 1 represents the number of seconds for the duration of the time interval.
  • Page 29 Python script for MQ-135 module from nanpy import (ArduinoApi, SerialManager) import time try: connection_1 SerialManager() ArduinoApi(connection=connection_1) except: print('Failed to connect to the Arduino') DIGITAL_PIN ANALOG_PIN time.sleep(2) print('Sensor is warming up...') print('[Press CTRL+C to end the script]') time.sleep(5) # Sensor warming up...
  • Page 30 Save the script by the name mq2nan.py. To run the script, open the terminal in the directory where the script is saved and run the following command: python3 mq2nan.py The result should look like as on the following image: To stop the script press ‘CTRL + C’ on the keyboard.
  • Page 31 Internet. If you are looking for the high quality microelectronics and accessories, AZ-Delivery Vertriebs GmbH is the right company to get them from. You will be provided with numerous application examples, full installation guides, eBooks, libraries and assistance from our technical experts.