Question about "pull to high 5v" with Photon (usb power vs VIN power)

Hi,

I’ve been reading every thread I can find about pull up/down to understand more about it.
(thanks to @piquan for the long explanation here: Disable pull-up/pull-down resistors?)

I am trying to create a hobby project with this gas sensor:

Since it will be running from battery (tiny lipo - 350mAh, via a PowerBoost 500 Basic), I really care about power usage.

The gas sensor needs a 5V input, which I am planning on supplying from the VIN pin on the photon.

For the photon, I have two options for powering it:
1.) power it via the VIN pin directly (with a breadboard - so I can use the same power “rail” to power the gas sensor)
or
2.) power it via micro USB port (and use the VIN pin to power the gas sensor directly)

The part I am having a hard time understanding/picturing is this for the gas sensor:
You can use the EN pin to power it off (pull it high to 5V to turn off).

If I am understanding @peekay123’s comment (here: 3.3 out on one pin, in on another... anything I need? ):
[1] FT = 5.0V tolerant pins. All pins except A3 and DAC are 5V tolerant (when not in analog mode). If used as a 5V input the pull-up/pull-down resistor must be disabled.

Does that mean that as long as I am not using the 5V (VIN) pin as an input (I do need to use it as an OUTPUT to power the gas sensor), it’s OK to set a Digital pin (let’s say D1 as an example) as “INPUT_PULLUP”?

If not - how can I achieve this?

Thanks!

EDIT1: Attaching fritz (NOTE: yellow wire is what I am curious about)

1 Like

There’s a few things to address here.

First, the link to @peekay123’s comment is broken, at least for me. But that’s ok; the bit you quoted is easy to find: that’s from the Electron datasheet at https://docs.particle.io/datasheets/electron-(cellular)/electron-datasheet/#peripherals-and-gpio . However, you said you’re using a Photon, so it’s not directly relevant. But we should still discuss what that means.

It means that if a FT pin (such as D0 on the Electron) is being used as an input for a 5V signal, you can’t turn on the pull-up / pull-down resistor on that pin. So if you’re using D0 as an input, and the device that’s talking to it sends 5V, you can’t use the built-in pull-up/pull-down on D0. It has nothing to do with what’s on any other pin, and in particular nothing to do with VIN.

However, pull-up and pull-down resistors (in this sense) only are used for input pins. But you want to use D1 as an output pin, not an input pin, since you want to send information to the sensor board. In particular, you want to send 5V to the board to tell it to turn off the heater.

The digital output pins from a Photon only send 3.3V, which isn’t enough to turn off the heater. (They send between 2.9 and 3.3 volts, and the heater won’t shut off unless you put at least 4.7 volts on the EN pin.)

You’re going to need a transistor to act as an intermediary to convert the 3.3 volt output of the Photon to the 5V input of the board. Or, since it’s going to a heater, you might want to use an optoisolator like the one at https://sparkfun.com/products/9118 . If I get time later this week, I might throw together a circuit, but try working on it yourself first.

1 Like

The same statement can be found in the Photon datasheets.
https://docs.particle.io/datasheets/photon-(wifi)/photon-datasheet/#peripherals-and-gpio
(the link to PeeKay’s post works for me, althought it could actually link to post #6 - hence I’ve updated the link accordingly)

@ventz, if you dare to tamper with the sensor board, you could remove/disable* the on-board pull-down resistor that keeps the sensor powered when /En is left N/C and instead apply a 10k pull-up resistor to Vin which keeps the sensor in off-mode till you actively apply a LOW signal via D0 (to power down again, change pinMode() to INPUT to let the 5V pull-up do its job again).
https://learn.adafruit.com/assets/33795


Footnote *)
To do that you’d just cut the trace between the FET and the 10k pull-down

You just need to be aware that the heater will need some heat-up time after power-up to provide correct readings.

1 Like

@Piquan Thanks for the explanation. The output of 3.3V I knew (for digital pins), but the Input bit I did not understand. I didn’t realize you can actually send 5V to the digital pins. But as you said, this doesn’t help me. The heater is just a small element (used to measure the gas) so doing the 3.3->5V is probably the easiest way. This way, I can just toggle the 3.3V digital pin easily from software.

@ScruffR This is awesome - thank you!

I am trying to keep the components/final size on this project as small as possible, so I am really trying to avoid adding anything else (even if it’s a tiny 3.3v -> 5v converter).

