Powering sensor/radio from digital pin

I want to switch off power to some sensors and RF24 radio on my battery powered sensor module.

I've seen an example that uses a resistor in series with the digital output of the Arduino and the power input of a sensor with a decoupling capacitor on the sensor between power and ground.

Is the capacitor/resistor necessary? I've tested things on a breadboard with the digital pin's output hooked straight to the sensor power in and it all worked.

As long as you are drawing NO more than (say) 20mA through the digital pin you won't have a problem. 40mA is the absolute max but I would not like to draw that except for very brief periods.

I suspect a radio would need more than 20mA.

You can easily use a transistor to control higher currents and use the Arduino to control the transistor. I'm sure there is an example on this website.

...R

Edit to add the word NO -- oops -- apologies, and thanks to @Paul_B for pointing it out

That's what I assumed so didn't understand the reason for the resistor/cap in the example.

It's this one on Gammon's site Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors

The radio only uses 20ishmA and the sensors are under 10mA so it's well under 40mA and won't be on for long each time.

ChrisHigs:
That’s what I assumed so didn’t understand the reason for the resistor/cap in the example.

It’s this one on Gammon’s site Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors

That’s beyond my pay grade. Hopefully Nick will come to the rescue.

…R

That's what I assumed so didn't understand the reason for the resistor/cap in the example.

I can't see anything that uses a resistor / cap on that page, can you say how many diagrams down that is?

As explained immediately under the diagram showing the resistor and capacitor on the first schematic:

The 220 ohm resistor is to stop too much current flowing through the output pin to charge the 0.1 uF decoupling capacitor.

This circuit will work only for something that draws very little current, like an RTC. You would not use a 220 Ohm resistor with a radio that draws 20 mA, because it will drop about 4.4 V. You should not need either the resistor or the cap for the radio. It will have its own decoupling circuit.

Thanks, missed it.

I can see why he has done it. A discharged capacitor looks like a short circuit and so it would exceed the 40mA current limit on the pins output. That is why the resistor is there.

The capacitor is for decoupling.

I’ve tested things on a breadboard with the digital pin’s output hooked straight to the sensor power in and it all worked.

The fact that it appears to “work” is no great test. You need a lot more testing. In short removing decoupling capacitors is unwise some would say stupid ( I’m one of them ). Going without decoupling erodes the noise margin of a circuit. See this:-
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Thanks. I don't quite understand decoupling capacitors. I'll have to learn some more about them.

Anyway, my radio works perfectly switching on and off. However the DS18B20 temperature doesn't. Or rather the 3.3V step up converter doesn't.

If I power the 3.3V step up from one of the pins on the Arduino I only get about 0.25V across its input. If I power it from the battery + terminal it works fine. It's only using about 1mA so it's not a power issue.

Any ideas why?

I changed to a different step up and it’s working now.

Regarding that circuit, Mike is right about protecting the output pin. jremington is also right about it only working for things that draw very little power. I have a note about it further down that page:

As pointed out on the Arduino forum, the voltage drop over the 220 ohm resistor is going to make this system not work for devices that draw much more than a milliamp or so. In the case of the DS1307, it draws around 1.5 mA when active, so over 220 ohms there would be a voltage drop from 5V of 0.33V, bringing it close to its lower operating voltage.

For devices that draw more current it is probably better to drive a suitable MOSFET to switch the power on and off ...

In fact I'm not quite sure what I was thinking of when I wrote that. A high-side driver is probably better to turn a device on or off (like another board).

On my page about a temperature logger I used a similar circuit:

ChrisHigs:
I changed to a different step up and it's working now.

So in order to help others in the future looking at this thread, how did you change it so that it works?

Hmmm. So you have changed the low side driver circuit according to our previous discussion, but not the high side! :grinning:



If you study the data sheet of the ATmegaxx8, you will note that at 20 mA current draw, you may expect the output to drop to less than 4.4V.

Please see important correction to Reply #1

...R

Paul__B:
Hmmm. So you have changed the low side driver circuit according to our previous discussion, but not the high side! :grinning:

Hmmm. You have a point there.

I've heard that before. Why?

That's always been one of my biggest questions in electronics. What's the difference between high side driver and low side other than the type of transistor used? I always chose based on which transistor I had handy. I would imagine I have chosen wrong more than once.

Paul__B:
Hmmm. So you have changed the low side driver circuit according to our previous discussion, but not the high side! :grinning:

