I'm currently working on an air pollution controller project and I have a problem to control an external power supply to supply 5V, 1.5V or 0V to an MQ7 gas sensor.

Using the direct PWM output to power the MQ7 is a bad idea because it drains 150mA at 5v for heating. I planned to control the voltage through a NPN transistor. The voltage of 5V and 1.5V are important to be sure that the output values are consistent.

I started with Experiment 1 which was to obvious way of achieving it for me. The PIN 2 (PWM) controls the S8850 NPN transistor.

Experiment 1 layout diagram

Experiment 1 wiring diagram

With Experiment 1:

  • Voltage measured at points A and B.
  • Without the MQ7, the voltage was just great (5V, 1.5V and 0V depending on analogWrite() values)
  • With the MQ7, the voltage dropped to 3.8V, 1.1V and 0V with the same analogWrite() values)

So, with Experiment 2 using an external power supply (maybe the Arduino cannot manage the drain of 150mA which leads to a decrease of voltage...)

Experiment 2 layout diagram

Experiment 2 wiring diagram

With Experiment 2:

  • External supply for the MQ7.
  • Voltage measured at points A and B.
  • With the MQ7, the voltage is correct (5V, 1.5V and 0V with the same analogWrite() values) as long as I provide 8V on the external power supply.

For the record, a snippet of the code :

const int PIN_MQ7_POWER = 2;

void setup() {
  // Prepare serial console

  // Prepare heater/power MQ7

void loop() {
  Serial.println("Switch to 5v");
  digitalWrite(PIN_MQ7_POWER, HIGH);

  Serial.println("Switch to 1.5v");
  analogWrite(PIN_MQ7_POWER, 255/5*1.5);

  Serial.println("Switch to 0v");
  digitalWrite(PIN_MQ7_POWER, LOW);

I checked the internet and all schematics use direct output of the Arduino to power the MQ7 (through PWM). IMHO, it could work for an experiment of some cycles in the lab, but not for a long-term solution.

The usage of an 8V additional power supply is not convenient and I'm pretty sure that it is possible to have a better schematics to select the 3 different voltages easily from the Arduino.

Any ideas how to achieve it?

  • \$\begingroup\$ Using a low-side switch, especially BJT, may cause logic level problem. \$\endgroup\$ – Long Pham Sep 13 '18 at 17:07
  • \$\begingroup\$ Are you powering the Arduino from USB? \$\endgroup\$ – JRE Sep 13 '18 at 17:47
  • \$\begingroup\$ @JRE : I’m powering the Arduino from 9v on the jack. USB is only there to monitor the serial console. \$\endgroup\$ – ostaquet Sep 13 '18 at 17:55
  • \$\begingroup\$ @LongPham : what do you mean with logic level problem? \$\endgroup\$ – ostaquet Sep 13 '18 at 17:56
  • \$\begingroup\$ 9V as in "9V transistor battery?" If so, then that's your problem. \$\endgroup\$ – JRE Sep 14 '18 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.