Would the 10K resistor be between the gas sensor’s 5V pin and the “power feed”? (either breadboard 5V rail/ the VIN directly on the Photon)?

(still new to to the electrical side of things, I apologize if this is a completely stupid/101 question) Assuming NC is “normally closed” - is the idea that a 5V signal goes through R3 (in the diagram you linked at adafruit - the “U1”/ENABLE component), and that connects the 5V line to the heater? If so - I guess I am not understanding why they would use a “5V trigger” (En) to control a 5V power needed? If I could control 5V on and off, why wouldn’t I just control it to the 5V needed for the sensor itself? I would completely understand if the trigger was 3.3V - that would make sense to me. Also, it seems that if you do not connect the En pin at all, the circuit is powered on by default, so wouldn’t that mean that the 5V on the En turns it off? (I am assuming that I am miss-understanding the closed/open part.)

Last question - different idea but same result possibly - if I power the photon from MicroUSB, if I put the Photon to deep sleep (which is the plan anyway), would that just cut the power to the VIN (5V) output pin – if this happens, this might be the easiest way without having to cut the enable to the 10K or convert the 3.3v D pin to a 5V for the enable?

In order to be a pull-up it needs to be between Vin/5V and /En.

N/C in this connection stands for “Not Connected”.

The /En pin goes to the gate of the MOSFET which either supplies the 5V to the heater or blocks it. When /En is pulled low (normal by R3) the MOSFET will open to allow the 5V applied to the source pin to get through to the drain pin and will start the heating. When /En is pulled high (e.g. via the external pull-up once R3 is disconnected) the MOSFET blocks the 5V. Since a MOSFET doesn’t draw any noticable current via the gate this will not affect your power consumption too much to keep the sensor powered off that way.

No, the USB power is directly (via a protection diode) connected to Vin, so deep sleep does not change that.

The point is that a GPIO used to supply the 5V might not be able to deliver the current required. Hence the board comes with a MOSFET that won’t draw any considerable current from the GPIO but switches the supply rail which is by design meant to deliver the current needed.

1 Like

Thanks. I am starting to understand the basics.
(Thank you especially for the MOSFET explanation – this really clicked for me now).

It’s a shame that the Vin on the photon won’t power off in deep sleep - that would have made things easier :slight_smile:

I wonder why there is no standardization on the lowest power that you can possibly register for control/triggers.
It seems some components use 3v and others use 5v.

That’s due to advancement in technology. The higher integrated circuits get the smaller the traces have to be and the lower the voltage has to be reduced not to fry the traces.
Even 3.3V is going to be reduced over time.

@ScruffR - so I can use something like this booster (https://www.adafruit.com/product/3661) to deliver the 5V to shut off the heater, but the issue is that when I sleep the photon, it will re-enable itself and draw power from the battery.

Your solution about cutting between the FET+10K might actually be the only right solution in this case – so that is, things are only drawing power when 1.) the photon is on and 2.) I manually “ask the photon” to power on the heater for a bit

Are there any better alternatives/components/etc that I can use to achieve this?

The primary concern is small/tiny + battery power (again because of small/tiny/safe).

ps: the idea for this is to be clipped on a baby diaper :smiley:

Actually, this should work – there should not be a drain if the Photon is powered off right?

No, why? That’s the whole purpose of having the 10k pull-up to keep the sensor powered off while D0 is not driven (e.g. during deep sleep or with pinMode(D0, INPUT)).
And to switch on the sensor you just pull D0 LOW so what would the booster be for?

Having a LiPo on a baby where it might get wet? I’d think twice there.

Correct, but that is with your solution (cutting the board)

If I go with the way it is right now + add a power boost (3v->5v), I don’t think it will work correctly.
(that is - the 2nd diagram I uploaded)

For the battery safety - if the baby can walk, it’s a concern. But attached externally on a diaper on a newly born should not be a problem. There are other ways to insulate the battery, and I am actually considering completely water proofing it/placing it in a rubber/silicone case. From everything I’ve read, the biggest concern with lipo is while charging it, and it seems that if you simply charge it very very slowly (obviously bellow it’s measured mAh, but specifically at 100mAh) it’s very safe.

