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
usrnsf_ted
 
Posts: 24
Joined: Sun Dec 15, 2024 5:02 pm

Electronics 101

Post by usrnsf_ted »

Okay just about everybody here is smarter than me. So you don't have to tell me I already know. That's why I'm here to learn from you. With that said, I'll get on with it. Circuit: 3.3 volts from raspberry pi pin 1 To one side of a 10k resistor. On the other side of the 10K resistor we have two connections, one going to a gpio pen and the other going to a switch. The other side of the switch goes directly to ground. Gpio pin set up as input reads 1 when the switch is open 0 when the switch is closed. So far so good. What I don't understand is why it reads zero when the switch is closed. Obviously the gpio pin creates a complete circuit because you can't read voltage without some current. That circuit is still complete even when the switch is closed completing the other circuit. So why does my gpio pin read zero when the switch is closed. And yes, I recognize that ohm's law means the current will be negated by the resistor. But some current had to flow for the gpio pin to read one. Why is that current no longer flowing? Or do I have something confused? Please be gentle. And thank you in advance.

User avatar
adafruit_support_bill
 
Posts: 89644
Joined: Sat Feb 07, 2009 10:11 am

Re: Electronics 101

Post by adafruit_support_bill »

Your GPIO pin has a very high input impedance, so it is not reading current, it is reading voltage. With nothing connected except the 10K resistor to 3.3v, no current will flow, so the voltage at the GPIO pin will be 3.3v.

Ohms Law says that the voltage drop across the resistor is equal to the current times the resistance (V = IR). Since the current (I) is zero, so is the voltage (V).

Now, with the switch closed, you have two components between 3.3v and GND. The resistor is 10K and the closed switch has a (theoretical) resistance of zero. Once again, the voltage drop across the switch is governed by Ohm's Law. And regardless of the current flow, V = IR = 0 if R = 0.

So how much current does flow when the switch is closed? Since the pullup resistor is 10K: 3.3v / 10K = 0.00033A.

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

Re: Electronics 101

Post by T_Mo »

(only a community member)
Since the current (I) is zero, so is the voltage (V).
Just to clarify, this statement refers to the voltage drop across the resistor, not the voltage between the pin and ground.

User avatar
sj_remington
 
Posts: 1339
Joined: Mon Jul 27, 2020 4:51 pm

Re: Electronics 101

Post by sj_remington »

But some current had to flow for the gpio pin to read one
Current does flow, but only for a very short time until the gate capacitance of the MOSFET input transistor is charged.

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

Re: Electronics 101

Post by adafruit_support_mike »

usrnsf_ted wrote: Wed Jan 29, 2025 7:15 pm That's why I'm here to learn from you.
Point 1: that's why we're here. Nobody is born knowing the fundamentals. Everyone has to learn them somewhere. These forums were specifically created as a place where people can do that.

Point 2: questions about the fundamentals are usually hard.. proving 1+1=2 without saying "it just does" takes a ton of work, and relies on a bunch of intermediate ideas that are far from obvious.

So let me rephrase your query as "with this configuration of parts and connections, pushing the button makes the GPIO pin read 0 Volts. Why?" You've got the apparatus and a repeatable observation, both framed in terms a lot of intelligent people spent about 150 years piecing together. About half of them went their whole lives without being able to give what we'd consider a complete answer today.

Just running through the ideas, I count ten major names: Galvani, Volta, Oersted, Coulomb, Ampere, Faraday, Maxwell, Heaviside, Kirchoff, and Ohm. Two of their contributions were basically, "hey, this is interesting", four were "okay, I think I understand this piece", one put all the pieces together, one did the actual math, and two turned that math into something humans could understand.

Starting off with the observers, we have Luigi Galvani, who noticed that a frog's legs would twitch when connected between two different pieces of metal. He called the result "animal electricity". The same kind of twitching was known to happen when muscles were zapped by a spark created by rubbing amber with animal fur, which had been known since at least ancient Greece. The two-metal thing produced a continuous effect though, not just a momentary spark.

Alessandro Volta generalized that to a stack of copper and zinc sheets with salt water between them. That was more convenient than any other source of electrical phenomena. It also had the advantage that you could stack the layers on top of each other to produce stronger effects.

Hans Christian Oersted found that the needle of a compass moved when placed near a wire connected to one of Volta's devices. That established the existence of some connection between electricity and magnetism, but it also created the galvanometer.. by putting a coil of wire around a compass, there was suddenly a way to measure this 'electricity' stuff.

