I'm thinking of connecting an LDR to ESP32 ADC (10kΩ to GND) and setting the interval to 10ms in ESPHome. The datasheet says I might need a bypass capacitor to reduce noise. Should I consider this? What would that entail? ...just connecting the leads of the capacitor to GPIO and GND?
It is very good that you read the Espressif documentation but you don't have to go that far. I learned everything of the ESP32 from this website: https://randomnerdtutorials.com/projects-esp32/.
Why do you need a update of the light of 100 times per second ? Is once per minute not enough ?
It does not make a big difference
You could add a capacitor, or you could take the average of a few samples in software, or just use the LDR value with its noise. It does not make a big difference.
A LDR is not accurate and its value also depends on the temperature and the light it measures is not the same as the light that we see. The analog conversion of the ESP32 is also not accurate. Don't expect too much from it.
The most common circuit is with the LDR to GND, and the 10k to 3.3V. Then the 100nF capacitor can be parallel to the LDR.
Trick for darkness
A LDR itself has a very large range. You can extend its range with two resistors. One of 1k and one of 100k. First power it with 1k, then with 100k, take the average of the two, and with some luck you can measure the difference between total dark and moonlight.
Be careful with sunlight
Don't put a LDR in direct sunlight. When it gets too hot, it will be permanently damaged.
Thank you for the detailed response.
I have a Lutron Caseta wall dimmer that drives an AC power receptacle behind my bed. When I turn on the switch, it turns on some 2700k LED bulbs on the floor behind my bed that are plugged into that AC receptacle. It takes about 1.5 seconds for the LED bulbs to transition from 0 to 100%. The LED bulbs are not very visible but the glow they cast on the wall makes for a nice ambiance. I have LIFX RGB bulbs on either side of the bed that create the real light for the room. I am using Home Assistant to run an automation: Wall dimmer LED bulbs ON > Turn on the LIFX RGB bulbs at 2700k on either side of the bed with a 1.5s transition time. So, ideally I could turn on the dimmer and the LED bulbs and LIFX RGB bulbs would transition up from OFF to ON in unison ...but there is a delay in sending the ON signal from the wall dimmer to the Lutron Smart Hub (and then to Home Assistant) and so the LIFX bulbs are playing catch-up.
-Side note, there is no delay when the same ON button is pressed on the Lutron Caseta Pico remote that I've paired with the dimmer switch, or when the ON setting is triggered in the Lutron App, because in these cases the Smart Hub is the go-between, and it sends the ON message to the wall dimmer (instantly!), and to Home Assistant at that same time. It works perfectly.
So, because I have some LDR handy, I thought I'd create an ADC sensor in an ESP32 under my bed, which I'm already using for my bed occupancy sensors. I'd mount this LDR at the base of one of the LED sockets on the floor, and when the LED turns on, Home Assistant will not have to wait for that delay between the wall dimmer and the Smart Hub before turning on the LIFX bulbs. ...so it will be a smooth transition.
...just because I can, and it'd be a fun thing to try.
Can you not just sense that power is going to that led ? Might be easier ?
Leds may also flicker at 100Hz - need to check that , although an LDR may not respond fast enough to notice it.
Do you have an output “ warning someone is in bed with you “
That's a good idea. Maybe one of these? ...in which case I would have real-time info as to the amount of current as well, correct? It would make for more precise brightness settings for the LIFX bulbs in my automation.
I've really tricked out this bed. It's a "disco bed"; I've integrated three separate LED Strips and I'm running MLSC, synching it with music in the room, etc. I have a 433MHz remote I'm going to use for quick lighting settings. The bed occupancy sensors are so I can automate home alarm on/off, and turn on some red lights in the room when I get up in the middle of the night, etc.
I'm actually yet to complete it. I'm just having fun letting my creative juices flow. I'm always thinking "what if I could do that?", and I keep playing as I go. It's quite fun. I think, ultimately, it might not impress anyone else, and might even have the opposite effect. But who knows what the future will bring.
Edit: I think I'll try the LDR first. I don't know if this little delay is worth investing in the current sensor over. I do have a question about ADC, now that I think about it.
If I have four FSR (one at each corner of the bed) for occupancy sensing with a time interval of 0.5s, and I have this LDR set to 10ms, is my ESP32-WROOM-32U going to be able to handle it?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.