How to Determine Voltage Required

If I were to connect a sensor to a breadboard, for example the 8ohm speaker, how do you determine how much power is needed to use it and if any resistors are needed how do you determine the right type? In the tutorials they always just give you a list of stuff and a diagram and tell you to attach it, I want to understand more about why those parts are being used.

A speaker is an interesting example - it could be used as a microphone - a sensor, or as an output device (producing sound). Ultimately the decision about components comes from the specifications of the device, the laws of physics, and usually a little experimentation to see what works. For instance as a speaker you can do the calculations to build circuitry to drive the speaker to 1 watt - however you might have to do a little experimentation to work out if 1 watt is right for the application.

With a speaker we might expect sine waves to be involved - so you'd have to work out the peak-to-peak voltage given the rms voltage needed to produce the wanted power level (power = VI = IIR = VV/R - this works for rms and DC).

For an example lets say a 16ohm speaker is wanted with power upto 200mW (for speakers we always talk about the electrical power going into the speaker voice-coil - the acoustic power coming out is a lot less, and is roughly indicated by a specification called "sensitivity"). Power P = 200mW = 0.2W, R=16, therefore VV = PR = 3.2, therefore V(rms) = 1.79V. For a sine wave that means amplitude of 2.53V (multiply by square-root-of-2). Peak-to-peak is twice this, or 5.06V. Thus a single ended driver for the speaker needs somewhat more than 5V for that power level. A bridged driver can get away with half this.

For driving a loudspeaker only the resistance of the speaker itself is usually of interest. The power levels here (peak voltage 2.53, peak current 160mA) are much beyond the capabilities of an Arduino pin (40mA is the danger level). So amplification of some sort is required.

Hoping this is sort of the thing you're asking for...

In the Arduino world devices can be grouped into two loose groups - Active and Passive.

Active components do things by themselves and report the results back to the Arduino in some way, or the Arduino sends stuff to them and they do things with it by themselves.

Passive ones just sit there and the Arduino looks at them to see what they are doing, or they just take what the Arduino sends at it and throws it out in a different form.

Things like LDRs, Potentiometers, Thermistors, Speakers, Piezo transducers, LEDs etc are all passive.

Things like realtime clock chips, temperature sensors, and the like are active components.

For active components you will have to refer to the data sheet (kind of like the manual for the product - they all have them, you may just have to google around a bit). Passives, however, tend to follow simpler rules, and I shall outline those for you now.

There are three basic quantities you will be dealing with regularly. Voltage, Current and Resistance. The three are interrelated through Ohm's Law, which states that "the current through a conductor between two points is directly proportional to the potential difference across the two points.".

Voltage is measured in volts (symbol: V), current in amps (symbol: I, or A) and resistance in ohms (symbol R, or Ω).

So Ohm's Law tells us that the current I through a conductor R is proportional to the potential difference V across the two points.

For a simple resistor, say 10Ω, if we put a voltage of 5V across it, then we can predict the current that would flow through it.

I=V/R.

So, I = 5 / 10, which is 0.5A.

The formula can be re-arranged into any of three configurations. The other two are for voltage:

V=R×I

and resistance:

R=V/I

That is one set of forumulae you will use lots, so you should remember them.

So, most passive sensors operate either by changing their resistance, or by giving us a voltage. Most passive "output" devices operate on a certain current and voltage, and may have a resistance of their own.

Let's take the humble LDR as an input example. This has a resistance which changes depending on how much light is falling on it; hence the name "Light Dependent Resistor". How would we go about using it? Well, obviously the thing we want to find out is the resistance, which will tell us the light level. The Arduino, though, isn't capable of directly measuring resistance. The ADC inputs can only read a voltage. So, we need to craft a circuit that will convert the resistance of the LDR into a voltage that the ADC can work with.

Enter the "Potential Divider" (also known as a "Resistive Divider").

So we know from Ohm's Law that the voltage across a resistor is proportional to the resistance and the current. Change one value and one of the other values has to change as well. Now, supposing we took that resistor and split it in half. From our example above we would now have two 5Ω resistors instead of one 10Ω. With them joined together into a small chain, they would still sum up to 10Ω, so across the whole lot the voltage of 5V would still give us 0.5A. Now, what about if we were to measure the voltage at the point the resistors meet? Well, we know the resistance (5Ω), and we know the current (0.5A), so we can calculate the voltage at the middle as:

V=R×I = 5 * 0.5 = 2.5V

That's exactly half! So, at a point midway along the resistance we get the middle of the voltage. Cunning! Now supposing we split the resistor unevenly - say we had 3Ω and 7Ω. The same sum works. The total is still 10Ω, so the current is still 0.5A. So, with the 3Ω at the "bottom" of the chain (closest to ground), we have:

V=R×I = 3 * 0.5 = 1.5V

Now we're getting somewhere. Changes of resistances give us changes of voltage. Nice - now we can read those values with the ADC. But wait! Where's the LDR?

