ESPHome ESP32 Photoresistor

Trying to use an analog read (photoresistor) to measure ambient light. This is a prof of concept to be able to read other ‘analog’ hardware.

However I can’t get it to work. When data is not connected I get random voltage values and when it’s connected I only get 0.0v even if moving sensor in front of a lamp. I’ve tried both 3.3v and 5v.

Any suggestions would be appreciated.

I’ve purchased Köp Ljussensor till rätt pris @ electrokit and thought I could use it with (Analog to Digital) Analog To Digital Sensor — ESPHome

The photoresistor module is used to measure light intensity. It can determine
the presence or absence of light.
This module consists of a photoresistor and a 10 kΩ in-line resistor.
The photoresistors resistance will decrease in the presence of light and
increase in the absence of it. The output is analog and determines the
intensity of light

Power is 5v

I’m running a ESP32 Wroom 32

Configuration

sensor:
  - platform: adc
    pin: GPIO32
    name: "Skylight Illuminance"
    update_interval: 10s

Startup

[20:12:41][I][app:105]: ESPHome version 1.15.3 compiled on Nov 20 2020, 20:10:30
...
[20:12:41][C][adc:026]: ADC Sensor 'Skylight Illuminance'
[20:12:41][C][adc:026]:   Unit of Measurement: 'lx'
[20:12:41][C][adc:026]:   Accuracy Decimals: 0
[20:12:41][C][adc:026]:   Icon: 'mdi:flash'
[20:12:41][C][adc:035]:   Pin: 32
[20:12:41][C][adc:038]:  Attenuation: 0db (max 1.1V)
[20:12:41][C][adc:051]:   Update Interval: 10.0s
...

running values

Data pin is not connected
[20:24:37][D][adc:056]: 'Skylight Illuminance': Got voltage=0.14V
[20:24:37][D][sensor:092]: 'Skylight Illuminance': Sending state 0.14183 V with 2 decimals of accuracy
[20:24:47][D][adc:056]: 'Skylight Illuminance': Got voltage=0.08V
[20:24:47][D][sensor:092]: 'Skylight Illuminance': Sending state 0.08166 V with 2 decimals of accuracy
[20:24:57][D][adc:056]: 'Skylight Illuminance': Got voltage=0.08V
[20:24:57][D][sensor:092]: 'Skylight Illuminance': Sending state 0.08166 V with 2 decimals of accuracy
[20:25:07][D][adc:056]: 'Skylight Illuminance': Got voltage=0.08V
[20:25:07][D][sensor:092]: 'Skylight Illuminance': Sending state 0.08193 V with 2 decimals of accuracy
[20:25:17][D][adc:056]: 'Skylight Illuminance': Got voltage=0.08V
[20:25:17][D][sensor:092]: 'Skylight Illuminance': Sending state 0.08166 V with 2 decimals of accuracy

Now I connect to D32 (GPIO32)
[20:26:47][D][adc:056]: 'Skylight Illuminance': Got voltage=0.00V
[20:26:47][D][sensor:092]: 'Skylight Illuminance': Sending state 0.00000 V with 2 decimals of accuracy

Connections

Not sure what that light sensor does, the chip part I mean.

Just the actual sensor at the end is a light sensitive resistor.
They can be used with a voltage divider to get an output.
Perhaps that is what the chip thing is supposed to do but perhaps the static resistor is not of correct value.

For starters have a read about setting an attenuation value on the ADC input. Then adjust that and see if that makes any difference.

Secondly, this is just a photresistor, so will work fine from 3.3V, but if you have used a 5V input to power it you may well have damaged your input, so try another one and stuck to using 3.3V power.

You can check your photoresistor is working just by using a multimeter.

Pin d32 may not be gpio32. See https://esphome.io/guides/configuration-types.html#pin

Success.
Short: Don’t fully understand what I did wrong before. Probably holding the hand over photoresistor wasn’t enough. Needed to put a finger on it!

Thanks everyone for all the great pointers :heart:

So I’ve setup a regular Photoresistor, figured out how to use the multimeter and getting “lux” differences. Connected it with 10k resistor to esp32. As soon the esp32 turns on the multimeter stops working on the ‘headphone 20k’ setting so changing to ‘v “with straight line” 20’ and getting some kind of differences.

Putting it on GPIO32 and ESP32 board D32 and getting 1.1v. However when I put my finger over the photoresistor something actually changes. I’m getting lower voltage.

Tried @picohassiotts suggestion and getting better values. This might actually work. getting around 50 - 255 in difference.

@Hellis81 to my understanding the board should be a 10k resistor.

Back to the board I got. First the multimeter measure gnd and data with ‘ohm?’ and getting values. Now connect it with esp32 (not changing any settings). The multimeter still works and now getting differences with 0 - 35.

@zoogara after using the suggested attenuation the lux values got even better due to reading of voltage higher than 1.1v. Lux now varies from 20 - 700 when using a simple photoresistor and 10k resistor. Will use this instead of the “boards”.

My final config

  - platform: adc
    pin: GPIO32
    name: "Skylight Illuminance"
    update_interval: 10s
    unit_of_measurement: lx
    attenuation: 11db
    filters:
      - lambda: |-
          return (x / 10000.0) * 2000000.0;
2 Likes

You know that is just * 200

1 Like