Voltage divider with transistor switch

I'd like some help with this basic schematic, because I don't understand why it's not working as supposed to.
It's a voltage divider that works with arduino clone (running at 3.3v) to measure voltage of the power source (from 18V to 5V). R3 and R4 are 4.7K and 1K. This combination ratio (5.27) works well for my purpose. Now this is where it becomes erratic. I'm using transistor to disconnect external source when not measuring it's voltage. For this I'm using 2N3904 w/ 4.7K resistor connected to Arduino's D8.
A7 pin is used to measure voltage.
When Transistor is active, everything works as intended (5Vin = 0.87Vout), but when I turn it off (LOW on D8) I'm getting weird voltage reading at A7 junction (using multimeter), it shows 0.66V.
No clue where is this coming from... Can someone help me? What am I doing wrong?
Here's simple sketch that turns transistor on and off

#define TRAN_PIN 8 // Pin connected to transistor's base (via 4.7K resistor)
void setup() {
  Serial.begin(115200);
   pinMode(TRAN_PIN,OUTPUT);
  digitalWrite(TRAN_PIN,LOW);
}
void loop() {
  digitalWrite(TRAN_PIN,HIGH);
  Serial.println ("Transistor on");
  delay (3000);
  digitalWrite(TRAN_PIN,LOW);
  Serial.println ("Transistor off");
  delay (3000);
}

v_div01.png

I'm using transistor to disconnect external source when not measuring it's voltage.

No you are not.

but when I turn it off (LOW on D8) I'm getting weird voltage reading at A7 junction (using multimeter), it shows 0.66V.

This is because turning a transistor off does not disconnect anything, there is always a leakage current through the transistor. As your input now floats it is no surprise you get odd results.

A relay is best for this sort of thing.

I suspect Mike has even then failed to grasp the consequences of this nonsense circuit.

The battery negative voltage is - negative! You cannot switch a negative voltage at the collector of an NPN transistor, it will simply conduct through the base-collector junction and your base resistor to the Arduino ground.

And - why would you be connecting a battery to this circuit and nothing else? You cannot use this to switch power to something; you cannot connect any other circuit to the battery unless it is totally disconnected from the Arduino circuit and anything connected in turn to that.

So what is the imagined purpose of this?

Paul__B:
I suspect Mike has even then failed to grasp the consequences of this nonsense circuit.

The battery negative voltage is - negative! You cannot switch a negative voltage at the collector of an NPN transistor, it will simply conduct through the base-collector junction and your base resistor to the Arduino ground.

And - why would you be connecting a battery to this circuit and nothing else? You cannot use this to switch power to something; you cannot connect any other circuit to the battery unless it is totally disconnected from the Arduino circuit and anything connected in turn to that.

So what is the imagined purpose of this?

I thought I stated pretty clear that I wanted to use transistor as a switch? I want to interrupt connection to JP1. It's true I have no experience with transistors so maybe I misunderstood how to use them as a switch. From examples I'm seen online NPN is usually used to disconnect ground. Current goes from emitter to collector when voltage applied to the base. When you disconnect base circuit is interrupted, right? So my question is how do I use transistor here? Do I need to use PNP instead? Maybe MOSFET is better choice?
Mike I'm actually using relay array now for this, but I wanted to use transistors instead as voltage is not that big... :slight_smile:

As I understand it you are measuring the voltage of a battery, which you describe as
the power source, so you cannot disconnect it by switching off the transistor since
it is powering the Arduino? 0.66V indicates 3.7V at batt Vcc, indicating a LiPo
battery?

As always providing the entire circuit would be most helpful, because there's clearly
something going on we cannot see from that diagram.

MarkT:
As I understand it you are measuring the voltage of a battery, which you describe as
the power source, so you cannot disconnect it by switching off the transistor since
it is powering the Arduino? 0.66V indicates 3.7V at batt Vcc, indicating a LiPo
battery?

As always providing the entire circuit would be most helpful, because there's clearly
something going on we cannot see from that diagram.

I see where confusion is. It's not a power source for the Arduino. Arduino (well it's actually Moteino) powered by FTDI adapter at 3.3V. External power (supplied by variable DC power supply) is connected to JP1. I want to measure it's voltage and then disconnect with Transistor. That's all I have right now on the breadboard (Moteino, 3 resistors, transistor and bunch of wires).
But sure,here's whole schematic, but I'm afraid posting it will add to the confusion :slight_smile:
Once again, I just want to disconnect JP1 (a.k.a INV_SENS on big schematic) from rest of the circuit with Transistor. But when I do I'm still getting pretty substitution voltage from somwhere (when I increase external power supply voltage this ghost voltage is also increasing, I don't think it's just leakage current, it's big, just slightly lower than Vout from voltage divider).

No, the whole circuit, not one circuit board - the socket marked INV_SENSE is clearly
interconnected with other external parts that connect with other connectors on this board,
that's the point, that's why you see a voltage.

MarkT:
No, the whole circuit, not one circuit board - the socket marked INV_SENSE is clearly
interconnected with other external parts that connect with other connectors on this board,
that's the point, that's why you see a voltage.

Not sure what you mean by whole circuit and not one circuit board? I posted both actually :slight_smile: I knew this will create more confusion.
You can completely ignore circuit and board from post #5.
Ok let me try again.
I took A PIECE OF THAT CIRCUIT consisting of:
3 resistors (2x4.7K, 1K)
1 NPN transistor
1 MCU running at 3.3V powered by FTDI

Connected them on a breadboard.

That's all there's.

I admit I'm total noob and idiot when it comes to transistors, that's why I'm asking for help!
How do I place transistor in this circuit so it acts as simple switch and disconnects anything coming from JP1? :grin:

