Documentation index Main site
Bendyroad IDE reference manual. © Copyright Bendyroad 2024.

Example: Air quality alerting with a MQ135 sensor

The MQ-135 sensor detects harmful gases in the air, such aas NH3, NOx, alcohol, and benzene.

MQ gas sensor

The sensing element reacts to concentrations of certain gases by changing its resistance.

Hardware setup

To wire the gas sensor up to an Arduino, connect the VCC and GND appropriately, and the signal wire to an analog pin, in this example pin 0.

Arduino and MQ sensor wiring example

Making the firmware

In this example, we're using a threshold value of '200'. When the sensed value is greater than that, the on-board LED is turned on.

Instead of turning on a LED, you can sound a buzzer or start a fan motor.

MQ gas sensor logic rule in BrainBuilder

This screenprint shows all there is to it: a sensor defined, and a basic logic rule to switch the LED on or off depending on the sensor value.

MQ gas sensors have a heating element and need approx. 180 mA to power the heating element, so you can't power a lot of them from one microcontroller.