Turning off power to sensors from moteino

Started by xavier, February 03, 2015, 08:33:32 PM

xavier

Hi,

I have a couple of moteinos with 3 sensors attached to each (BMP085, DHT22 and a soil humidity thingiehttp://www.ebay.com/itm/271530972307) - Inspired by Felix's Mailbox notifier and the idea of just turning on power to the sensors when needed to conserve my 3.7V lithium battery I added a bipolar transistor (2N2222 - link here:http://www.microtivity.com/p/IC2N2222-4/pack-of-4-2n2222-npn-bipolar-amplifier-switching-transistors)

Unfortunately this is not working - I thought the 2N2222 was rated for 1amp/40V which would be enough to run the other 3 sensors but I suppose I'm mistaken (note that if I use the setup shown in the attachment for just 1 sensor (the soil humidity thingie) then it works fine (aka the sensor is really turned off).

Is this the wrong approach? I'm looking at Felix's new weather shield as well and if I understand correctly he's using a BSS84
P-Channel transistor to turn power on/off to the sensors but I'm not certain I understand really where the sensors are getting the power from in that setup...

anyhow, if anyone can shed some light on my rudimentary understanding of EE I'd appreciate :-)

thanks!

X

Felix

PNP/Pchannel is a sourcing transistor/mosfet. It means it controls the high side/VCC of anything.
NPN/Nchannel is a sinking transistor/mosfet. It controls the low side/GND.
For low power sensors you don't need any special transistors except you need to make sure the Vgs is enough to turn the transistor ON.

You need to switch to a P channel to control the VCC. Or otherwise if using NPN switch the GND for the sensors instead of VCC.
Also mosfets are logic/voltage driven (voltage + almost any tiny current will turn them on) whereas traditional BJT transistors are current driven, meaning you have to control the gate current with a resistor to make sure the output of the transistor allows enough current for the load.

TomWS

Those sensors aren't very high current, you might even be able to power them directly from the moteino pin.  You can certainly power EACH sensor from their own pin, but I don't believe this is necessary.

If you want to use the transistor then, following up on what Felix said, given that you have NPN transistors, you need to connect the transistor differently to power these devices.  Here is the connection:
Connect the Emitter (E) pin to ground.
Connect the Collector (C) pin to the VSS (GND) pin on your sensors.
Connect the power pin (Vdd) on the sensors to 3.3V.
Connect the bias resistor to the Base (B) pin of the transistor.
Connect the other side of the resistor to your digital output pin on your Moteino.

To power ON the sensors, you need to drive the control output HIGH.  To power off, you need to drive it LOW.

The hfe (gain) of the transistor is at least 35 (that spec was ALL over the map on this parameter, but I'd say this was a very conservative value for this part!), so, if your sensors draw a total of 10mA (which I doubt it's this much, but you can measure it) then the bias current into the base of the transistor must be at least 10mA/35 or 285uA.  Since the base of the transistor doesn't conduct until you reach about 0.65V, you will have approximately 3.3V-0.65V or 2.65V across the resistor.  To get 285uA, you divide V/I or 2.65/285 uA and get 9.29K Ohm resistor.  Let's be safe and go with 4.7K, a very common value...

In general, however, it is common practice to switch the power (Vdd) pin of the sensors.  You tried to do this but with the wrong kind of transistor.  You would need a PNP type bipolar transistor or a P type MOSFET.  The problem with a MOSFET, however, again as Felix pointed out, you need to have a high enough gate voltage to turn them on and, while there are plenty that can be run from 3.3V there are FAR more that can't.  For someone just starting out, I'd recommend staying with the bipolar transistor.  The P2N3906 transistor on the same site you referenced would do this very nicely - they have a much higher current gain (although I feel compelled to point out that those prices are significantly higher than they should be for these parts...)

Tom


TomWS

I've thought some more about this and think a PNP transistor would be a much better choice.

Thinking about your soil moisture sensor, it isn't clear if power GND is coupled to the soil. I suspect it is. This isn't such a good thing in general, but really spoils the value of an NPN power control - there would still be leakage currents or worse.

So, replace the P2N2222 in your circuit with a P2N3906 and you should be good to go.  Please sure to check that the transistor pin out is the same and rewire if not.

Tom

xavier

thank you Tom et Felix, will drop by my local store to pick up some 2N3906. (http://www.jameco.com/webapp/wcs/stores/servlet/StoreCatalogDrillDownView?langId=-1&storeId=10001&catalogId=10001&freeText=2N3906&search_type=jamecoall)

I think I'm still confused w the weather shield voltage divider but I guess the voltage divider is just for generating a lower voltage that can be read on A7 to measure the battery level but it does not turn off the sensors...

Since I'm here I'll ask for a feature request :-)
Any chance we could get BLE on future versions of moteino? I'm putting moteinos in my backyard to measure temp, humidity etc... but right now I need to configure them in code and assign each of them a name and lat/long. Would like to do the config from my phone for each device and have the device send that back through the RFM69 to the main station which sends it back to my server... I picked up some HM10 that use the CC2540 from TI http://www.ebay.com/itm/181588926247 so I'll try to hack it but a board with it already installed would be neat (maybe use something like  http://www.digikey.com/product-detail/en/NRF8001-R2Q32-T/1490-1026-ND/4626390)

Some folks in EU already tried something (http://fab-lab.eu/kurse/ultra-low-power-arduino/schaltplan/) using the BLE112 but that seems a little expensive...

Anyhow, thanks again for the help!

X

TomWS

Quote from: xavier on February 04, 2015, 12:46:30 PM
Since I'm here I'll ask for a feature request :-)
Any chance we could get BLE on future versions of moteino? I'm putting moteinos in my backyard to measure temp, humidity etc... but right now I need to configure them in code and assign each of them a name and lat/long. Would like to do the config from my phone for each device and have the device send that back through the RFM69 to the main station which sends it back to my server... I picked up some HM10 that use the CC2540 from TI http://www.ebay.com/itm/181588926247 so I'll try to hack it but a board with it already installed would be neat (maybe use something like  http://www.digikey.com/product-detail/en/NRF8001-R2Q32-T/1490-1026-ND/4626390)

Some folks in EU already tried something (http://fab-lab.eu/kurse/ultra-low-power-arduino/schaltplan/) using the BLE112 but that seems a little expensive...

Anyhow, thanks again for the help!

X
This should probably be moved to a new thread, but you might look into RFDuinos.  They are low power, reasonable cost, decent range and use Arduino IDE for coding.  Connecting to Moteino could be done in a variety of ways.  (Serial, SPI, I2C, etc)
Tom

Saxx

I have a similar setup and I found that those sensors don't use much power at all, so I don't see the point of "turning them off". I have measured the current when the Moteino sleeps and roughly calculated my batteries to last for 16 months using two 1.5V AA batteries. Of course this is just theoretical, but the numbers is more than enought for my use.

You can have a look at my setup here:

http://www.borngeek.net/Projects/Multi-purpose-moteino-sensor

xavier

thanks Ronny - looks like a nice setup you have (where did you get the antenna btw and what kind of range do you get outdoors?)

The moisture sensor I use has a LED that is always on so I don't think I will get really good results, I suppose I could measure the current as well...Seems like a good idea though to just turn off the power since I'm sampling every 15m (I'm using a 1200mAmp Lithium Ion Polymer Battery which may be overkill)

X

Saxx

I always remove the LEDs. In my opinion they have no purpose, except when experimenting and when you want a visual indicator that it works.

My sensors measure every 6 minutes.

I haven't really tested the outdoor range since I have all sensors inside, except for one that's located right outside the kitchen window. You will find plenty of info on this forum about range.

The antennas I buy cheap on eBay or Ali Express. Just search for "433MHz helical antenna".

xavier

k my lipo battery died so it's finally time to try Tom's idea :-)

I think I got it working now using the P2N3906 (pretty much using Tom's connection (using 3.3 to E instead of ground)) - If you still see 3.3V coming out of the collector make sure you have connected the ground to the arduino. I measured  voltage at one of my sensors VIN and it constantly shows 3.3V  but if I measure current I see it go down to 0 when I set the A3 to HIGH. (btw I suppose I could use a PWM pin for this as well)

fyi, this helped me understand better why I had to connect the collector to the ground: http://electronicsclub.info/transistorcircuits.htm - long story short the PNP acts like a switch (it's not a switch so don't try to connect the collector to the 3.3 of the sensors)

thanks again for the help, and please let me know if I made any mistakes!

my final connections:
Emitter (E) pin to 3.3V from arduino
Collector (C) pin to the VSS (GND) pin on your sensors
Arduino A3 to 4.7K resistor to the Base (B) pin of the transistor
3.3V from arduino to 3.3 of each sensor
Arduino GND to GNDs of sensors

TomWS

Quote from: xavier on February 24, 2015, 12:27:41 PM
k my lipo battery died so it's finally time to try Tom's idea :-)

I think I got it working now using the P2N3906 (pretty much using Tom's connection (using 3.3 to E instead of ground)) - If you still see 3.3V coming out of the collector make sure you have connected the ground to the arduino. I measured  voltage at one of my sensors VIN and it constantly shows 3.3V  but if I measure current I see it go down to 0 when I set the A3 to HIGH. (btw I suppose I could use a PWM pin for this as well)

fyi, this helped me understand better why I had to connect the collector to the ground: http://electronicsclub.info/transistorcircuits.htm - long story short the PNP acts like a switch (it's not a switch so don't try to connect the collector to the 3.3 of the sensors)

thanks again for the help, and please let me know if I made any mistakes!

my final connections:
Emitter (E) pin to 3.3V from arduino
Collector (C) pin to the VSS (GND) pin on your sensors
Arduino A3 to 4.7K resistor to the Base (B) pin of the transistor
3.3V from arduino to 3.3 of each sensor
Arduino GND to GNDs of sensors
Xavier, your description doesn't sound correct to me.  The collector of the PNP transistor is the pin that DOES supply power to all of your sensors and should NOT be connected to GND. 

I have attached a PDF schematic showing the proper hookup (using your selection of A3 as the control pin).  NOTE: that you must set the pinMode(17,OUTPUT); to make A3 a digital output pin and to turn ON the transistor and sensors, you must pull pin 17 LOW: digitalWrite(17,LOW); and to turn off the power to your sensors: digitalWrite(17,HIGH);

I used a 3.3K resistor, but a 4.7K should work fine if your sensors are relatively low power.

Tom

xavier

#11
uhm.. I guess I did not get it then! I tried what you described (thank you for the detailed schematic) but I only get 0.2V on the collector pin... I'll spend more time tonight looking at my setup as I must be missing something obvious.. thanks Tom.

update: I changed the P2N3906 and now I'm seeing 3.2ish V coming out of the collector pin - seems my resistor is not right though as I still see 0.6V coming out when A3 is high, will try a couple of changes later. Note as well that the data coming out of my sensor seems wrong, so I suppose the P2N3906 is not getting out enough amps? 

TomWS

Quote from: xavier on February 24, 2015, 06:12:57 PM
uhm.. I guess I did not get it then! I tried what you described (thank you for the detailed schematic) but I only get 0.2V on the collector pin... I'll spend more time tonight looking at my setup as I must be missing something obvious.. thanks Tom.

update: I changed the P2N3906 and now I'm seeing 3.2ish V coming out of the collector pin - seems my resistor is not right though as I still see 0.6V coming out when A3 is high, will try a couple of changes later. Note as well that the data coming out of my sensor seems wrong, so I suppose the P2N3906 is not getting out enough amps?
What sensor are you powering?

It would be useful if you provide a drawing of what you have.  Key factors are to make sure that you do the pinMode correctly.  With 4.7K ohm resistor you should be able to drive a 20mA load without a problem (unless you bought the transistor from Felix  ;D

If you could measure the voltage at all three leads of the transistor when it is on and when it is off, that would also be useful.  And, um, '3.2ish' isn't a 'measurement'  ;)

Tom
PS: Make sure the 3906 emitter is connected to the 3.3V output of the Moteino and not its PWR pin.


xavier

uhm... tried this am again and it's working fine. My main issue yesterday seemed to have been a bad 3906, using a new one fixed the main problem. Time to connect the anemometer to another moteino now  :-)

Thanks for the help Tom!