Maker Pro
Maker Pro

Using a transistor to cut 5v supply to arduino analog pins

mikgol

Jul 6, 2013
87
Joined
Jul 6, 2013
Messages
87
Hi there,

I'm using an arduino to detect water level with the analog pins - to detect current though the water.

The problem is that sending 5v through the water causes corrosion on the electrodes, so I want to only turn on the 5v though the water during sensing.

I tried hooking up an NPN transistor, but that didn't work - I think I need a PNP transistor for this. Can someone please describe the circuit I need to do this (i.e. 5v from arduino gets supplied to the analog pin when the transistor is turned on via a digital pin)

Cheers for the help
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
Hi there,

I'm using an arduino to detect water level with the analog pins - to detect current though the water.

The problem is that sending 5v through the water causes corrosion on the electrodes, so I want to only turn on the 5v though the water during sensing.

I tried hooking up an NPN transistor, but that didn't work - I think I need a PNP transistor for this. Can someone please describe the circuit I need to do this (i.e. 5v from arduino gets supplied to the analog pin when the transistor is turned on via a digital pin)

Cheers for the help
Do you understand the difference between PNP and NPN?
You don't have to get really scientific, it's just a matter of how it's hooked up.
In theory, either one would work for you. It just depends if you will be switching on the 5V, or switching on the 'ground' for the 5V to connect to.

Here.. read this : http://www.learningaboutelectronics.com/Articles/Difference-between-a-NPN-and-a-PNP-transistor
The pictures are the important part right away. Replace the blocky resistor for the water
 

mikgol

Jul 6, 2013
87
Joined
Jul 6, 2013
Messages
87
Thanks for the reply Gryd3. I'm new to electronics, but I think i'm starting to understand the difference between NPN and PNP.

The analog pin needs to be supplied 5v, so I'm guessing I need to hook up a PNP resistor with E = +5v, B = digital pin, and C = analog pin.

Would that work? The digital pin would feed 5v directly to the analog pin, but if I put a resistor in there then I can still detect the "extra" current coming from the water - is that right?
 
Last edited:

mikgol

Jul 6, 2013
87
Joined
Jul 6, 2013
Messages
87
Stupid me - I can solve this problem by feeding Digital Pin => water => Analog.

No need for a transistor, although I'm curious how I could use a transistor to do this (as I'm half way through learning about transistors)
 

Gryd3

Jun 25, 2014
4,098
Joined
Jun 25, 2014
Messages
4,098
Stupid me - I can solve this problem by feeding Digital Pin => water => Analog.

No need for a transistor, although I'm curious how I could use a transistor to do this (as I'm half way through learning about transistors)

Well. you could trigger your transistor by setting your digital pin high or low

Use a PNP transistor, and connect E to 5V, B to the Digital Pin, and C to the Water.
When the digital pin is set as a digital high (5V) or high impedance, the transistor will be Off.
When the digital pin is set as a digital low (0V) then current will flow into E, out B to the digital pin, and the transistor will turn On allowing even greater current to flow into E and out C to the water.

Use a NPN transistor, and connect 5V to the water, C to the water, B to the Digital Pin, and E to ground.
When the digital pin is set as a digital high (5v), then current will flow info B and out E turning the transistor On allowing current to flow into C and out E.
When the digital pin is set as a digital low (0v) then the transistor will be Off.

Please note that you can switch power before or after the water. If you always have your analogue sensor in the water then you will find that if you turn the ground on and off with the NPN transistor the analogue sensor will read 100% (255) or 5V depending on how you read the value when the transistor is OFF. When the transistor is ON, you will get your proper reading.
If you use the PNP transistor and switch the 5v side, then the analogue sensor will read 0% (0) or 0V until you turn the transistor on to get your reading.

As far as corrosion of the conductor in the water is concerned... current flow causes this. So as long as your current flow is very very low, or nothing, you won't accelerate the corrosion. I've seen other builders use an H-Bridge to be able to control the current flow direction which is supposed to help eliminate corrosion.
 

GPG

Sep 18, 2015
452
Joined
Sep 18, 2015
Messages
452
To reduce DC corrosion use AC. IO1 low, pulse IO2, IO1 high, Analog measure. Repeat
 

Attachments

  • cconductivty.gif
    cconductivty.gif
    24.4 KB · Views: 94
Top