Fixed the images. Reload the page to see them.

First see: Gammon Forum : Electronics : Microprocessors : Driving motors, lights, etc. from an Arduino output pin

In ordinary house wiring, you normally switch the high side (that is, a light switch or kettle, or whatever has one end connected to neutral, and you turn on and off the 240V/110V supply). This makes sense in this situation.

However with MOSFETs, and in particular if you want to switch more than the processor supply voltage, then it is easier to sink current. I’ll quote from my page about why sourcing current is harder:

Things get more complicated if we need to source more than 5V, because to turn the MOSFET on we have to have a VGS of -5V or more (the Gate needs to be -5 relative to the Source, which is the opposite compared to an N-channel MOSFET). To turn it off we need to be able to set VGS to zero. So, for example, if we need to source 12V then to turn the MOSFET off we have to present 12V at the Gate. This can’t be done with the Arduino output pin. To achieve this, we need a “helper” transistor, like this:

You need extra components to source current (more than the output pin voltage), which is why people often sink it instead. For something like a motor or LED it doesn’t really care whether you are switching the high side or the low side.

However, for the case of running an extra circuit board, it is probably better to use the “source” technique, particularly if the board is still running at 5V because then the extra transistor isn’t needed. It is better because otherwise you are “disconnecting ground” from the board with your switch rather than “connecting 5V” which is probably bad for the components on it.

In my circuit above, for example, one side of the motor is connected to ground. Now imagine that is a auxilliary circuit (eg. an SD card or clock chip), then it is better to have all the grounds connected, and then turn on and off the 5V supply.

I've heard that before. Why?

Because you can keep the ground common.

What's the difference between high side driver and low side

One switches the +ve line and the other switches the ground.

Disconnecting either power supply with active signals going into it will screw things up but high side switching will screw things up less because there will be less problem with parasitic back powering.

Delta_G:
That's always been one of my biggest questions in electronics. What's the difference between high side driver and low side other than the type of transistor used? I always chose based on which transistor I had handy. I would imagine I have chosen wrong more than once.

You need to discern (at least) two different situations here.

It primarily depends on just what sort of device you are switching, and what its supply voltage is.

If the device to be controlled has only two connections to supply power to it and requires more current than the Arduino can comfortably provide, then "low-side" switching is likely to be appropriate. This is particularly relevant if it is operating from a power supply external to the Arduino where the two control wires leaving the control circuit are ground (going to the external power supply) and the low-switched line.

If on the other hand, the power is to be supplied from the Arduino, then it is preferable to use "high-side" switching where either the current is less than 20 mA and the Arduino pin supplies it directly, or a high-side (PNP/ P-channel) switch is used. Again, the two control wires leaving the control circuit are the switched line and ground.

So for example, an indicator LED with a 330 ohm resistor to limit its current to 10 mA could be powered directly either returned to ground or 5V. If external to the immediate housing however, it should return to ground and the resistor be fitted adjacent to the MCU so that any short circuit of the external wiring either to itself or another ground will not cause harm.

If on the other hand, you wish to drive an IR LED at 100 mA and power it from the Arduino 5V (however supplied), you need a control transistor. If it is again, contained in the same housing as the Arduino, then a low side driver would suit as well as high-side but if external, then a high side driver is preferred.

The situation is complicated if the device controlled requires I/O other than its power line. You have to consider what happens when it is switched off. If you control the power on the ground side, then its I/O connection to the Arduino will be pulled high and may feed current back into the Arduino circuitry. Perhaps more to the point, if that device is connected to other devices, some of those are likely to have their negative supply grounded such that the device you thought you had switched off, is still switched on through a ground path indirectly back to the Arduino which is a very undesirable situation.

Of course it should also be mentioned that if you do implement a high-side switch to power that external I/O device, then switching it off will pull the I/O lines to ground, but that is largely a much more manageable situation.

In general, it is overall safer if the principal connection from the Arduino control circuit to any external components including a power supply is the ground.

In several projects we power external devices (indirectly) from ATTiny MCU output. In the case here, a battery-powered device goes to sleep after several minutes of inactivity, and it is necessary to power off the power-hungry HC-06 bluetooth module, which does not have sleep mode… The AO3401 MOSFET works great as a switch with battery-powered devices, since it gets into on-state with as little as 2.5 V on the gate