Electrical – Wire soil moisture sensor such that it only powered when measuring

humidityraspberry pisensortransistors

I am a rookie electronics tinkerer who wants to use the SparkFun soil moisture sensor. I plan on connecting it to ADC MCP3008 to the GPIO pins on a Raspberry Pi. On the SparkFun site the vendor warns that the quality of the sensor may degrade fast if the power is left on continuously. I understand that I need to use a transistor to regulate the power to sensor but I am not sure which one I would need and how I can best connect it to the Raspberry Pi.

I came up with the following design with a BC548 transistor. Could someone give me feedback whether:

  1. this is the right wiring
  2. I need resistors

schematic

simulate this circuit – Schematic created using CircuitLab

Best Answer

OK you are hoping the transistor will behave like a relay contact but this won't happen but there is a solution (later).

But firstly, why your current circuit won't work.

To turn the transistor on into saturation (low volt drop between collector and emitter) you need to drive several mA of current into the base. Given that the base is a forward biased diode (internally) you have to overcome that forward bias with your GPIO voltage. Given that your GPIO voltage might be (at best) 5V then the emitter CANNOT rise to 5V or the base-emitter isn't taking current.

This is why this type of circuit is called an emitter follower - because the emitter has to "follow" what the base does and generally lags behind by 0.7 volts.

This means you won't see more than maybe 4 to 4.5 volts on the emitter. If this is enough to power your sensor then that's fine.

A better circuit uses a PNP transistor and an NPN transistor like this: -

enter image description here

It'll work at 5V of course and if your GPIO voltage is 3V3 then you'll definitely need the NPN transistor. If your GPIO voltage is 5V then, if the load is only a few mA then you can use your GPIO to the base of the PNP via (say) a 1k resistor.

If your load requires say 100 mA then it's probably better to go for a P channel mosfet: -

enter image description here

You have to be careful about selection of ther mosfet - it has to be able to turn on adequately from your logic signal - you need a "logic-level" p channel mosfet.