Electronics 101

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
westfw
 
Posts: 2082
Joined: Fri Apr 27, 2007 1:01 pm

Re: Electronics 101

Post by westfw »

Maybe this will help...

Suppose that the switch is NOT "perfect", and somehow has a resistance of 1Mohms when it's supposed to be "open" and 100ohms when it is supposed to be "closed", while the pullup continues to be 10kohms, and the input to the microcontroller continues to act essentially like a voltmeter, with near infinite input resistance.

So, when the switch is open, we essentially have a voltage divider from +5V to GND with a 10k resistor and a 1M resistor.
The total resistance is 1.01Mohms, and the current through the resistors (by Ohm's law) is 5/1.01e6, or about 4.95 microamps.
The voltage across the switch is 4.95e-6 * 1e6 (ohm's law again), or 4.95V - the pin "sees" 4.95V, which is close enough to 5V that it counts as a "1"
open.png
open.png (10.73 KiB) Viewed 62 times

Now, if we close the switch, we have a similar voltage divider, but now the total resistance is only 10100ohms, so the current is 5/10100 = 0.495mA, and the voltage across the switch is 0.495mA*100 = 0.0495V; the microcontroller sees that, and it's close enough to 0V that it counts as a "0"
closed.png
closed.png (10.87 KiB) Viewed 62 times

User avatar
usrnsf_ted
 
Posts: 26
Joined: Sun Dec 15, 2024 5:02 pm

Re: Electronics 101

Post by usrnsf_ted »

Image Okay simply, my understanding says if no current flows you can't read voltage. So a path to ground has to exist the other side of the GPIO pin thus completing a circuit from 3.3v to resistor to gpio to inboard ground. A second circuit runs 3.3v to resistor to switch then to ground. My question is 1. why does the flow of current to the gpio pin not trigger the "resistance" of the resistor. And 2nd why does closing the switch in the "second circuit" effect the first circuit. Nothing I see about closing the switch physically changes the first circuit. It is still a complete circuit. I know the answer has to be something regarding the activation of the resistor. but I still don't understand what changed in the first circuit and why the resistor didn't stop the gpio from reading a "1" since the same resistor and voltage are involved.
Attachments
Screenshot_20250205-194610~2.jpg
Screenshot_20250205-194610~2.jpg (16.64 KiB) Viewed 55 times

User avatar
T_Mo
 
Posts: 1719
Joined: Thu Mar 15, 2018 7:10 pm

Re: Electronics 101

Post by T_Mo »

my understanding says if no current flows you can't read voltage.
That's not quite right. In modern circuitry, logic levels are voltages. A digital input senses voltage, not current.
(there are some older logic families like TTL which used current flow, which I'm not discussing here).

A voltage drop happens when you pass current through a resistor. Voltage drop = Current * Resistance.
If there's no current through a resistor, the voltage drop is zero.

So in your sketch, with the switch open (and assuming there is negligible current into the Gpio pin), there is no current through the 10K resistor, so its voltage drop is zero, so the Gpio node is at 3.3 VDC. Since that's higher than the Gpio threshold value, it's read as a '1'.

If you close the switch, that ties Gpio to ground. Since 0 volts is less than the Gpio threshold, it's read as a '0'. SInce there is 3.3v across the 10K resistor, current will flow at a rate of V/R = 3.3V / 10K = 330 micro-amps into the GND node. The current doesn't go into the Gpio pin.

Note: I don't totally understand why the previous sketch showed the closed switch as a 100 ohm resistor. In practice the resistance of a closed switch will be so close to zero as to be negligible compared to the 10K resistor.

User avatar
westfw
 
Posts: 2082
Joined: Fri Apr 27, 2007 1:01 pm

Re: Electronics 101

Post by westfw »

if no current flows you can't read voltage.
Not true. You can detect (and measure) an electric field without any current flow, similar to being able to detect a magnetic field around a permanent magnet (in fact, there's a device called an "electret" that produces a permanent electric field without ever sourcing any current, exactly similar to a permanent magnet.)

The inputs to a modern microcontroller are MOS transistors, where a voltage on what is essentially a capacitor plate (the "gate") produces an electric field that changes the conduction properties between the other two terminals ("Source" and "Drain.") There's a (very) small amount of current involved when the gate changes state, because charges have to move to or from the "capacitor plate", but zero current in the steady state (in fact, "flash memory" stores data using charges on similar "plates", rather permanently.)

User avatar
adafruit_support_mike
 
Posts: 68386
Joined: Thu Feb 11, 2010 2:51 pm

Re: Electronics 101

Post by adafruit_support_mike »

usrnsf_ted wrote: Wed Feb 05, 2025 7:30 pm Okay I'm going to take a shot here and you guys poke holes in my theory.
That's excellent.

You're fitting the pieces currently in your mind together, and trying to align them with things in the world you can observe. That's the most basic practice of all science.. everything else sits on top of that. Everything useful you learn will be the result of what you're doing above.

But to give you advance warning, almost everything you do in that realm will be wrong.

People don't like that idea because schools have taught us definitions of 'right' and 'wrong' that are.. less than helpful.

As a first approximation, we can call an idea 'wrong' if it contradicts itself or some observable fact. On those terms, every idea in science is wrong. Logic itself is wrong; for a few thousand years the goal to prove all true statements ("completeness") while only proving true statements ("correctness"). In the early 20th century a logician named Kurt Godel proved it's impossible to do both at the same time.

The functional reality of science is: "All ideas are wrong. Some ideas can be useful in certain conditions."

That means we need better tools than just rejecting ideas as "wrong". We need to think about how they're wrong, how much they're wrong, and how much we care in the given circumstances. The only way to do that is to explore the ideas and find the boundaries of "wrong enough to care" in a given problem domain. And the only way to do that is to be wrong enough to care.

That's what this realm of thought is for. Finding problems is how we define success. Shying away from 'being wrong' like we're taught in school is worse than useless.

So let's run through the ideas you listed and I'll give you my thoughts:
usrnsf_ted wrote: Wed Feb 05, 2025 7:30 pm Given that a gpio pin in an indeterminate state sometimes reads zero and sometimes reads one
The word 'indeterminate' is typically used another way: 'Deterministic' means a system always behaves the same way in the same conditions, or gives you the same output for the same input.. basically 'predictable'. 'Indeterminate' is the opposite of that, meaning the system is fundamentally unpredictable.

It looks like you're using it to mean "the value isn't always the same" or "the value can change". The idea is correct, and it does fall in the more general meaning of 'indeterminate'. We normally use the word 'variable' for that idea, but that's a matter of social convention not a part of the idea we're talking about.
usrnsf_ted wrote: Wed Feb 05, 2025 7:30 pm And that it takes approximately 1.8 volts for that reading to change I conclude that there must be some small amount of voltage and therefore the potential for current on the gpio pin when it is not connected to anything.
The word 'potential' is exactly the same one people used historically.. voltage is considered a form of potential energy, and you'll still find the term in use in certain places. Another historical term is 'tension', which is why we call 100kV power transmission cables 'high tension lines'. It refers to the high voltage, not to the physical cables being pulled tight.

The units of electronics are a bit weird.. mechanics uses force, mass, and acceleration, but the concept of an electron's mass is problematic. Maxwell stepped around that problem by rearranging the units to remove any 'mass' terms.

That means we have to translate units when we want to find analogies to mechanics. One option is to compare voltage to speed and current to momentum. Another is to treat current as a mass moving up and down, and voltage as height.

We can extend that one to treat voltage as a kind of 'electrical distance', which makes it easier to see a certain detail: just like distance, voltage only makes sense if you measure it between two points.

There is a concept of absolute voltage: two electrons in a vacuum will repel each other, so it takes energy to push them together. We define the Volt as 1 Joule of energy per Coulomb of electrons, and there are about 6e18 electrons per Coulomb. Scaling that down, 1 Volt applies about 1.6e-19 Joules of energy to a single electron.

There is a distance between the electrons that corresponds to 1.6e-19 Joules of energy pushing them together (about 1.5nm IIRC). That condition is what we call "1 absolute Volt". It just isn't a very useful idea, for reasons I'll get to in a bit.

Your description looks like you were trying to treat voltage as an intrinsic property like mass rather than a relative property like distance. Doing so forces you to use ideas that don't work. That's far from obvious.
usrnsf_ted wrote: Wed Feb 05, 2025 7:30 pm When it is connected to the 3.3 volts through the resistor. Enough voltage is present to guarantee a reading of "1" But not enough current flows to engage the resistance of the resistor.
You need more tools for this one.

Another mechanical analogy for voltage is pressure.

The basic idea in quantum physics is that particles like electrons can exist in some locations, and can't exist in others. It takes a certain amount of energy to be near other particles, and electrons can only exist in locations where the value is an integer. When you pack lots of atoms together, some of the options get interesting.

Metals are one of the interesting cases: for some electrons (usually 1 per atom) it takes less energy for an electron to hop from one atom to another than it does for the electron to stay near any single atom for a long time. We call them "free electrons".

Free electrons can't go too far away from the atoms though, so they form what amounts to an electron gas around the atoms.

And since we already know voltage pushes atoms closer together, the gas is compressible.

That brings us to the idea of "charge density": the number of free electrons in a given volume of space. Higher voltages push the electrons closer together, producing higher charge density. Lower voltages make the electrons spread out, producing lower charge density. That idea makes voltage behave exactly the same way as pressure.

But that forces us to think about "absolute voltage" and "relative voltage".

Just like there's an absolute voltage of 1V, there's a charge density that corresponds to the electrons pushing against each other with 1.6e-19 Joules of energy.

Trouble is, there's no such thing as an absolute voltage of 0V in a universe with two electrons less than an infinite distance apart.. they're always pushing each other away with some tiny amount of force. Trying to work with absolute voltage is like trying to work with absolute vacuum.. a nice theoretical starting point, but impossible to do in practice.

What we actually do is choose some reference point and declare its absolute voltage to be our reference point.. we use the terms GND and 0V.. then measure every other voltage in the circuit relative to that. That means the numbers we use as voltage are always (absolute voltage of the point we want to measure) minus (absolute voltage at our 0V reference point), making "voltage" a relative value like distance.

That's a *long* way from obvious, and the way we talk about voltage in the lumped element model really doesn't give you enough cues to figure it out for yourself.

So when we say one end of a 10k resistor is connected to 3.3V, it means that the charge density at that end has 3.3 Joules per Coulomb more energy than the charge density at our 0V reference point.

Resistance doesn't control voltage directly, but does control how quickly electrons can move from one end of the resistor to the other. Ohm's Law expresses that as the amount of charge density we lose as a given amount of current flows through the resistor.

That's why I chose to describe the switch as a resistor with two different values, one of which is always in series with the 10k connected to 3.3V: it makes the model simpler. We could also say there's a theoretical capacitor between the free end of the 10k resistor and GND, but that's exactly the kind of thing we try to ignore when using the lumped element model.

So.. 'the switch has very high resistance when open' means it's very hard to push current through that resistance. Even pushing a few thousand electrons per second through it will use the entire 3.3 Joules per Coulomb of energy we have relative to the 0V reference point at the other end. It takes much less energy to push those few thousand electrons through the 10k resistance, so the charge density at the end of the resistor connected to the switch will only be slightly lower than the charge density at the end connected to 3.3V.

The switch having very low resistance when closed means it takes very little energy to move a huge amount of current through that resistance. Under those conditions the 10k resistor can't keep up, so we lose almost all of the 3.3 Joules per Coulomb of energy pushing current through that 10k resistance.

The current loses energy as it moves through the resistor, which means the charge density of the current has to decrease. By the time the current gets through the 10k resistor to the closed switch, the charge density is just barely higher than the charge density at the 0V reference point on the other side of the low resistance through the closed switch.

"Converting the energy to heat" is how the current loses energy and charge density. Electrons do still hop from one atom to another, and when a fast-moving electron hops to an atom, some of its energy gets transferred to the nucleus of the atom. It will have a little less energy when it hops away again, with the remaining energy staying behind to make the atom vibrate harder than it did before.

Now energy transfer does happen the other way: when an electron hops to a fast-vibrating atom, the electron picks up some of that energy. That energy isn't useful electrically though. It doesn't push the electron in the same direction as the rest of the current, if just pushes the electron in some random direction.

If we drop a closed surface around a few atoms, we'll see electrons leaving in every direction, matched by an equal number of electrons coming in from every direction. Since there's no tendency to move one direction more than any other, we can't call that electron motion "current".

If we expand the surface to go all the way through the resistor, we'll have an upstream side where current comes in, and a downstream side where current goes out. The resistance between those two sides means electrons come in through the upstream side a little slower at a higher charge density. Then the electrons will bounce off the atoms inside the surface, which has two effects: first, the atoms vibrate harder; second, the electrons have a little less tendency to move forward and a little more tendency to move in any other direction. Then they leave through the downstream side moving a little faster, but at a lower charge density.

If the resistance between the two sides is 1 Ohm, the current will lose 1 Joule of energy to vibration of the atoms for every 1 Coulomb of electrons that moves from the upstream side to the downstream side. If the current is 1A, that 1 Coulomb will flow through every second. If the current is 10uA, getting the same 1 Coulomb will take 10,000 seconds.

A 10k resistor will have 10,000 such boxes in series. A 1e15 Ohm open switch will have a million billion of them. A 0.1 Ohm closed switch will have a tenth of one box.

The current will naturally adjust itself so it loses the same amount of energy as it goes through every 1-Ohm box. Its charge density just before entering the first box will be the voltage connected to that end of the resistor. The current density just after coming out of the last box will be the voltage connected to the other end of the resistor.

So.. going back to the way you stated your idea: when the switch is open its resistance is huge, so almost no current can flow through it. That means almost no current flows through the 10k resistor. That tiny amount of current generates almost no heat as it passes through the 10k resistor, so it loses almost no energy by the time it reaches the other end of the resistor.

The charge density at the switch end of the 10k resistor will only be a tiny amount lower than the charge density at the end connected to 3.3V, so the end of the resistor connected to the switch will be only slightly less than 3.3V.

When the switch is closed its resistance drops to almost nothing, so the current flowing through that low resistance will lose almost no energy. That means the charge density at the switch end of the 10k resistor will have to be near 0V.

The difference in charge densities from one end of the 10k resistor to the other will push current through the resistor at a rate that loses 3.3 Joules of energy per Coulomb of charge. For a 10k resistor that comes to 330uA. The resistor will generate slightly more than 1mW of heat every second, and it will take about 50 minutes for the full 1 Coulomb to flow through it.

In electronics we consider the heat a side-effect though.. something we agree to think about when the physicists get all "blah blah, conservation of energy" at us. Otherwise we ignore it until something catches on fire.

User avatar
blakebr
 
Posts: 1470
Joined: Tue Apr 17, 2012 6:23 pm

Re: Electronics 101

Post by blakebr »

Hi,

How about an example I have used before.
Water pressure represents the voltage.
The water represents the current.
The valve represents the switch.
The hose represents a resistor.
The gauge represents a volt meter, transistor, FET, GPIO, etc.

Lets say we have a spigot with 33 pounds of water pressure when turned on.
Lets say we have 10,000 feet of cheap garden hose. We can't afford the good ones.
Lets say we have at the end of the garden hose connected to one side of "T", a pressure gauge at the junction and then the remaining side of the "T" is connected to a valve.
The output of the valve spills any water on the ground.

When the valve at the end of the hose is turned off the gauge will show 33 pounds of water pressure, and everywhere along the 10,000 (ohms) feet of garden hose it will measure 33 pounds of water pressure too.
The water is not flowing through the hose and no work is being done. (Just like if the switch is open)

Now if we fully open the valve and let the water flow freely the gauge will show very close to zero pounds of water pressure. Along the garden hose there will be a gradual reduction in water pressure from 33 pounds to zero pounds due to the resistance to water flow by the walls of the garden hose. Work will have been done by the water rubbing on the walls of the garden hose. That work will create a very small rise in temperature along each foot of the garden hose.

The needle of the gauge can be interpreted as a logic "1" aka True when the pressure is zero because work is being done. Water is moving from place to place. When the gauge shows 33 pounds no work is being done so the logic level is "0" aka False, and no work is being done.

The pressure gauge can be replaced by another valve that is controlled by water pressure on something.

Bruce

User avatar
usrnsf_ted
 
Posts: 26
Joined: Sun Dec 15, 2024 5:02 pm

Re: Electronics 101

Post by usrnsf_ted »

I want to thank all of you individually for your responses. They have all helped me learn and I'm sure I will have more stupid questions in the future.... Lol. It would seem that the key point error in my logic was in assuming that current had to flow in order to read voltage. I don't know if this will make sense but to me when I connected the red and black of a multimeter current had to flow between the two in order for me to read voltage. And I I then applied this principle to all circuits. Now that I understand or think, I understand the fact that the multimeter was actually reading the difference in "potential" between the two points, not necessarily requiring current flow between. Them things became more clear. Still muddy but I'm learning and that's largely thanks to all of you. So thank you for for the time and thought you put into your responses.

User avatar
T_Mo
 
Posts: 1719
Joined: Thu Mar 15, 2018 7:10 pm

Re: Electronics 101

Post by T_Mo »

the multimeter was actually reading the difference in "potential" between the two points, not necessarily requiring current flow between.
You are correct.

A voltmeter measures voltage (e.g. "potential").

Current flowing in a circuit (not your meter) is one way to get a potential difference, but not the only one.

User avatar
adafruit_support_mike
 
Posts: 68386
Joined: Thu Feb 11, 2010 2:51 pm

Re: Electronics 101

Post by adafruit_support_mike »

usrnsf_ted wrote: Sun Feb 09, 2025 5:26 pm It would seem that the key point error in my logic was in assuming that current had to flow in order to read voltage.
That's a reasonable thought, and no one had said otherwise. That's what talking through the ideas and looking for trouble spots is all about.

Post Reply
Please be positive and constructive with your questions and comments.

Return to “General Project help”