OK, noted your difficulty with keeping track of how current flows. I daresay either you comprehend my explanation or you do not. :smiley:

We are still a trifle unsure of the overall scope of your project, but essentially what you must not do is to try and interrupt the connection of any power source - battery or otherwise - to ground. The circuit without the transistor - as with R1 and R2 - is a good start. To "disconnect" your sense input, you use one gate in a 74HC4066 to interrupt the positive input connection to that 4k7 resistor. It is however essential that the Vcc to the 74HC4066 must never be turned off while the external power source is connected - it could in fact be powered by the very power source you are sensing given that it consumes essentially no current under static conditions.

Oh dear! It gets worse! I suppose you are trying to sense voltages higher than 5V, aren't you? So the 74HC4066 isn't going to do the job.

Well, you will need two transistors - a PNP to do the switching of the positive input, and an NPN to switch the PNP. The problem resolves to exactly the same as "high side" switching to control an output device.

Thanks Paul! Yes you are correct voltage I'm monitoring is about 14V. I will build version with 2 transistors just as you suggested! I didn't know it mattered where you interrupt circuit. :slight_smile:

Current goes from emitter to collector when voltage applied to the base.

FYI,
The standard convention is to describe the direction of current from positive to negative. (despite the fact that electrons are negatively charged and are attracted to a positive charge). The reason (I believe) for this
convention is that it is easier to discuss circuit operation by talking about the current flowing from the source , through the load, through the collector , through the emitter to ground (which is the RETURN).
This is why the negative leads of loads is always described as the RETURN. If people talked about the current flowing from the emitter to the collector, they would be calling the ground the SOURCE and the positive lead the RETURN, which would be very confusing. If you have a circuit consisting of a battery, a
resistor and a led, you would say the current flows from the source , through the load, to the return lead
of the battery. (not the other way around). The ground leads of circuits are often referred to as the RETURNS. (returning to the source ground, the negative battery lead). Mike has been around longer than
I have so maybe he can explain the reason for that convention.

Ben Franklin made a guess about polarities and current carriers, and guessed wrong. It is that simple.

Ben Franklin made a guess about polarities and current carriers, and guessed wrong. It is that simple.

Well, there you have it...

Benjamin Franklin is the first person to correctly suggest the positive and negative nature of electrical charge. In Franklin's Fluid Theory of Electricity, he posited that electricity acted as a fluid moving through the planet. The theory called for "electrical fluid" to move through the ether as a single substance and not two completely different fluids per the contemporary belief of the time.

Franklin's mid-18th Century theory called for a neutral equilibrium of electrical fluid, with electricity flowing from an area of electrical excess to areas lacking the electrical "fluid". Franklin deemed the areas of excess "positive" - a flipped viewpoint from our current scientific understanding wherein electron rich areas likely hold an overall negative charge or a negative dipole.

Ben Franklin's Theory of Electricity

Electric Current: direction of positive charges

No it was not a guess, it was based on the action of electricity in liquids. The fact that electro plating happens to the cathode suggested current was flowing to the cathode and taking the metal with it. We now know this is not the case, it was a mistake based on the evedance avaliable not a guess.
Some how the guess theory has become an urban myth.

In the early days of semiconductors when all you had were PNP transistors you drew circuits with the neg at the top and described current flow from the neg to the pos. When NPN became more popular people swaped things over.

Grumpy_Mike:
In the early days of semiconductors when all you had were PNP transistors you drew circuits with the neg at the top and described current flow from the neg to the pos. When NPN became more popular people swapped things over.

Not necessarily. The convention of positive supply "at the top" originated of course much earlier, with thermionic valves.

(I said "thermionic valves" - is everyone happy now?)

Pedantic as ever, I never said it originated with semiconductors I said it was used in the early days of semiconductors.

In the early days of semiconductors when all you had were PNP transistors you drew circuits with the neg at the top and described current flow from the neg to the pos.

That was clearly before I ever got into electronics. I think I was still working as a short-order cook in restaurants (1967-1979). I didn't know what a resistor was then. (until I discovered HEATHKIT in 1979)

I said "thermionic valves" - is everyone happy now?

Are you guys all in GB ? Doesn't anyone call them vacuum tubes ?

raschemmel:
Are you guys all in GB ? Doesn't anyone call them vacuum tubes?

Well, not in Australia, no!

In a previous discussion, someone failed to recognise the term "valves", so it was suggested to prefix them as "thermionic valves". So that's what I did.

"Tubes" has a different meaning in Australia, and "vacuum" is something the XYL does to the carpet - they do not naturally coexist.

Fascinating conversation about voltage direction :slight_smile: I love nuclear phisics and I actually thought electrons didn't move at all, only EM field, but I was surprised to find out they they actually do move, just very slowly (about 0.02 cm per sec), although energy (electricity) is transferred much faster (1/100th sped of light). Which makes sense if you think of it as "Newton's cradle" :slight_smile:
Anyway back to the topic, I have one more question.
I found schematic I really like:
.
It works almost exactly as what Paul recommended. Is there any advantage for me to use FET instead of BJT? Lower current leakage?

P-channel MOSFET can have a much lower Rds (on-state resistance) and thus have lower voltage loss (= to Rds x current) vs a fixed voltage drop (0.5V to 0.7V) across a PNP transistor.

A Low Rds, Logic Level P-channel MOSFET, such as this thru-hole part, with .05ohm (50 mOhm) would have hardly any voltage loss across it.
A "standard" MOSFET will need 10V VGS to fully turn on, Logic Level parts need much less voltage swing, important when running off 4.5V battery pack or similar.

What is the battery voltage you are using? It's possible you won't need the NPN BC547 at all if the MCU can handle the battery voltage on its IO pins.