I'm beginner in electronics but what the hey.
You can use a regulator but I think it's an overkill.
The other way is to drop 4V through a resistor. Let's say your circuit
requires 30mA.
So we have Vcc=9v I=30mA.
Now we can use OHMs law to figure out the resistor that can drop 4V.
V=4v I=30mA
V=IR
R=V/I=4/(30/1000)=133.33ohms
130ohms is good enough. Sometimes the resistance is good to be a little more
than the required so you might add another 10ohm resistor in series to make
it 140ohms.
Also, you have to consider the power of the resistor as well. Since we're
dropping 4V through the resistor and the current is 30mA=0.03A then using
the power equation, P=I*V=0.03*4=0.12Watts which is less than 1/4 so we can
use a resistor that is rated at 1/4Watts.
Check out the resistors at:
http://www.radioshack.com/search.asp?find=1/4w+resistor&SRC=1
You can put 4 resistors in series as follows: R=100+10+10+10=130ohm
So far we have the following:
R=130ohms
----------/\/\/\--------o
|
| Vcc=9V
---
-
|
|-----------------------o
Now we add the potentiometer which will vary the voltage between 0 and 5V.
That means it has to be able to drop 5volts at its max position. That means
the max ohm value you want is:
V=5v
I=30mA
V=IR
R=V/I=5/.030=166.7ohms
Find a pot with a max value close to that. Then connect it as in the
following diagram:
R=130ohms Pot=0ohms min, 167ohms max
--------/\/\/\-----(o)-----o Vout
|
| Vcc=9V
---
-
|
|--------------------------o Vgnd
Someone please correct my if I made a mistake. Like I said, this was a good
exercise for a beginner liky myself.
Say if a battery has rated at 600mAh(miliamp hours) and you need 30mA as
described above, you can use it for 20 hours non-stop. It will vary though
depending on the circuit you attach to the outputs Vout and Vgnd.
Or instead of using a resistor you can use a zener diode. Maybe someone with
more experience can help you out in the more efficient and correct ways to
accomplish this circuit.
Hope I could be of some help.
--Viktor