Detection on LDR-sensor


I have a code that doesn’t work as I intended. It is a stepper motor connected to a drum with holes that let light through when spinning and when the LDR sensor registers the light, the motor should stop. The LDR sensor reads the light conditions according to the logs and during perhaps 700 msec the light changes but the detection does not seem to have time to register the change. If I check the logs, you can see that the value goes up to close to 3v for a short while and then goes back to ~0.45v. How can I make the condition more responsive? I’ve tried increasing/decreasing the update time on the sensor, I’ve decreased the speed of the motor but now it runs way too slow and the detection still doesn’t happen.


  • platform: adc
    id: ldr_sensor
    pin: A0
    name: “LDR Sensor”
    update_interval: 500ms
    • multiply: 3.3
    • lambda: |-
      if (isnan(x) || x < 0.2) {
      return 0.2;
      } else {
      return x;


  • platform: uln2003
    id: my_stepper
    pin_a: D1
    pin_b: D2
    pin_c: D5
    pin_d: D6
    max_speed: 100 steps/s
    sleep_when_done: true


  • platform: template
    name: “test button”
    id: my_button
    • stepper.set_target:
      id: my_stepper
      target: 600
    • delay: 2s
    • output.turn_on: led_pin
    • while:
      lambda: “return id(ldr_sensor).state > 1.70;”
      - output.turn_off: led_pin
      - stepper.set_target:
      id: my_stepper
      target: 0