Charles-Augustin de Coulomb, who was primarily a mechanical engineer, gave us another one: the torsion balance. A rod hanging from a thin wire can rotate like the needle of a compass, and will respond to incredibly small forces.. you can measure the gravitational attraction between two golf balls with one. He used it to measure the force between objects charged to different voltages, and found that they behaved exactly the same way as magnets.

He described his results in terms of an 'electric fluid' because that's the best they had at the time. They also considered heat to be a liquid (phlogiston).

Andre-Rene Ampere generalized that by measuring the force between parallel wires connected to a Voltaic battery. That led to the idea of 'the amount of stuff flowing through the wire', or 'current', which he thought was composed of 'electrodynamic molecules'. A whole bunch of them would be Coulomb's electrical fluid, with the energy making them move from one place to another coming from Volta's device.

Georg Ohm took careful measurements of wires connected to batteries and developed a relationship between the concepts: the battery produced energy that made the electrodynamic molecules move. Current was the quantity of electrodynamic molecules moving through the wire at a given time. But the wire also had a tendency to prevent current from flowing, which Ohm called 'resistance'. The battery only provided enough energy to move a certain amount of current through a certain amount of resistance.

He was fired from his job as a physics professor for that. Not because he was wrong, but because he'd dared to publish work that contradicted the established experts. Worse yet, he'd relied on mere empirical evidence rather than reasoning from first principles.

Ohm was eventually vindicated because.. well.. he was right. Along the way we established the habit of describing the motion of electricity as current measured in Amperes. The energy that makes current move is measured in Volts, and the amount of 'electrodynamic molecules' in current is measured in Coulombs.

Michael Faraday, a self-taught lab assistant generally recognized as the greatest experimental scientist of western history, went through all the disparate observations of magnets and electricity sytematically and collected detailed observations. He discovered any number of things -- the rock stars of science have a constant or principle named after them.. Faraday has like, seven -- and developed a geometric description of how everything fit together.

James Clerk Maxwell, a mathematical genius, translated Faraday's observations into rigorous math. Unfortunately he did it with quaternions (four-dimensional vectors that represent rotation in space) so his paper contained 20 equations, each with 20 variables.

He got it right.. to this day Maxwell's equations are the tools that explain electromagnetic phenomena. They're just too complicated to use for practical work.

Oliver Heaviside, a self-trained telegraph operator, taught himself to understand Maxwell's equations. Then he invented vector calculus to express the same ideas a different way, and wound up with the four equations in four variables everyone calls 'Maxwell's equations' today.

Heaviside has kind of been written out of history because he had a habit of creating math that worked, but didn't bother to prove it to academic standards. Everything we do is based on his ideas, but we give the pieces different names.. he created operational calculus, we do exactly the same thing with Laplace transforms. He invented the step function, which we now call the integral of the Dirac delta function. He invented half the terms we use.. impedance, inductance, conductance, permeability, electret.. but nobody mentions his name. It's a case of history being written by the gatekeepers.

Gustav Kirchoff was a college student studying physics who realized the math got a *lot* easier if he made a couple of reasonable assumptions: the first is to assume the electrical fluid is ideal.. you can't squish it, stretch it, it doesn't spontaneously appear or disappear, and it moves instantly from one point to another. The short version is to say that the current flowing out of a wire has to be the same as the current flowing into the wire.

One important side effect of those assumptions is that current can only flow in a loop. You can't push it from one end of a wire to another without compressing it, and we're assuming that doesn't happen.

Kirchoff made a similar assumption that the energy making the current move doesn't appear or disappear. To put that in formal terms, if we start at any point on a current loop and add or subtract the changes in voltage as we go around, the sum will be zero when we get back to the starting point. If it didn't work that way you could get infinite energy just going around the loop over and over.

As it turns out, Kirchoff's assumptions work really well to simplify Maxwell's equations, leading to what's known as the 'lumped element discipline'.

Physicists have a tendency to explain ideas indirectly, leaving the useful parts as an exercise for the reader: if you ask them for Kirchoff's second assumption they'll say, "the sum of voltages around a loop is zero".. uh yeah, thanks.. why do I care? The idea that voltage doesn't just appear an disappear is 'implied'. Because of that, I won't go into the details of Maxwell's actual equations.. 'the divergence of the magnetic field around a closed loop is zero' isn't obviously relevant. The furniture he used to create them is more valuable for our purposes.

The first useful piece of furniture is 'surfaces', which we use to define the difference between 'here' and 'there'. For our purposes a surface has an inside and an outside, and it's impossible to go from one to the other without passing through the surface. Maxwell defined stuff that does go through a surface as 'flux', a second piece of furniture we can use to define current: it's the flux of electrons through a surface.

