Digital output to trigger switch

Hi all,

I am doing gas sensor capsule project and using ATtiny85 (Program by Arduino).

My gas sensor requires 5V input (It worked fine with 4 AA batteries or 6V).

ATtiny85 could not supply that much voltage so I have to make some kind of switch in between the batteries and the sensor. So I am able to turn on/off sensor on the specific duration.

Problem is I don't know what kind of switch should I use in this case (smaller is better)... I just need a simple switch which close/open by using the digital output from micro-controller pin (digitalWrite high/low)

Please kindly suggest..

Thank you very much

Use a P-Channel MOSFET to switch the power, and use an NPN BJT to switch the MOSFET:

PFetSwitch.png

majenko:
Use a P-Channel MOSFET to switch the power, and use an NPN BJT to switch the MOSFET:

Thank you very much :slight_smile:

BTW, could you explain why the BJT is needed here? I don't really get that part, sorry..
I also found this set up, http://www.hobbytronics.co.uk/arduino-tutorial9-power, does it work the same way even if there is no BJT and extra resistor?

Thx again

When using a P-channel MOSFET, sending a LOW will turn it on, and sending a HIGH will turn it off. The BJT is there to both invert that signal and make it so it's not so critical what voltage levels the MOSFET will switch with.

This arrangement is what is known as "High Side Switching" because the switch is between the positive power and the load. The circuit you link to is "Low Side Switching" in that the switch is between the ground and the load, and uses an N-channel MOSFET.

While that is fine for a simple load like a motor, or a relay, it can cause problems when the load is more active and feeds data back to the Arduino. In that situation, the route back to the Arduino can sometimes act like a ground and stop the switching from working right. In general, if it's anything other than a single component like an LED, a motor, or a relay, for example, then high side switching is to be preferred.

An additional comment:
In the tutorial they use an N channel MOSFET, which can be switched by a 5V signal, thus there the BJT is not required.
If your Attiny runs on 3 V, you cannot directly drive a MOSFET anyway.

In your case, with a 5V gas sensor running on small batteries, all this MOSFET stuff might be a bit oversized, IMO.

If the sensor takes less than 100 .. 200 mA, it should be easiest handled by a small BJT transistor. (Below 100 mA, "any" NPN transistor should do)
If you're going to switch more current, MOSFET's come into play. In the tutorial, they are using an 60A type.

An output pin on a ATTiny can drain/source easily 10mA (40 mA is the spec MAX, with a max of 60 mA for all 6 pins together) eventually you might consider running the ATTiny at 5 V and drive your sensor directly, if it's just the voltage being too low.

majenko:
When using a P-channel MOSFET, sending a LOW will turn it on, and sending a HIGH will turn it off. The BJT is there to both invert that signal and make it so it's not so critical what voltage levels the MOSFET will switch with.

This arrangement is what is known as "High Side Switching" because the switch is between the positive power and the load. The circuit you link to is "Low Side Switching" in that the switch is between the ground and the load, and uses an N-channel MOSFET.

While that is fine for a simple load like a motor, or a relay, it can cause problems when the load is more active and feeds data back to the Arduino. In that situation, the route back to the Arduino can sometimes act like a ground and stop the switching from working right. In general, if it's anything other than a single component like an LED, a motor, or a relay, for example, then high side switching is to be preferred.

Thank you very much, now I understand how it works :slight_smile:

michael_x:
An additional comment:
In the tutorial they use an N channel MOSFET, which can be switched by a 5V signal, thus there the BJT is not required.
If your Attiny runs on 3 V, you cannot directly drive a MOSFET anyway.

In your case, with a 5V gas sensor running on small batteries, all this MOSFET stuff might be a bit oversized, IMO.

If the sensor takes less than 100 .. 200 mA, it should be easiest handled by a small BJT transistor. (Below 100 mA, "any" NPN transistor should do)
If you're going to switch more current, MOSFET's come into play. In the tutorial, they are using an 60A type.

An output pin on a ATTiny can drain/source easily 10mA (40 mA is the spec MAX, with a max of 60 mA for all 6 pins together) eventually you might consider running the ATTiny at 5 V and drive your sensor directly, if it's just the voltage being too low.

Thanks for your advice, the sensor I used is Methane Gas sensor (Gas Sensors / FIGARO Engineering inc. World leader in gassensing innovation),

It drains 60mA, so do I need MOSFET then? or just BJT like you mentioned is fine? If so then how should I connect ATtiny output pin to BJT?

I am also actually having problem on the battery too as I have to used small battery, eg. two of 3V button cell battery add up to 6V (I think that is the maximum Vcc ATtiny can take)

