This convention to assume that the current goes from - to + when it physically the other way around is something I don't really understand.Brandon92 wrote: ↑Mon Feb 11, 2019 9:02 pmWell, if you look at the electrons. They indeed move from the (-) to the (+). However, by convention we decide that the current flows from (+) to (-). More info
So, in your case, (if we make the input of the Rpi infinity), the current will go from "power supply" -> Echo -> R1 -> R2 -> ground -> "power supply". And this is indeed one of the kirchoff laws.
And to give you a simple example of your setup:
The current that will flow out of the echo is: I=U/(R1+R2)=5/(330/470)=6.25mA. So, there is indeed 2.9V across R2 and the voltage across R1 is 2.1V. And the voltage across R1 and R2 are together 5V (Kirchhoff's voltage law). And if you remove the R1, the current can not make a full loop at where he started as showed in this picture:
*https://learn.sparkfun.com/tutorials/vo ... viders/all
And the next question you need to ask yourself, can the HC-SR04 deliver the 6.25mA?
Blame the 18th & 19th century physicists for this.
Thanks for the reply. Yeah, it would be ~ 0,011 A with only R2 (470 Ohm) and accordint to the Kirchhoff law the resistor R1 woudln't even reduce the voltage, or what? U would be I * R, so ~0,11 A * 47 Ohm, thus ~5 V.Brandon92 wrote: ↑Tue Feb 12, 2019 6:38 amYes, physical the current flow from - to +. But we dicided to make it goes from + to -. To make it easier for or self. (Easier to calculate for example, you don't need to thing much about the - sing.)
Anyway, this explanation we use the convention way.
So, let's assume that a F1 car is the current and that if goes around a oval race track. Where the start and finish is the echo. And R1 is one big turn of the circuit and R2 is the other one.
When the echo is enabled the F1 cars are beginning to race and everything is happy. Because they can make all the laps they want. So, now we cut the whole R1 turn. This means that the F1 cars can not complete the circuit any more. And they can not move to the finish any more.
So, if they are not moving through the R1 turn. There is also no current through the resistor R2, and no current means that there is also no voltage across that resistor.
So the current want to make always a full circuit. And if you make the R1 resistor a wire, what has a very low resistance. The total resistance has changed and the 6.25mA is not true any more. Try to calculate this
Thanks for your reply. Getting into physics/electricity it seems to me very illogical to not adapt the schemes to physical reality. Physics as subject has the reputation to be logical, but then it is so illogical in this, only because it would be too much effort to adapt. I don't bother so much about the Greek letters, but this logical issue is difficult to understand from the point of view of someone who has an arts degree. Anyway, that's another topic.Burngate wrote: ↑Tue Feb 12, 2019 12:09 pmBlame the 18th & 19th century physicists for this.
They could see strange things happening when they connected differing metals, with chemicals between them, or when they moved magnets inside coils.
There appeared to be a flow of something, but they hadn't a clue what that something could be, or which direction it was going.
Nor did there appear to be any way to find out.
So they made a random choice - which turned out to be wrong.
A bit like trying to convert the whole world to driving on the sensible side of roads, assigning the charge on the electron a positive value would be possible, but is unlikely to happen.
So, indeed, in your diagram, electrons set off from the ground pin, go through your two resistors, and into the Echo pin - from where they're sent through the 5v pin to the power supply which pushes them to the ground pin, again.
How many electrons go round that loop per second is determined by the resistance of the whole loop - lower resistance means more electrons/second.
Since the charge on the electron is rather small, and so the number of electrons would be astronomical, we tend to talk about the total charge rather than the number of electrons, calling them Coulombs (after the bloke of that name, 1736 - 1806, another of those pesky early physicists) and then promptly ignore him, in favour of the Amp (Andre-Marie Ampere, 1775 - 1836) which is just Coulombs/second.
So, to make the voltage (Alessandro Giuseppe Antonio Anastasio Volta, 1745 - 1827) across the 470Ω resistor R2 about 3v, we need 6¼ mA to flow through it.
For that to happen, the total resistance in the loop has to be about 800Ω. Hence R1.
And just to fill out the dates, Georg Simon Ohm 1789 – 1854. Whoever decided to use the Greek letter Omega hadn't encountered the standard QWERTY keyboard - another irritation.
procount wrote: ↑Tue Feb 12, 2019 1:00 pm@cloudapplepi - I'll have a go at trying to explain, because I think Brandon mis-interpreted your "removal of R1" suggestion as to have no connection (open-circuit), whereas I think you were intending to replace it with a straight wire (short-circuit) ....?
So I'll assume this was your thought process.
I like to use a plumbing analogy to explain electricity (it breaks down in some places but it helps to get the point across),
Try to image the electrical circuit as a central heating system, where the battery is the boiler, the wires are pipes and the resistors are radiators.
In your diagram the ultrasonic sensor represents the boiler, with the echo pin providing hot water, and the cold water from the radiators is returned to the ground pin.
When the sensor detects something, the boiler turns on to produce the hot water which is pushed out of the echo pin and through the R1 "radiator". When it gets to the pin 18 connector, it has a choice - does it go through radiator R2 and back to the ground pin to complete the circuit, or does it go into pin 18?
This choice is decided by the resistance of each pathway. If each path was of equal resistance, you would find half the water goes through radiator R2 and half would go through pin 18.
Suppose you started to close down the valve on the radiator. This restricts the flow of water by increasing the "resistance" of the radiator. The water would find it harder to go that route, so more water would go though pin 18 instead.Conversely, if you open the radiator valve, its resistance is less and more water would flow through it and less through pin 18.
So what is the resistance of Pin 18? Brandon already gave you the answer that it is very high (infinite maybe), like a very, very narrow pipe. So how much water will flow though it? Hardly any. So you can assume all of the water is flowing through Radiator R2.
Suppose we close the valve completely on Radiator R2. It now has infinite resistance and no water will flow. No water can flow through pin18 because it is also infinite resistance. So no water can flow through Radiator R1 either, because it has no where to flow to. So what happens?
Well, the boiler is still on and trying to push water out of the echo pin and pressure is building up in your pipework.
How much pressure is pin 18 feeling? All of the boiler pressure! So you are about to kill it.
Let's try and bring this analogy back to electricity.
The flow of water is the same as the electrical current. The pressure of the water is like the voltage.
When the resistance R2 is very high, there is no current flowing in the circuit, but there is a lot of voltage (pressure) at pin 18, in fact it is the full 5v, more than the 3V3 that Pin18 can handle.
In your first post you assumed the resistor could reduce the voltage on its own. But it can't. Current needs to flow through the resistor for the voltage to drop.
It's all to do with Ohm's law that states V=IR : The voltage(V) developed across a resistor(R) is proportional to the current (I) flowing though it.
So if there is no current flowing though R1, it produces no voltage across it and the voltage at pin 18 is the voltage at the echo pin minus the voltage across R1. 5V -0V = 5V
So you need current to flow through R1 and you do that by having R2 in the circuit to allow the "water" to flow back to the "boiler"
How much current is flowing?
Well, we know from Ohm's law that V=IR. The voltage (V) at the echo pin is 5V. The resistance is (R1+R2), so the current I=V/R = 5/(R1+R2)
In your example I = 5V(330+470) = 5V/800 = 6.25mA
Now we can calculate the voltage developed across R2 alone.
So using V=IR again, V= 6.25mA * R2 = 6.25mA * 470 ohms = 2.9V
So back to your question about removing R1.
If R1 is removed and no wire replaces it, then the water from the boiler will spill onto the floor and ruin your kitchen! In this case you don't have a complete electrical circuit and nothing will work (like Brandon's answer).
But suppose you replace it with a wire of zero resistance.
Let's go through the calculation again. How much current is flowing through the circuit now?
Using V=IR, The 5V at the echo pin = current x the resistance R2
5V= I x 470, so I=10.63mA. So more current is flowing now.
What is the voltage at pin 18?
It's the same as the voltage across R2.
So V=IR = 10.63mA x 470 ohms = 5V.
Looking at it another way, there is no resistance between the echo pin and pin 18 to lower the voltage from 5V.
Be careful how you interpret what I said in relation to your simple circuit.
Thanks. Very useful links, got to bookmark them.pcmanbob wrote: ↑Tue Feb 12, 2019 2:59 pmWith the 3.3v gpio any voltage above 1.8 - 2.0V should be seen as a high input, when assembling a potential divider using resistors I normally aim for 2.9V on the gpio pin , this allows a little leeway for the resistor tolerances, because no resistor is ever its stated value.
If you want to see how changing your resistor values will change the output voltage have a look at these sites, handy if you have some existing resistor and want to see if you have some suitable values.
https://www.electronics2000.co.uk/calc/ ... ulator.php
https://www.random-science-tools.com/el ... ivider.htm
Thanks again for the reply.procount wrote: ↑Tue Feb 12, 2019 3:43 pmWell, I hope my ramblings clarified a few points for you.
Be careful how you interpret what I said in relation to your simple circuit.
The one resistor R1 connected between Echo and PIn 18 wouldn't change the voltage ONLY BECAUSE there is no current flowing in it because pin18 is such a high resistance. As soon as current flows through the resistor, a voltage will develop across it and the voltage at pin 18 will be the 5v at the echo pin minus the voltage developed across the resistor (IR). Use the webpage that pcmanbob linked to to see how varying R2 will affect the voltage at pin 18.
The simple equation for this voltage divider is: V_pin18 = Vecho X R2 / (R1+R2)
Note that resistors come in specific standard values (like 330 and 470), so you can't always pick the exact value you need. You might have to manufacture a value by putting resistors in series or parallel to get what you actually need. But the combined value of parallel resistors is another story.
There is also a balancing act to be done between the voltage you want and the current you want.
With the values of 330 & 470 Ohms you have chosen, Vpin18 will be 2.9V and the current flowing is 6.25mA.
You could also have chosen 3.3K and 4.7K to give the same voltage, but the current though the voltage divider would be 0.625mA (ie. 10x smaller)
In your LED example, you are not using the resistor as a voltage divider, but just as an essential current limiter.
If you connect the resistor between the positive of an (imaginary) 5V battery and the LED and leave the other side of the LED disconnected, then, (obviously) no current will flow in the resistor because the LED looks like an infinite resistance (like your pin18). The voltage at the LED will be the same as the battery. But when you connect the other side of the LED to the negative side of the battery, current will flow through the LED and in the resistor and cause a voltage drop across the resistor. LEDs are not like resistors because they are non-linear. Consider that they have no resistance, but have a fixed voltage drop across them. (Let's say 0.2V for simplicity).
So you can calculate the current flowing through the resistor using V=IR again.
Assuming some random figures of battery = 5V, LED voltage drop = 0.2V, resistor = 470 Ohms,
(5V-0.2V) = I x 470 ohms
I = 4.8V/470 ohms
I = 10mA which is probably enough to let the LED glow safely but dimly. (LEDs will consume as much current as they can, but if they exceed their current rating they tend to die, hence the need for the current limiting resistor).
In answer to your other questions, yes you can solder it as you have painted.
Every logic pin has a minimum "turn-on" and a maximum "turn-off" voltage value and this will be specified in the data sheet. Pcmanbob indicates for 3.3V systems, the minimum turn-on is typically around 1.8-2.0V, so resistors that give you a value between that and 3V should be ok.
Thanks. That's a good explanation.rpdom wrote: ↑Wed Feb 13, 2019 8:39 amI don't know if this will help the understanding, but I'll have a go.
Imagine a longish metal rod. Put one end in a flame (5V) and the other end in a bucket of ice (0V). About 2/3 of the way along that rod from the cold end it will be quite warm (3.3V). That's where you connect to it.
The rod is like the two resistors put together. The join between the resistors is like that point 2/3 the way along the rod. By changing the resistor values you are changing where you feel the heat (which voltage you will get).
If you only have one resistor you will only have no middle point to connect to. You only have the hot end or cold end.
A ladder analogy would have worked well. After all, you do get resistor ladders made from several resistors in series giving many different points where you can tap off different voltages.