By those terms Kirchoff's first assumption is that the total flux over a closed surface is zero: everything that goes in has to come out, and everything that comes out had to go in.

Calculating the flux through a closed surface is a pain though.. you have to subdivide the surface into small pieces, measure the amount of stuff going in through each piece, subtract the amount coming out, add the results together, and yeah.. no thanks.

This is where we make another simplifying assumption: if we collect everything that goes in at one point, and collect everything that comes out at another point, there's no work left to do. You can use Maxwell's equations to prove that's okay as long as the surface is 'large' compared to the electromagnetic stuff inside it, and thanks to Kirchoff we can even assume the 'goes in' and 'comes out' values are the same.

That is the fundamental concept of a lumped electrical element: a 'component' is a surface where current goes in through one point and comes out through another. We call those points the component's 'terminals', and it makes sense to measure the voltage between them. Everything that might need to be explained by Maxwell's equations happens inside the surface. And the surface is large enough for the inside and outside to be independent systems.. nothing that happens outside the surface has any effect on what happens inside, and nothing that happens inside has any effect on anything outside.

By doing that we've reduced all electronics to components, the connections between them, and the measurable properties of voltage and current at the component terminals. All the Maxwell's equations stuff happens inside the components, and all they do is define a relationship between the voltage and the current.

Maxwell's equations tell us about two things we can do with electromagnetic energy: store it in an electrical field between charged surfaces, or store it in the magnetic field around moving current. Those give us two kinds of components: a capacitor is a component that contains an electric field, and an inductor is a component that contains a magnetic field.

We can also convert electromagnetic energy to other kinds of energy, with the most common one being heat. That gives us a third component: the resistor, whose voltage-to-current relationship is described by Ohm's Law.


That was a long-winded infodump of history and basic principles, but now we can use those pieces to approach your query:

When we connect the 'comes out' end of one resistor to the 'goes in' end of another, we say the resistors are 'in series'. The same current has to flow through both of them (because Kirchoff says current can't just appear or disappear), and we can find the voltage across each resistor from its value, the current, and Ohm's Law (because that relationship *is* the component).

That gives us a few easily calculated relationships: the combined value of two resistors in series equals the sum of their individual values. R(A+B)=R(A)+R(B). The current through series resistors equals the voltage across them divided by their series resistance: I=V/R(A+B). The voltages of the individual resistors are V*R(A)/R(A+B) and V*R(B)/R(A+B).

That's almost all we need to understand the behavior you see with the pull-up resistor and the switch: the last piece is to understand the pushbutton as a resistor with two possible values: about 1e-15 Ohms when the switch is open, and about 0.1 Ohms when the switch is closed.

With that, we can understand the resistor and button as two resistors in series: the 10k whose 'goes in' end is connected to 3.3V and whose 'comes out' end is connected to the switch, and the switch whose 'goes in' end is connected to the resistor and whose 'comes out' end is connected to GND.

Instead of trying to find some more complicated description of the system, we just assume it's two resistors in series with 3.3V across them at all times. The switch is just a resistor whose value changes. The current changes when its value changes, and that changes the current through the 10k. And changing the current through the 10k changes the voltage across it.

When the switch is open its value is around 1e15 Ohms, and the 10k in series with it barely counts as a rounding error. The current through the combination will be around 3e-15A, the voltage across the 10k will be almost nothing, and almost all of the 3.3V will appear across the open switch.

When the switch is closed its value is around 0.1 Ohms, which barely counts as a rounding error compared to the 10k. The current through the combination will be 3.3V/10k=330uA, and almost all the voltage will appear across the 10k.

It also helps to consider is the oriented nature of voltage across a resistor: the mathematical relationship that defines the resistor as a component says the voltage at the end where current goes in will always be higher than the voltage at the end where current comes out.

We're measuring the voltage at the end of the resistor connected to the switch, which we've already identified as the 'comes out' end. If the voltage across the resistor is 3.3V, the voltage at that end will have to be 3.3V lower than the voltage at the 'goes in' end. We established that the 'goes in' end is connected to 3.3V when we described the system, so the 'comes out' end will have to be 3.3V-3.3V=0V.

That matches the behavior you've observed.

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

Re: Electronics 101

Post by blakebr »

This is why I come to this forum!

Do we get the Heaviside layer of the atmosphere from Oliver Heaviside?

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

Re: Electronics 101

Post by usrnsf_ted »

First, thank you..
Second, if there's an award for being too smart, I'm nominating you for it.
That was awesome! Have a great day!

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

Re: Electronics 101

Post by usrnsf_ted »

Bill, T-Mo, and SJ thank you for your responses as well. All of it is helping me understand.

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

Re: Electronics 101

Post by T_Mo »

Happy to help.

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

Re: Electronics 101

Post by adafruit_support_mike »

blakebr wrote: Sat Feb 01, 2025 7:28 pm This is why I come to this forum!

Do we get the Heaviside layer of the atmosphere from Oliver Heaviside?
Yep.. he predicted its existence based on his understanding of transmission line theory (which he did a lot to develop) and observations of radio waves. Today we just call it 'ionospheric reflection'.

To get a sense of the mindset about Heaviside, you know how we always get articles about "observations from [new scientific instrument] confirm Einstein's predictions!" Imagine the whole academic and scientific community saying, "well he didn't actually prove it, so there's no reason to mention him."

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

Re: Electronics 101

Post by blakebr »

Mike,

OK... Einstein's predictions were later proven and he gets fame.
...... Heaviside's predictions were later proven and he gets erased.

Sounds like some snobs making the decisions on who gets remembered and who does not.

Bruce

P.S. This may be TL:DR.

When I was in high school and turned 16 I got a job at The University of Wisconsin, Space Astronomy Laboratory (SAL) during the summer. I was paid $1.00 per hour. In 1963 that was 10 cents above the minimum wage. Dr. Code and Dr. Houck were the astronomy brains, and Dr. McNall was the computer brain behind the computer systems for the Wisconsin Experimental Package on the Orbital Astronomical Observatory (OAO). It was the first orbiting telescope looking at the UV section of the spectrum. The frequencie's filters that were used were created in a vacuum chamber then tested by various people. I was one of them. From the random results of around 100 filters, 12 were selected for flight. Along with testing filters my pal and I build printed circuit boards. We etched with ferric chloride, drilled, gold plated, and assembled them. Dr. McNall designed them and we sent the designs out for the art work.

Now for the interesting part. Because the telescope was above the atmosphere there was no filtering of the UV radiation and we saw the true levels of UV for the first time. When we published the readings for the catalog of locations that were observed U of W SAL started getting unpolite letters that were telling us we were wrong. The observations could not be correct. About half the letters were from PHD candidates. The other half from PHDs. The problem was that our observations ran afoul of their PHD thesis's. Their calculations did not account for the much, much higher UV radiation readings. Part of the observation sequence was to look at calibration stars to test the photomultipliers. The data was accurate. The calibration stars were picked from suborbital rocket and X-15 flights.

Three telescopes were made. The telescopes were to last 6 months. It lasted 18 months. That was a good thing because the first one broke within 24 hours of arriving on orbit (That is another story.) The second one made it to orbit and was the one that lasted 18 months. The third ended up in the Atlantic Ocean after the second stage didn't ignite.

FYI, Astronomers act like little kids in a candy store when they learn they have time on a orbiting telescope.

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

Re: Electronics 101

Post by T_Mo »

Cool story.

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

Re: Electronics 101

Post by adafruit_support_mike »

blakebr wrote: Mon Feb 03, 2025 9:25 pm P.S. This may be TL:DR.
I have absolutely no standing to say such a thing. ;-) And T_Mo's right.. that's a great story!

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

Re: Electronics 101

Post by usrnsf_ted »

Okay I'm going to take a shot here and you guys poke holes in my theory. Between your answers and the study that I've done, here is my answer to my own question which was how does the ground change the original circuit?. For a refresher, here's the original circuit. 3.3 volts to a 10k resistor 10K resistor to a gpio pin on a raspberry pi. And the lead off that same pin to a switch and then to ground. The lead with the switch and the ground being the additional piece and me asking how this changes the original circuit which is 3.3 volts to the gpio pin. In other words, why does my GPIO pin read "1" until I close the switch and then it reads "0". Here is the logic as I understand it at this moment. Given that a gpio pin in an indeterminate state sometimes reads zero and sometimes reads one. 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. 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. However, when closing the switch, two things happen current flowing through the resistor creates heat. This heat effectively cancels the voltage from the source. The small amount of voltage already existing on the gpio pin now goes to The newly available ground now guaranteeing a a "zero". Now who will explain to me if the way I'm thinking is right or wrong and why?.

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

Re: Electronics 101

Post by T_Mo »

Your description really could use a sketch to visualize the connections.

Heat likely has nothing to do with it.

More likely the input gates have some capacitance, and unless you have a resistor to drain the capacitance, you'll get highly variable results.

Digital inputs have a threshold, usually with some hysterisis. So the voltage has to be above the threshold to read as a '1', and below the threshold reads as a '0'. Anything that hovers around the threshold could read as either level, depending on electrical noise that varies on a micro-seconds scale.

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

Return to “General Project help”