So I could drive the sensor directly from the Vcc, however as I mentioned, I need some switch which is controlled by ATtiny pin so that I can save power from sensor and extend the battery life.

What do you suggest on what battery should I use? I just found out that these batteries has Maximum discharge current: 1 mA. Maximum pulse discharge current: 5 mA which I'm not really sure that it means I cannot use this battery for my project? Or it is fine.. ref: List of battery sizes - Wikipedia

Coin batteries, as you have deduced, are not a good match for this solution. 4 rechargeable AA types maybe would have been a better choice.

If so then how should I connect ATtiny output pin to BJT?

Using a NPN Transistor:
Signal to 1k Resistor to Base
Emitter to GND
Collector to Sensor -
6 V to Sensor +

I'd reduce the attiny Vcc a bit: one or two normal diodes would take 0.7 or 1.4 V
There's even headroom for a small low current LED in series, which would take about 1.7 V and would signal sensor state by more than duplicating its current to (I guess) about 5 mA.

Not sure if sensor accurracy is ok with unregulated battery voltage, just reduced by Vce of the transistor.

edit: It's also possible to use a PNP Transistor, see next reply

zetinal34:
BTW, could you explain why the BJT is needed here? I don't really get that part, sorry..

If the voltage you are switching to the load is the same as the Vcc supply to the microcontroller, then you don't need the BJT, if you are happy for a Low on the output pin to turn power to the sensor on and High to turn it off.

As you are only switching 60mA you could use a PNP BJT such as BC327 instead of the mosfet. Connect emitter to +5v, collector to the load, and base through a 1K resistor to the output pin. You will get slightly more voltage drop (probably around 0.2v) in the BJT than you would in the mosfet.

Thanks everyone for all the advice.

About the battery, is there any small battery which is capable of 60mA current drain?

I really need the small battery for my project as it is meant to be a pill-size circuit or a little bit larger, that is why I can't use AA battery...

If this is not possible.. Is there anyway to modify my system so that I could use small batteries for 60mA drain?

Thank you very much

Yes, there are small batteries that can give 60mA current drain, though it's more common to see them <30mA, and 15mA is more typical. The problem with that though is that small battery + high current = short lifetime.

The larger the current drain, the faster a battery runs flat. The smaller the battery, the less total current there is in there (mAh).

Instead of trying to find a battery that can satisfy your circuit, why not try and make your circuit satisfy your battery? What is causing you to have a 60mA peak current, and how can you adjust things to reduce that peak current? Which components are most power hungry, and what can you do to replace them with low-power substitutes, or reduce their current requirements?

Things to think about:

  • Higher clock speeds consume more power. Running at 32768Hz is a common way to massively reduce power consumption.
  • Switching off areas of the circuit that aren't in use 100% of the time can save massive amounts of power.
  • Resistive dividers consume power - keep resistor values high in these situations to reduce current.

As an aside, TI has an interesting whitepaper on peak battery current in small cells: www.ti.com/lit/wp/swra349/swra349.pdf

I have a remote temperature probe running from a single 3.7V lithium polymer (ex-phone) battery which takes temperature measurements every 15 seconds and relays them through the ISM band to a base station. It's been running for the past 3 months without being recharged. I designed it originally to recharge using solar power, but haven't yet got round to connecting up the panels. During the periods it's not doing anything the only thing running is a low powered oscillator inside the main controller chip which triggers an interrupt to wake everything else up. During this sleep mode it only consumes a few nanoamperes. Even when active it barely makes it into the milliamp range.

majenko:
Yes, there are small batteries that can give 60mA current drain, though it's more common to see them <30mA, and 15mA is more typical. The problem with that though is that small battery + high current = short lifetime.

The larger the current drain, the faster a battery runs flat. The smaller the battery, the less total current there is in there (mAh).

Instead of trying to find a battery that can satisfy your circuit, why not try and make your circuit satisfy your battery? What is causing you to have a 60mA peak current, and how can you adjust things to reduce that peak current? Which components are most power hungry, and what can you do to replace them with low-power substitutes, or reduce their current requirements?

Things to think about:

  • Higher clock speeds consume more power. Running at 32768Hz is a common way to massively reduce power consumption.
  • Switching off areas of the circuit that aren't in use 100% of the time can save massive amounts of power.
  • Resistive dividers consume power - keep resistor values high in these situations to reduce current.

As an aside, TI has an interesting whitepaper on peak battery current in small cells: www.ti.com/lit/wp/swra349/swra349.pdf