I was reading a bit on the quailty/suppliers of lipo too, and it seems that adafruit for what it’s worth has some of the highest quality and safest lipos out there. I am actually really impressed how much safety is put in place compared to your typical lipo. Short of it being under water, a direct spill on it should still be ok given how it’s wrapped.

1 Like

I see now :blush: - in that case you are correct.

@ScruffR - I got it to work, but running into a strange problem when using 3v3 vs the digital out pin – same voltage when I measure it on HIGH, but the 3v3 works and the digital pin does not. I don’t understand what would cause this?

Here is a picture of the working version (if I move the yellow back up to the dedicated3V3):

The weird part is that when I power it from the dedicated 3v3 pin (yellow), it works perfectly, going through the pololu step up converter (black for ground, red for the 5v out of the pololu), and then 5v (red again) into the heater (and black again ground).

However, when I switch the yellow from the 3v3 to any digital pin (let’s use for ex: D5) and use it as an output + set it to HIGH, it does not work (even though I can measure the voltage to the same 3.28 that I get from the dedicated 3v3 pin).

Here is the code:

int heater = D5;
int gasSensorData = A0;

void setup() {
    Serial.begin(9600);
    pinMode(heater, OUTPUT);
    pinMode(gasSensorData, INPUT);
    digitalWrite(heater, HIGH);
}

void loop() {
    int gas = analogRead(gasSensorData);
    Serial.printlnf("===> %d", gas);
    delay(1000);
}

This doesn’t make any sense to me…

The key may be the current. The power provided is the product of the voltage x current. While the voltage for both is 3.3V the current delivered by a GPIO pin is limited to 20mA while 3v3 can give you 100mA+.

But why are you not using Vin as power source but 3v3?
3v3 will go through the voltage regulator and limit the current while on Vin you’d have the full current of the LiPo (or 1000mA+ when going via USB) and the stepup gap from 3.7~4.2V from the LiPo is smaller.

1 Like

@ScruffR - Not using the lipo yet, just regular USB power into the photon while testing/building it out.

I thought the same (must be the current), but the current is the same when using the dedicated 3v3 pin and when I toggle the digital pin to high. So is the voltage (exactly the same). This is the part that makes no sense to me.

I am using the 3v (vs the 5 on the VIN) because I need to toggle it off eventually while sleeping the photon – and all of this will be powered from the same power source.

I was thinking of potentially using the high/low pin just as the control (via the step up converter) since it needs 5V for control, but unfortunately I have to set it to high in order to turn off the heater – so I have no way of setting it high and deep sleeping the photon (as far as I know at least). Otherwise this would be perfect. [back to the cutting it would reverse that, but trying to avoid cutting it]

If I use the Vin directly to the heater - it works, but it’s always on (so no chance of going to a small lipo later)
If I use the dedicated 3v3 with the step-up converter (for the 5v source power) - it works, but same problem of power drain. When I go into deep sleep, the 2.79 V (if I remember correctly) from the 3v3 are still going strong - and converting to 5V successfully.

But if I use the digital pins, same voltage and amps output from the digital pin, and then the output from the step up is exactly 5V (which is what’s needed) but yet the analog gas reader is not functioning properly. Specifically, it is in the 20s-40s as a default/stable read and doesn’t respond to gases (ex: when functioning - vodka spikes it instantly to 3000-4000)

I just don’t understand how both the digital and 3v3 can output the same voltage + amperage and in one case it works and in the other it doesn’t.

Also, if it was the amps - I would assume the step up converter would not be able to produce the 5V output – but in both cases it produces it without a problem.

Any ideas on how to debug this? I am not sure why this is so complicated – everything about this sensor seems backwards (ex: instead of controlling it turning it on, it turns it off). It’s almost like they didn’t think it would be powered from a battery.

How did you confirm that?
Voltage and current are two completely different things and 3.3V is only voltage doesn’t tell anything about the current (mA)

With a multimeter.

I am not that bad :slight_smile:

The stepup will still produce the 5V but at a lower max current output. After all we are dealing with the laws of conservation of energy. If you feed 3.3V x 20mA = 66mW and step that up to 5V you’d max. get 13.2mA if you had a 100% efficient converter (which we don’t have).

But if you want to power down the converter you can use a GPIO and any kind of transistor. The low current demand of the transistor can easily be satisfied by the GPIO but the actual driving current has to come from a beefier source (Vin or 3v3).

It’s quite common to have invers logic for an enable circuitry.

1 Like