Setting a potentiometer to increase the lifespan of an LED
You've already got the standard answer regarding a fixed supply voltage and some known LED forward voltage. But it is also possible to design a circuit that will be relatively efficient (you write, "optimium level for the longest life span") with respect to linear regulation, generally, and where you don't really need to know the LED forward voltage and where it will work well with a battery whose voltage isn't at all fixed over its lifetime. (A \$9\:\textrm{V}\$ battery will actually have a lifetime voltage that is: \$6.5\:\textrm{V} \lt V_{BAT} \lt 9.5\:\textrm{V}\$.) If you don't mind using BJTs, that is.







simulate this circuit &ndash; Schematic created using CircuitLab

The value of \$R_2\$ sets the current. Making it smaller increases the current and making it larger decreases the current in the LED. The value of \$R_1\$ is somewhat less important. Note that there is no need for a potentiometer (which is a good thing, I think.)

The circuit does require that the battery voltage be at least \$1.5\:\textrm{V}\$ more than the LED requires. But in your case, there are few LEDs requiring more than \$4\:\textrm{V}\$ to operate and your \$9\:\textrm{V}\$ battery will be completely dead by the time it reaches \$5.5\:\textrm{V}\$. So this circuit is fully functional throughout the battery lifetime.



To design this, start by first estimating the lowest battery voltage. I wrote above that \$6.5\:\textrm{V}\$ is a good minimum to use for a \$9\:\textrm{V}\$ battery. I figured two standard diode drops for the two transistors, so the base of \$Q_1\$ should be \$1.4\:\textrm{V}\$. (In reality, \$Q_1\$'s \$V_{BE}\$ will be \$120\:\textrm{mV}\$ more than \$Q_2\$'s \$V_{BE}\$ to account for the two orders of magnitude difference in collector currents. But the average between them will probably be about \$700\:\textrm{mV}\$, so no harm done here.)

At an LED current of \$18\:\textrm{mA}\$, the base current for \$Q_1\$ will be near or less than \$180\:\mu\textrm{A}\$. I decided from that figure that I wanted at least \$280\:\mu\textrm{A}\$ flowing in \$R_1\$ when the battery voltage was at its lowest point. So I computed \$R_1=\frac{6.5\:\textrm{V}-1.4\:\textrm{V}}{280\:\mu\textrm{A}}\approx 18\:\textrm{k}\Omega\$. With a completely fresh battery, the current in \$R_1\$ will then be \$I_{C_2}=\frac{9.5\:\textrm{V}-1.4\:\textrm{V}}{18\:\textrm{k}\Omega}=450\:\mu\textrm{A}\$.

Knowing that \$280\:\mu\textrm{A} \le I_{C_2} \le 450\:\mu\textrm{A}\$, I can now estimate that \$Q_2\$'s \$V_{BE}\$ will be about \$60\:\textrm{mV}\$ less than the typical \$700\:\textrm{mV}\$, or \$640\:\textrm{mV}\$. So now I can figure out that \$R_1=\frac{640\:\textrm{mV}}{18\:\textrm{mA}}\approx 35.5\:\Omega\$. I went with \$33\:\Omega\$ for the standard value here (because I know that the \$V_{BE}\$ may actually be a little less than I estimated.)

That's all there is for designing this. You don't really need to know the required voltage for the LED. It could be most any LED (all of them I believe I've seen, which are just LEDs and not entire circuits.)



It should be quite stable. Regulation of current through the LED should be in the area of \$\pm 2\%\$ over the range of battery voltage variations. However, there will be probably another \$\pm 4-5\%\$ due to part variations with the BJTs (which can be most any small NPN BJT you have laying around.) So if you build several of these, they will still be fairly close in behavior to each other.

Current efficiency is good. It wastes at most \$450\:\mu\textrm{A}\$ in order to provide \$18\:\textrm{mA}\$ for the LED, and as the battery voltage declines this added requirement also declines with it. This works out to around \$97-98\%\$ efficiency (in terms of assigning and regulating the current through the LED.) This control overhead should be relatively hard to beat in a linear regulator.



Since efficiency has come up, I thought I'd add a "switcher" version of the circuit that should work over the same range of voltage inputs and will be relatively efficient in power consumption. (Perhaps 75% efficient?)

It's a relatively simple modification to the above circuit:







simulate this circuit

\$R_2\$ has to be lowered a little bit in order to increase the peak current so that the average will be about right. \$R_1\$ gets moved over into the emitter leg of \$Q_3\$ and must also be adjusted by about the same factor, plus a little smaller yet because of some added voltage drops. \$L_1\$ gets inserted into the LED leg and now \$D_1\$ is required to provide a current path for the inductor when the switches are off. \$R_3\$ helps start the circuit and its value isn't critical. \$L_1\$ also isn't critical and a variety of inductors within a factor of 10 in value can be applied, I suspect; including a variety of copper resistance values, too. \$C_1\$ was added here because \$9\:\textrm{V}\$ batteries have notorious internal resistance.