I have a remote temperature probe running from a single 3.7V lithium polymer (ex-phone) battery which takes temperature measurements every 15 seconds and relays them through the ISM band to a base station. It's been running for the past 3 months without being recharged. I designed it originally to recharge using solar power, but haven't yet got round to connecting up the panels. During the periods it's not doing anything the only thing running is a low powered oscillator inside the main controller chip which triggers an interrupt to wake everything else up. During this sleep mode it only consumes a few nanoamperes. Even when active it barely makes it into the milliamp range.

Thank you very much, I will try reduce the current drain as much as possible.

However, if I really can't change the sensor(which is the major drain, around 60mA here), what small batteries can I use in this case regardless of the lifetime (operating for a few hours is fine to me)
I only need to heat up the sensor for measurement every 20 minutes, the rest of the time will be power-down period.

I tried to search up for the button coin battery which has high current drain but still can't find the one with >60mA.

Please kindly help, Thanks a lot :slight_smile:

I tried to search up for the button coin battery which has high current drain but still can't find the one with >60mA.

Probably because you're searching for the wrong chemistry.

You would require a rechargeable lithium ion or lithium polymer battery for that kind of current drain. Note that these require special charge circuitry to charge them up - your normal battery charger won't do it.

Something like these batteries here: http://www.eemb.com/Li-ion_battery/Li-ion-Button_Type.html

The maximum pulse current is "2Cma" - that's "twice the capacity in milliamps", so for a 20mAh battery the maximum pulse current would be 40mA. The maximum continuous current is "1Cma", so a 40mAh battery can supply 40mA continously, and would last an hour.

Their LIR3048 (obviously) would provide the longest operation and place the least strain on the battery.

Your link http://www.figarosensor.com/products/2611pdf.pdf shows that it's not a peak of 60 mA but a kind of electrical heating system.
Not sure how long you have to switch it on until there's a useful result.
And it's probably not meant to run on a small lithium coin cell battery.
Perhaps the guys at figarosensor.com can help you with suitable use cases or a different sensor technology to detect methane ?

Thanks you guys a lot for the suggestions

The sensor takes around 30s to be ready for the measurement (According to what I tested)

I realize now that the normal button cell is not suppose to use in this case because of its draining problem.

However, with the Button Type Li-ion Battery, it seems to be capable with the project but it supply only 3.6V so I'm thinking of using this kind of regulator..
http://www.circuitsathome.com/dc-dc/low-cost-step-up-down-120ma-dc-dc-converter

I'm not sure if it will work.. what do you guys think..
Also, is it possible to just connect this regulator directly to arduino output pin to increase digital output to 5V.. If that is possible then there won't be a need of BJT switch anymore?

If there is really no other way.. I will have to change the sensor type to non-heating (I can't change the battery size because this has to be pill-size circuit or close to that dimensions)

Thank you :slight_smile:

Hi! I know this is an old old topic, but I have some doubts pertinent that were discussed here.

For power saving reasons, I’d like to turn off almost everything connected to a Pro-Micro (Leonardo), when in sleep mode. The only thing that will be on always is a touch sensor (TTP223) that consumes 6uA when idle, and will wake arduino from sleep by an interrupt.

So for the rest of devices attached to the Pro-Micro, a High-side Mosfet configuration, as I read here, is the way to do it.

So, do I need multiple P-Mosfets for turning off multiple devices in different voltages?

I have to power off an RGB LED (PL9823 - that uses max 52mA), a TOF laser sensor (VL53L0X that uses max 40mA), both 5 volts powered). So the Vcc max current from arduino can power this two.

But I have also a voltage sensor (a simple voltage divider, attached to A0) and a power led driver (that uses 630mA) both connected on 8.4V Lipo Battery, which also powers the Pro-Micro, by it’s RAW pin. Arduino of course will be connected directly to the battery.

So, I’m kind of confused.
Would I need one p-mosfet setup for each device? I mean 4 mosfets?

Or would I need two p-mosfets, one for each voltage? One for 5v from arduino that powers the LED and the TOF sensor, and another one for the battery level sensor and the power led driver, at 8.4V?

Or could I use only one mosfet and have all the positive connections with different voltages attached to it?

Or one p-mosfet for the 5V devices and ine n-mosfet for the 8.4v ones?

Thanks for the help!

Edit: I added my modified schematics based on the info in this thread... Is this the way to turn off all the devices if needed? I used two p-mosfets.. Can anyone tell me if it's right, and if there's a simpler way to do it? I have little space in the tiny enclosure, so, the less extra components the better.