Well, let's put it into the circuit. The LDR can connect to 5V, then a resistor which is around the same value as the LDR in shade (say 10,000Ω) connects the LDR to ground. We then want to look at the voltage in the middle. Ah, but now we have two unknowns when we had only one before. This starts to get a little trickier.

So we know that the voltage across the whole shebang is 5V. And our Arduino is measuring the voltage in the middle of the chain, so we know that. We know that the "bottom" resistor is 10,000Ω. We don't know the top resistor (it's the LDR, and keeps changing), and we don't know the current (it depends on the total resistance, and that keeps changing). But don't fret - there's (yes, another) formula for that.

The middle-point voltage of a potential divider can be calculated by:

Vout = V2/(V1+V2) × Vin

Where R1 is our LDR, and R2 is our known 10,000Ω resistor. Vin is the 5V we know about alread, and Vout is the voltage measured by the Arduino. So, we can rearrange that formula using basic algebraic principles:

R1 = (R2×Vin) / Vout - R2

And bingo! Just feed in the numbers and bob's your uncle. Let's say the Arduino is measuring 3.86V at the moment.

R1 = (10,000 × 5) / 3.86 - 10,000 = 50,000 / 3.86 - 10,000

= 2953.37Ω

Magic! Now you have a value you can use for things in your program.

The same principle applies to other passive sensors, like thermistors. Once you have their actual resistance, you can calculate what that means in terms of what they are sensing.

Now, what about output devices? Well, let's look at the simple LED, shall we?

An LED is a semiconductor device. This means it has two special materials inside it with special properties. Where they join is called the "junction". This junction, in semiconductors, causes a drop in voltage. All semiconductor junctions have a drop, but different materials cause different amounts of drop. For instance, a normal diode might have a 0.7V drop. An LED, though, typically has a much larger drop, say 2V. They don't have a resistance though. So, using Ohm's Law, we can see that, if we put 5V across an LED, then the current would be the voltage (5V) divided by the resistance (0Ω). That's bad. That's infinity amps. That's Magic Smoke™ time. Either the LED will go pop, or whatever is providing the volts will go urgh. So, we need to limit that current somehow. The easiest is to give the LED some resistance.

So, looking at the trusty data sheet (or supplier's website) for the LED tells us it has a current it operates at - say 25mA (that's 0.025A), and we know the "forward" voltage of 2V (also from the data sheet). So, from our 5V we have 3V left to play with after the voltage drop of the LED. 3V, and 25mA - that's two of the magic three - sounds like Ohm's Law time again.

R=V/I = 3 / 0.025 = 120Ω

So, the LED needs a 120Ω resistor in with it to stop the Magic Smoke™ from being released.

The same applies to pretty much all devices you want to drive with the Arduino.

But, the Arduino can't drive everything directly. It can only provide an absolute maximum of 40mA out of any one of its digital pins, so if you want to drive something that requires more current than that, say a motor, then you're out of luck.

For that you need a device that you can control with the Arduino that can then go and control the device you want to use. Sort of like a remotely operated switch that takes very little current to operate.

That sounds like a transistor to me. The transistor is another semiconductor device, just like the LED, but it has 3 connections instead of 2. Put current in one terminal (the "base") and it switches the current on between the other two ("collector" and "emitter"). There's various different types of transistor, and they connect up in different ways, but the basic principle is the same. Let's take an "NPN Bipolar Junction Transistor" as our example - these are very common in the Arduino world.

Again, this transistor, because it is a semiconductor, with a junction, has a voltage drop, but no resistance - just like the LED. So, we cannot just put 5V straight into the base as the current would be infinite and the Magic Smoke™ would get out. So, again, a resistor is needed - just like the LED. The value is less critical though, as we aren't too bothered about how much current, just that there's not more than either the transistor or the Arduino can cope with. We can control a transistor with a tiny current, so a big resistor (say 1,000Ω or more) can be used.

There are plenty of other interesting components that are used alongside your sensors and transducers, but we'll leave those and their associated formulae for another day :slight_smile:

Thank you for the responses, they are very insightful and very in depth and they will come in handy. I have found a book called Tab Electronics Guide to Understanding Electricity and Electronics aka Tab Understanding Electronics. Since I'm not an EE, but a CS student hopefully I will be able to teach myself as I normally have to. Thanks.

A quick answer about driving a speaker is an LM386N1 (Full part name ) it is a 325 Mw audio amplifier it can be used it 2 modes one with a gain of ~20 and another mode (connection method) that will give you a gain of 200 which probably won't be useful here (too High)... So go get the data sheet and If you have problems still post them, there will probably be someone here to help. If it is just a tone or beep you wish to make a simple driver with a 2N3904 should work well. although it is a lot of power from the Arduino's power supply... Nearly 25% of it's 800 mA Max available current. The Audio amp canj be supplied from the 7 to 9V external PSU. Go get the data sheet and read it carefully. If you still have questions then Post them...

Doc