Using phototransistor to regulate LED brightness

I think about ways how to solve the indicator LEDs problem: when there is a lot of ambient light they are barely visible but in the dark (at night) they are too bright. In one of my projects I am using a photoresistor and PWM to control the brightness. But now I have realized there may be much simpler way: the current through a phototransistor is about linear with irradiance. Simply using a phototransistor in series with the LED should make the current (and so light output) nearly linear with the ambient light. It looks like a very neat trick. However I did not manage to find something similar on the internet. Maybe there is some hidden catch?

Even allowing for gain, phototransistors pass only a very tiny current.

Your LEDs require orders of magnitude more current to light them.

I did once see a design using the segment LEDs themselves as photodiodes.

Yes, I remember seeing something like that. Think it was an automatic night-light for a child's room or a hallway or something. The led was regularly switched off, for a very brief time, in order to use it as an ambient light detector.

Maybe you could simply connect an led and series resistor between A0 and ground. Set the pin to OUTPUT/HIGH to light the led. Set it to input and use analogRead() to read the voltage generated in the led by ambient light. The voltage generated would be less than 100mV I would guess. But you could use a voltage divider to reduce the 5V down to 100mV and connect that as an external voltage ref?

EDIT: just tested a high-brightness green led with a clear lens using my DMM. Got >500mV. Its not even a bright day. Wonder how the impedance of an Arduino analog pin compares to my DMM...

EDIT2: Dang! Of course, you can't do hardware PWM on an analog pin on atmega328. But you can do it on A7, A9, A10 of atmega32u4...

I find reading some sensor and converting it in some non-obvious way to PWM duty (and using one PWM pin) cumbersome. Ideally the LED brightness would be regulated automagically. Only turn it on or off by a simple digital write. If a phototransistor current is not enough I could add another transistor to boost it?

PaulRB:
Yes, I remember seeing something like that. Think it was an automatic night-light for a child’s room or a hallway or something. The led was regularly switched off, for a very brief time, in order to use it as an ambient light detector.

No, the one I saw was a seven segment, four digit clock.

Dammit, I’m going to have to search for it now.

Smajdalf:
I find reading some sensor and converting it in some non-obvious way to PWM duty (and using one PWM pin) cumbersome.

You're entitled to your opinion, of course. But another valid strategy is to use an MCU to minimise and simplify external circuitry as far as possible by using the built-in hardware & software capabilities of the mcu.

TheMemberFormerlyKnownAsAWOL:
I did once see a design using the segment LEDs themselves as photodiodes.

That's possible?
++Karma; // For teaching me something new :slight_smile:

There’s a well-known paper from Mitsubishi’s research labs that describes a device called the iDropper, which gives chapter and verse on using LEDs as photodiodes.

The clock I saw either did something like use the colon LEDs as the sensor, or one of the numeral segments (possibly all) by multiplexing, and then adjusting the LED duty cycle, but there’s so much junk out there searching is really difficult.