user47431: I want to install some LED stripes on my motorcycle, i.e. as brake light and indicators. I use WS2812 LED stripes which can be very bright - especially with many LEDs on at the same time.
I want to measure the ambient light so that in the bright sun I can light the LEDs with, let's say, 100%. But in the night maybe just with 30% intensity. I want to detect the ambient light to change the intensity.
I don't need high resolution and I don't need high speed. If the ambient light is measured i.e. once per second with 4 bit resolution that would be already good enough.
Which ambient light sensor (or photo diode or whatever) makes sense for this little project and how to connect it?
Does it make sense to use more than one light sensor for a better average ambient light value (just in case one sensor is in the shadow, another in the sun)?
I found these sensors form a Chinese supplier:
https://www.banggood.com/CJMCU-9930-APDS-9930-Digital-Proximity-And-Ambient-Light-Sensor-For-Arduino-p-1103139.html
https://www.banggood.com/GY-49-MAX44009-Ambient-Light-Sensor-Module-For-Arduino-p-1196674.html
But an I2C interface seems to be overkill for my simple project.
Any suggestions?

user40409: You can also use an LED. Connect the LED and its resistor between two port pins. Then, when you want to measure ambient light in your program, do this:

Make sure any pullups/pulldowns are disabled.
To discharge the LED, start with switching it on for a short moment (a clock cycle is enough) by setting the pins to output and setting anode high and cathode low.
Reverse the polarity by setting the anode pin low and the cathode pin high.
Set the cathode pin to input.
Using a timer and a pin change interrupt, measure the time it takes for the cathode pin to become low.

Since the capacity of the LED varies with light intensity, the time it takes for the LED to discharge through its resistor and the pin resistance is is an indication of light intensity.

user37523: Perhaps a LDR and a 10k ohm resistor might work.

#define LDRpin A0
unsigned int LDRvalue = 0;

void setup(){
  Serial.begin(9600);
}

void loop(){
  LDRvalue = analogRead(LDRpin);
  Serial.println(LDRvalue);
  delay(1000);
}


47431: <p>I want to install some LED stripes on my motorcycle, i.e. as brake light and indicators. I use WS2812 LED stripes which can be very bright - especially with many LEDs on at the same time.</p>

<p>I want to measure the ambient light so that in the bright sun I can light the LEDs with, let's say, 100%. But in the night maybe just with 30% intensity. I want to detect the ambient light to change the intensity.</p>

<p>I don't need high resolution and I don't need high speed. If the ambient light is measured i.e. once per second with 4 bit resolution that would be already good enough.</p>

<p>Which ambient light sensor (or photo diode or whatever) makes sense for this little project and how to connect it?
Does it make sense to use more than one light sensor for a better average ambient light value (just in case one sensor is in the shadow, another in the sun)?</p>

<p>I found these sensors form a Chinese supplier:</p>

<p><a href="https://www.banggood.com/CJMCU-9930-APDS-9930-Digital-Proximity-And-Ambient-Light-Sensor-For-Arduino-p-1103139.html" rel="nofollow noreferrer">https://www.banggood.com/CJMCU-9930-APDS-9930-Digital-Proximity-And-Ambient-Light-Sensor-For-Arduino-p-1103139.html</a></p>

<p><a href="https://www.banggood.com/GY-49-MAX44009-Ambient-Light-Sensor-Module-For-Arduino-p-1196674.html" rel="nofollow noreferrer">https://www.banggood.com/GY-49-MAX44009-Ambient-Light-Sensor-Module-For-Arduino-p-1196674.html</a></p>

<p>But an I2C interface seems to be overkill for my simple project.</p>

<p>Any suggestions?</p>
 40409: <p>You can also use an LED. Connect the LED and its resistor between two port pins. Then, when you want to measure ambient light in your program, do this:</p>

<ol>
<li>Make sure any pullups/pulldowns are disabled.</li>
<li>To discharge the LED, start with switching it on for a short moment (a clock cycle is enough) by setting the pins to output and setting anode high and cathode low.</li>
<li><a href="https://www.youtube.com/watch?v=QDaCMhKPGys" rel="nofollow noreferrer">Reverse the polarity</a> by setting the anode pin low and the cathode pin high.</li>
<li>Set the cathode pin to input.</li>
<li>Using a timer and a pin change interrupt, measure the time it takes for the cathode pin to become low.</li>
</ol>

<p>Since the capacity of the LED varies with light intensity, the time it takes for the LED to discharge through its resistor and the pin resistance is is an indication of light intensity.</p>
 37523: <p>Perhaps a <a href="https://www.aliexpress.com/item/20Pcs-Photo-Light-Sensitive-Resistor-Photoresistor-5528-GL5528/32651317086.html" rel="nofollow noreferrer">LDR</a> and a 10k ohm resistor might work.</p>

<p><a href="https://i.stack.imgur.com/i7xji.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i7xji.png" alt="enter image description here"></a></p>

<pre><code>#define LDRpin A0
unsigned int LDRvalue = 0;

void setup(){
  Serial.begin(9600);
}

void loop(){
  LDRvalue = analogRead(LDRpin);
  Serial.println(LDRvalue);
  delay(1000);
}
</code></pre>
