LED Dimmer: quickly restore the last-set brightness

  • Hi fellow MySensorists,

    I have put together an LED dimming prototype board using the instructions on the relevant Build page and the NodeManager documentation.

    Everything seems to be working but I have trouble implementing one crucial feature which is important for my application.

    My dimming application is a retrofit for a ceiling LED fixture which has no built-in dimming capability. My plan is to simply add my Mysensors based dimming board between the fixture's built-in 12V power-supply and the LED strips installed in the fixture. Thus, my Arduino would get the power from the fixture's power supply, same as the LED strips.

    In this setup, my Arduino powers up every time when the light gets switched on and powers down when the light gets switched off.

    I would like to switch the LEDs ON as soon as possible when the user flips the light-switch ON to have a good user experience. A long delay between flipping the switch and getting light is annoying (I also have some LED fixtures with slow PSUs and I hate them).

    Currently, I try to restore the brightness in the before() method but this still results in a 2s delay between getting power and the LEDs start emitting in the fixture. This is probably because long bootup time of the Arduino and the initialization of the radio.

    How could I get this delay down? (Ideally below 300-500ms)

    Is there a method which runs immediately after the Arduino powerup (before any kind of MySensors activity around the radio)?

    If the Arduino boot sequence is the main culprit for the slowness, how can I make it faster?

    Any insight is appreciated,

  • Mod

    @sola the main delay is caused by the bootloader. You can remove the bootloader (but then you need a programming device because the bootloader is needed for the Arduino IDE's upload feature). Or you can upload a bootloader with a shorter startup time (but there will still need to be a delay). See https://forum.arduino.cc/index.php?topic=501575.0 for more information.

  • @mfalkvidd
    Thanks for the help.

    If I use a programmer (like USBtinyISP) and thus remove the bootloader: How fast will it get? Will it completely eliminate the current boot time.

    It seems that the part of the Mysensors radio init which is happening before the before() method is very fast since I have also tried the Nano with a plain Arduino sketch and it is still ~2s before it starts executing.

  • Mod

    @sola yes the init should be very fast. But you can put your code in preHwInit() instead to make it run even earlier.

    I think the default bootloader delay is 2 seconds.

  • I have managed to upload with a home made programmer (my Uno as an AVR ISP) and test the behaviour without the bootloader.

    It seems to be very fast now even in the setup(), so I think this solves the problem for me perfectly. I guess it is now below 500ms, maybe even less.

    Many thanks for the help.

  • Mod

    @sola great! Thanks for reporting back.

  • add a li-ion battery backup and charging circuit so the node will never go down 😄

  • @rozpruwacz
    Actually, I considered that as the fallback solution but I do not want to increase complexity if there is a robust, simple solution.

Log in to reply

Suggested Topics

  • 2
  • 9
  • 3
  • 10
  • 24
  • 2
  • 15
  • 2