0
\$\begingroup\$

I was very helpfully directed to this forum from Stack Overflow with this question.

So I've been working on some project for making air quality sensors and ran into a problem. As anyone who has worked with a NodeMCU would know, the chip only has one analog pin. Unfortunately, I have two MQ gas sensors, MQ2 and MQ7, and so I had to follow the guide here to install two analog sensors to the chip.

Now, the MQ sensors are working kinda strange. They output very high values when I uploaded the code from the Arduino IDE and often make no sense when converted into ppm (makes 0). Dunno if it's due to the fact that the heater in the sensors aren't being preheated or what.

Later, I was told that the GPIO pin outputs around ~3V of power while the MQ gas sensors needed 5V to function but I was told it can be done. What I was advised was to "use the IO-pins to switch on/off a transistor which drives the sensor".

Could anyone here detail me on how to do this? Or could I just use a voltage divider to constantly supply ~2V more of power to the sensors (currently I'm trying it with a 10K and an 18K)?

\$\endgroup\$
  • \$\begingroup\$ Add schematic of your current circuit. \$\endgroup\$ – Bence Kaulics Aug 10 '17 at 12:37
  • 1
    \$\begingroup\$ Get a cheap analog multiplexer to switch between your sensors. \$\endgroup\$ – Bence Kaulics Aug 10 '17 at 12:39
0
\$\begingroup\$

Well, your title is totally misleading! I'm only saying it for you, since you will probably not attract much attention.

But anyway, if you want to switch 5V with a 3.3V level I/O from the MCU I would do it like in the circuit below.

schematic

simulate this circuit – Schematic created using CircuitLab

You have a P-MOSFET (M1) as the main switching device to turn on/off the 5V coming from your voltage source. Then to be able to turn M1 properly you have to add the M2 N-MOSFET.

When the I/O is at LOW level, M2 is off and thus the gate of M1 is pulled high through R1. Thus M1 is off and the sensor doesn't have supply.

When the I/O is at HIGH level, M2 is on and thus the gate of M1 is at a voltage close to ground. M1 is then on and the sensor is supplied with 5V minus the voltage drop across M1.

That would do the job you need.

But have in mind that the A/D converter of the MCU can only measure voltages until 3V. If you expect the analog output of the sensors to be above this voltage, then you have to properly adapt it before connecting it to the A/D pin.

\$\endgroup\$
  • \$\begingroup\$ Hahaha. Sorry, this is my second time posting a question to a forum and the first time here so it may not be clear. Thanks for the reply. I'll have a go at this after I've look through how to use a MOSFET and worked out the schematic (have never seen one before :) ). Thanks again. P.S Also can you recommend me a particular model of the MOSFET to use? There are so many to choose from \$\endgroup\$ – Sorakrit Chonwattanagul Aug 11 '17 at 6:55
0
\$\begingroup\$

I gone through the instructables what you have given. The method implemented is not preferable while working with gas sensors, since the heating element is sensor needs 900 milli-Watt to power up. which is impossible by an nodemcu pin.

Please try this instead.

Go with 74HC4051 IC to expand the single ADC input port of the ESP8266 in to 8 ports. Go thorugh the circuit below for connections and add maximum up to 8 sensors to IO0 TO IO7

Follow the following link to download the library https://sourceforge.net/projects/davidegironi/files/esp-lib/esp_lib_adc4051_01.zip/download

enter image description here

\$\endgroup\$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.