Wemos D1 mini and photoresistor

Greetings
I had a photoresistor like this, 30pcs 5mm gl5516 light dependent resistor photoresistor ldr Sale - Banggood.com, connected to a Pi2 using a very basic capacitor based A2D-converter and a python script calculating the result. Can the same resistor be connected to a Wemos D1 mini as a digital sensor? I’ve tried to with the A0 port but I’d like to use the photoresistor with the power_meter component and that requires a digital input.
I was sort of thinking the resistor goes “high” when there is a light and sets the Esphome sensor to high triggering something. But I might be wrong.

Regards
Fredrik

That is possible.
It’s the same principle as a light sensitive relay.

You need to connect the photoresistor in series with another resistor between 3.3 volt and ground.
Then connect between the photoresistor and the other resistor a wire to a pin.

This is what is called a voltage divider and what you now need to figure out is what the “other” resistors value needs to be.

If you connect the photoresistor to a multimeter and test the range of light you have in mind then you will see what the resistor value is.
Using something like: https://www.allaboutcircuits.com/tools/voltage-divider-calculator/
If the photoresistor gives you about 5000 ohms when you have the lights on and say 50 kOhm when it’s off then a 20 kOhm resistor will probably be a good choice.

With 50 kOhm the output is 2.6 volt which should not trigger the pin.

Hmm, I must either have messed up the resistor choise or the photoresistor isn’t quick enough. I have one of those power meters that gives 1000 light pulses for every kWh, I’ve taped the photoresistor over the power meter LED and the voltage reading between the “out pin” and Wemos GND is a constant 0.68 volt.

/Fredrik

Constant reading seems to suggest it’s picking up a lot of background light.
You need to make sure it only sees the light from the LED.

It could also be that the LED is not bright enough or does not light up long enough to trigger the photo resistor.
What happens if you set the multimeter across the photo resistor and set it to resistance?

I’m facinated by electrical engineering but willfully admit it’s not my strongest subject. My multimeter has a dial for 2000k Ohm and at that setting the digital reading is roughly 1100 and jumps to roughly 400 when the LED blinks. The multimeter is not the most expensive and it takes the reading 1 second to return back to 1100 which makes me think the photoresistor isn’t suitable since the LED blinks rapidly when there is high load.

/Fredrik

Let me just get this straight.
When the LED is off you get a reading of 1100 Ohm, and when it’s on 400 Ohm?
That is far less than I expected.

The multimeter has the dial at 2000k, doesn’t that mean the resistance is 1100k without the led and 400k with the led?

Using the link I linked to earlier if you have a 4.7 or 3.9 MOhm resistor then it seems you should be fine.
With 400 kOhm on the photo resistor you get 3.04 v, should be high.
With 1.1 MOhm on the photo resistor you get 2.67 v which should be considered low.