Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Announcements
  3. 💬 Dimmable LED Actuator

💬 Dimmable LED Actuator

Scheduled Pinned Locked Moved Announcements
59 Posts 27 Posters 13.7k Views 27 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • hekH Offline
    hekH Offline
    hek
    Admin
    wrote on last edited by hek
    #1

    This thread contains comments for the article "Dimmable LED Actuator" posted on MySensors.org.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jeti
      wrote on last edited by
      #2

      Hi,

      i am still kind of a beginner in programming...:disappointed:

      how does the:

       * This sketch is extensible to support more than one MOSFET/PWM dimmer per circuit.
       * http://www.mysensors.org/build/dimmer
      

      work?

      i have tried starting with adding a "_1" LED_PIN and other stuff:

      #define LED_PIN 3      // Arduino pin attached to MOSFET Gate pin
      #define LED_PIN_1 6      // Arduino pin attached to MOSFET Gate pin
      #define FADE_DELAY 35  // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
      
      static int currentLevel = 0;  // Current dim level...
      static int currentLevel_1 = 0;  // Current dim level...
      MyMessage dimmerMsg(0, V_DIMMER);
      MyMessage dimmerMsg1(1, V_DIMMER);
      MyMessage lightMsg(0, V_LIGHT);
      MyMessage lightMsg1(1, V_LIGHT);
      
      /***
       * Dimmable LED initialization method
       */
      void setup()  
      { 
        // Pull the gateway's current dim level - restore light level upon sendor node power-up
        request( 0, V_DIMMER );
        request( 1, V_DIMMER );
      }
      
      void presentation() {
        // Register the LED Dimmable Light with the gateway
        present( 0, S_DIMMER );
        present( 1, S_DIMMER );
        
        sendSketchInfo(SN, SV);
      }
      

      , but this does not seem right, as i can not differentiat between for the input :confused:

      thanks in advance

      1 Reply Last reply
      0
      • thazlett144T Offline
        thazlett144T Offline
        thazlett144
        wrote on last edited by
        #3

        It looks like you are trying to add another LED/Mosfet? I have done it this way, I have 3 on mine:

        To do this I may or may not have used some examples I found on this forum. I basically add the pins I am using (PWM capable) into an array. I have 4 pins defined (3 is in there twice) to get around the array references starting from 0. Probably a better way to do that but this was my quick way round it.

        I have basically adapted the code from the example LED Dimmer sketch to work with the array / multiple child devices.

        Hopefully thats helpful and what you were after?

        // Enable debug prints to serial monitor
        #define MY_DEBUG 
        
        // Enable and select radio type attached
        #define MY_RADIO_NRF24
        //#define MY_RADIO_RFM69
        
        #include <SPI.h>
        #include <MySensors.h> 
        
        #define SN "MultiDimmableLED"
        #define SV "1.1"
        
        #define noLEDs 3
        const int LED_Pin[] = {3, 3, 5, 6}; //put 3 in twice as a start from 0 workaround
        
        #define FADE_DELAY 10  // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
        
        static int currentLevel = 0;  // Current dim level...
        MyMessage dimmerMsg(noLEDs, V_DIMMER);
        MyMessage lightMsg(noLEDs, V_LIGHT);
        
        
        
        /***
         * Dimmable LED initialization method
         */
        void setup()  
        { 
          // not sure this works
          // Pull the gateway's current dim level - restore light level upon sendor node power-up
        for (int sensor=1; sensor<=noLEDs; sensor++){
          request( sensor, V_DIMMER );
         }
        }
        
        void presentation() {
          // Register the LED Dimmable Light with the gateway
         for (int sensor=1; sensor<=noLEDs; sensor++){
         present(sensor, S_DIMMER);
         delay(2);
         }
          sendSketchInfo(SN, SV);
        }
        
        /***
         *  Dimmable LED main processing loop 
         */
        void loop() 
        {
        }
        
        
        
        void receive(const MyMessage &message) {
          if (message.type == V_LIGHT || message.type == V_DIMMER) {
            
            //  Retrieve the power or dim level from the incoming request message
            int requestedLevel = atoi( message.data );
            
            // Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on]
            requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
            
            // Clip incoming level to valid range of 0 to 100
            requestedLevel = requestedLevel > 100 ? 100 : requestedLevel;
            requestedLevel = requestedLevel < 0   ? 0   : requestedLevel;
            
            Serial.print( "Changing LED " );
            Serial.print(message.sensor);
            Serial.print(", PIN " );
            Serial.print( LED_Pin[message.sensor] );
            Serial.print(" level to " );
            Serial.print( requestedLevel );
            Serial.print( ", from " ); 
            Serial.println( currentLevel );
        
            
            fadeToLevel( requestedLevel, message.sensor );
            
            // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
            send(lightMsg.set(currentLevel > 0 ? 1 : 0));
        
            // hek comment: Is this really nessesary?
            send( dimmerMsg.set(currentLevel) );
        
            
            }
        }
        
        /***
         *  This method provides a graceful fade up/down effect
         */
        void fadeToLevel( int toLevel, int ledid ) {
        
          int delta = ( toLevel - currentLevel ) < 0 ? -1 : 1;
          
          while ( currentLevel != toLevel ) {
            currentLevel += delta;
            analogWrite( LED_Pin[ledid], (int)(currentLevel / 100. * 255) );
            delay( FADE_DELAY );
          }
        }
        
        
        BartEB 1 Reply Last reply
        0
        • thazlett144T thazlett144

          It looks like you are trying to add another LED/Mosfet? I have done it this way, I have 3 on mine:

          To do this I may or may not have used some examples I found on this forum. I basically add the pins I am using (PWM capable) into an array. I have 4 pins defined (3 is in there twice) to get around the array references starting from 0. Probably a better way to do that but this was my quick way round it.

          I have basically adapted the code from the example LED Dimmer sketch to work with the array / multiple child devices.

          Hopefully thats helpful and what you were after?

          // Enable debug prints to serial monitor
          #define MY_DEBUG 
          
          // Enable and select radio type attached
          #define MY_RADIO_NRF24
          //#define MY_RADIO_RFM69
          
          #include <SPI.h>
          #include <MySensors.h> 
          
          #define SN "MultiDimmableLED"
          #define SV "1.1"
          
          #define noLEDs 3
          const int LED_Pin[] = {3, 3, 5, 6}; //put 3 in twice as a start from 0 workaround
          
          #define FADE_DELAY 10  // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
          
          static int currentLevel = 0;  // Current dim level...
          MyMessage dimmerMsg(noLEDs, V_DIMMER);
          MyMessage lightMsg(noLEDs, V_LIGHT);
          
          
          
          /***
           * Dimmable LED initialization method
           */
          void setup()  
          { 
            // not sure this works
            // Pull the gateway's current dim level - restore light level upon sendor node power-up
          for (int sensor=1; sensor<=noLEDs; sensor++){
            request( sensor, V_DIMMER );
           }
          }
          
          void presentation() {
            // Register the LED Dimmable Light with the gateway
           for (int sensor=1; sensor<=noLEDs; sensor++){
           present(sensor, S_DIMMER);
           delay(2);
           }
            sendSketchInfo(SN, SV);
          }
          
          /***
           *  Dimmable LED main processing loop 
           */
          void loop() 
          {
          }
          
          
          
          void receive(const MyMessage &message) {
            if (message.type == V_LIGHT || message.type == V_DIMMER) {
              
              //  Retrieve the power or dim level from the incoming request message
              int requestedLevel = atoi( message.data );
              
              // Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on]
              requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
              
              // Clip incoming level to valid range of 0 to 100
              requestedLevel = requestedLevel > 100 ? 100 : requestedLevel;
              requestedLevel = requestedLevel < 0   ? 0   : requestedLevel;
              
              Serial.print( "Changing LED " );
              Serial.print(message.sensor);
              Serial.print(", PIN " );
              Serial.print( LED_Pin[message.sensor] );
              Serial.print(" level to " );
              Serial.print( requestedLevel );
              Serial.print( ", from " ); 
              Serial.println( currentLevel );
          
              
              fadeToLevel( requestedLevel, message.sensor );
              
              // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
              send(lightMsg.set(currentLevel > 0 ? 1 : 0));
          
              // hek comment: Is this really nessesary?
              send( dimmerMsg.set(currentLevel) );
          
              
              }
          }
          
          /***
           *  This method provides a graceful fade up/down effect
           */
          void fadeToLevel( int toLevel, int ledid ) {
          
            int delta = ( toLevel - currentLevel ) < 0 ? -1 : 1;
            
            while ( currentLevel != toLevel ) {
              currentLevel += delta;
              analogWrite( LED_Pin[ledid], (int)(currentLevel / 100. * 255) );
              delay( FADE_DELAY );
            }
          }
          
          
          BartEB Offline
          BartEB Offline
          BartE
          Contest Winner
          wrote on last edited by BartE
          #4

          @thazlett144 can't help to make a few comments on your sketch (sorry)

          The led the array start from 0 and prevent the double pin declaration simply subtract one on usage so
          this LED_Pin[ledid] becomes this LED_Pin[ledid-1]

          please do use wait() instead of delay(), delay is blocking MySensors communication

              // hek comment: Is this really nessesary?
              send( dimmerMsg.set(currentLevel) );
          

          Answer: Yes, controllers like Vera want feedback about the new dimlevel

          thazlett144T 1 Reply Last reply
          1
          • J Offline
            J Offline
            jeti
            wrote on last edited by
            #5

            Hi,

            thank you both, i will be testing soon!

            thanks again!

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jeti
              wrote on last edited by
              #6

              so this works now like a charm:

              // Enable debug prints to serial monitor
              #define MY_DEBUG 
              
              // Enable and select radio type attached
              #define MY_RADIO_NRF24
              //#define MY_RADIO_RFM69
              
              #define MY_NODE_ID 153 
              
              #include <SPI.h>
              #include <MySensors.h> 
              
              #define SN "MultiDimmableLED"
              #define SV "1.1"
              
              #define noLEDs 3
              const int LED_Pin[] = {3, 5, 6}; 
              
              #define FADE_DELAY 25  // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
              
              static int currentLevel = 0;  // Current dim level...
              MyMessage dimmerMsg(noLEDs, V_DIMMER);
              MyMessage lightMsg(noLEDs, V_LIGHT);
              
              
              
              /***
               * Dimmable LED initialization method
               */
              void setup()  
              { 
                // not sure this works
                // Pull the gateway's current dim level - restore light level upon sendor node power-up
              for (int sensor=1; sensor<=noLEDs; sensor++){
                request( sensor, V_DIMMER );
               }
              }
              
              void presentation() {
                // Register the LED Dimmable Light with the gateway
               for (int sensor=1; sensor<=noLEDs; sensor++){
               present(sensor, S_DIMMER);
               wait(2);
               }
                sendSketchInfo(SN, SV);
              }
              
              /***
               *  Dimmable LED main processing loop 
               */
              void loop() 
              {
              }
              
              
              
              void receive(const MyMessage &message) {
                if (message.type == V_LIGHT || message.type == V_DIMMER) {
                  
                  //  Retrieve the power or dim level from the incoming request message
                  int requestedLevel = atoi( message.data );
                  
                  // Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on]
                  requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
                  
                  // Clip incoming level to valid range of 0 to 100
                  requestedLevel = requestedLevel > 100 ? 100 : requestedLevel;
                  requestedLevel = requestedLevel < 0   ? 0   : requestedLevel;
                  
                  Serial.print( "Changing LED " );
                  Serial.print(message.sensor);
                  Serial.print(", PIN " );
                  Serial.print( LED_Pin[message.sensor] );
                  Serial.print(" level to " );
                  Serial.print( requestedLevel );
                  Serial.print( ", from " ); 
                  Serial.println( currentLevel );
              
                  
                  fadeToLevel( requestedLevel, message.sensor );
                  
                  // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
                  send(lightMsg.set(currentLevel > 0 ? 1 : 0));
              
                  // hek comment: Is this really nessesary?
                  send( dimmerMsg.set(currentLevel) );
              
                  
                  }
              }
              
              /***
               *  This method provides a graceful fade up/down effect
               */
              void fadeToLevel( int toLevel, int ledid ) {
              
                int delta = ( toLevel - currentLevel ) < 0 ? -1 : 1;
                
                while ( currentLevel != toLevel ) {
                  currentLevel += delta;
                  analogWrite(LED_Pin[ledid-1], (int)(currentLevel / 100. * 255) );
                  wait( FADE_DELAY );
                }
              }```
              
              thank you :thumbsup:
              PlantexP 1 Reply Last reply
              1
              • korttomaK Offline
                korttomaK Offline
                korttoma
                Hero Member
                wrote on last edited by
                #7

                I just tried the DimmableLightWithRotaryEncoderButton and I found that when rotating the rotary encoder clockwise the dim level decrease and turning it counter clockwise will increase the dim level. I would like it the other way around.

                Any ideas how to modify the sketch? Or is this a feature of my rotary encoder? Did I wire something wrong (I did check my wires and it is according to the instructions).

                • Tomas
                1 Reply Last reply
                0
                • hekH Offline
                  hekH Offline
                  hek
                  Admin
                  wrote on last edited by
                  #8

                  Did you try just switching the pins for KNOB_ENC_PIN_x?

                  korttomaK 1 Reply Last reply
                  0
                  • hekH hek

                    Did you try just switching the pins for KNOB_ENC_PIN_x?

                    korttomaK Offline
                    korttomaK Offline
                    korttoma
                    Hero Member
                    wrote on last edited by
                    #9

                    @hek said:

                    Did you try just switching the pins for KNOB_ENC_PIN_x?

                    That did the trick. Thanks!

                    • Tomas
                    1 Reply Last reply
                    0
                    • BartEB BartE

                      @thazlett144 can't help to make a few comments on your sketch (sorry)

                      The led the array start from 0 and prevent the double pin declaration simply subtract one on usage so
                      this LED_Pin[ledid] becomes this LED_Pin[ledid-1]

                      please do use wait() instead of delay(), delay is blocking MySensors communication

                          // hek comment: Is this really nessesary?
                          send( dimmerMsg.set(currentLevel) );
                      

                      Answer: Yes, controllers like Vera want feedback about the new dimlevel

                      thazlett144T Offline
                      thazlett144T Offline
                      thazlett144
                      wrote on last edited by
                      #10

                      @BartE Thats great thank you. I am still learning anyway so there are gaps in my knowledge :-) I knew I could do something like that -1.

                      delay was part of the original example I think?

                      1 Reply Last reply
                      0
                      • pjblinkP Offline
                        pjblinkP Offline
                        pjblink
                        wrote on last edited by
                        #11

                        Hi guys,

                        Struggling with this a little and think it may be hardware related. I'm using a 3.3v pro mini and it won't let the 12v LEDs go to full brightness, at max dim level they're still quite dim. I've tried this on both regular flexi LED strip and the copper-wire type LEDs (final project is based on these).

                        I've tried with a different FET, an IRLB8721 and that goes to full brightness however won't switch the LEDS off completely so guessing there's a leak from that FET! I'm not sure if that's normal or not. Frustrating.

                        Ideally i want the circuitry to be 3.3v as i'm already converting the 12v LED power supply down to 3.3v for the nRF. I'd rather not have a 5v and 3.3v regulator.

                        Thanks,

                        Patrick

                        mfalkviddM ? 2 Replies Last reply
                        0
                        • pjblinkP pjblink

                          Hi guys,

                          Struggling with this a little and think it may be hardware related. I'm using a 3.3v pro mini and it won't let the 12v LEDs go to full brightness, at max dim level they're still quite dim. I've tried this on both regular flexi LED strip and the copper-wire type LEDs (final project is based on these).

                          I've tried with a different FET, an IRLB8721 and that goes to full brightness however won't switch the LEDS off completely so guessing there's a leak from that FET! I'm not sure if that's normal or not. Frustrating.

                          Ideally i want the circuitry to be 3.3v as i'm already converting the 12v LED power supply down to 3.3v for the nRF. I'd rather not have a 5v and 3.3v regulator.

                          Thanks,

                          Patrick

                          mfalkviddM Offline
                          mfalkviddM Offline
                          mfalkvidd
                          Mod
                          wrote on last edited by
                          #12

                          @pjblink I had the same problem in https://forum.mysensors.org/topic/2335/controlling-leds-with-the-irlz44n/ and another community member had something similar: https://forum.mysensors.org/topic/2335/controlling-leds-with-the-irlz44n/

                          The solution seems to be to buy new mosfets and hope that they work properly.

                          pjblinkP 1 Reply Last reply
                          0
                          • mfalkviddM mfalkvidd

                            @pjblink I had the same problem in https://forum.mysensors.org/topic/2335/controlling-leds-with-the-irlz44n/ and another community member had something similar: https://forum.mysensors.org/topic/2335/controlling-leds-with-the-irlz44n/

                            The solution seems to be to buy new mosfets and hope that they work properly.

                            pjblinkP Offline
                            pjblinkP Offline
                            pjblink
                            wrote on last edited by
                            #13

                            @mfalkvidd So keep trying IRLZ44N FETs?

                            mfalkviddM 1 Reply Last reply
                            0
                            • pjblinkP pjblink

                              @mfalkvidd So keep trying IRLZ44N FETs?

                              mfalkviddM Offline
                              mfalkviddM Offline
                              mfalkvidd
                              Mod
                              wrote on last edited by
                              #14

                              @pjblink probably. Several people have reported their IRLZ44N opening fully at 3.3V.

                              1 Reply Last reply
                              0
                              • korttomaK Offline
                                korttomaK Offline
                                korttoma
                                Hero Member
                                wrote on last edited by korttoma
                                #15

                                Inspirational pictures from my Dimmable LED Actuator with rotary encoder device I made for my sons bedside lamp.
                                Running this at 12VDC. His lamp had a G9 socket so I just broke apart the G9 LED bulb and soldered some G4 12VDC LED lights like these to it and replaces the "Dumb" switch with a 5mm DC plug. It turned out so nice that I think I will MySensor my own bedside lamp also.

                                Edit: btw, I found the nice big knobs from here -> eBay

                                0_1476680417320_WP_20161014_07_07_53.jpg

                                0_1476680429390_WP_20161014_07_11_47.jpg

                                • Tomas
                                1 Reply Last reply
                                3
                                • korttomaK Offline
                                  korttomaK Offline
                                  korttoma
                                  Hero Member
                                  wrote on last edited by
                                  #16

                                  Bahh.. I had the 12VDC connected directly to the RAW pin on the Arduino Pro mini and yesterday it failed.
                                  I should have known better. Now added a 5V regulator to the device and a new 5V Pro Mini.

                                  • Tomas
                                  1 Reply Last reply
                                  0
                                  • MalmQM Offline
                                    MalmQM Offline
                                    MalmQ
                                    wrote on last edited by
                                    #17

                                    Hi all
                                    I love the mysensors project. I have made a lot of sensors by now. Now I would like to control these LED-lights with a dimmer node:
                                    http://www.siriushome.dk/product/50200/ (in danish)
                                    The specs. for the LEDs are 6W@80V.
                                    I have two questions that I hope you can help me with.
                                    A) What is the easiest way to drive an arduinonode from 80v. Is a DC/DC converter the only way?
                                    B) What mosfet would you suggest using for controling the LEDs?

                                    I hope you can help. Many thanks.

                                    // MalmQ

                                    1 Reply Last reply
                                    0
                                    • pjblinkP pjblink

                                      Hi guys,

                                      Struggling with this a little and think it may be hardware related. I'm using a 3.3v pro mini and it won't let the 12v LEDs go to full brightness, at max dim level they're still quite dim. I've tried this on both regular flexi LED strip and the copper-wire type LEDs (final project is based on these).

                                      I've tried with a different FET, an IRLB8721 and that goes to full brightness however won't switch the LEDS off completely so guessing there's a leak from that FET! I'm not sure if that's normal or not. Frustrating.

                                      Ideally i want the circuitry to be 3.3v as i'm already converting the 12v LED power supply down to 3.3v for the nRF. I'd rather not have a 5v and 3.3v regulator.

                                      Thanks,

                                      Patrick

                                      ? Offline
                                      ? Offline
                                      A Former User
                                      wrote on last edited by A Former User
                                      #18

                                      @pjblink the irlzn44n is very sensitive to over heat during solder, I have lost some of them during soldering :) please be careful

                                      1 Reply Last reply
                                      0
                                      • CreakyC Offline
                                        CreakyC Offline
                                        Creaky
                                        wrote on last edited by
                                        #19

                                        Hi!

                                        I'd like to use this sketch with a 5V Arduino Nano, do I need to use another type of MOSFET for this?
                                        From the OP I gather that the IRLZ44N is used because of the lower gate threshold in combination with the 3.3v operating voltage, but won't the IRLZ44N gate be saturated very quickly when using 5v?

                                        Creaky

                                        mfalkviddM 1 Reply Last reply
                                        0
                                        • CreakyC Creaky

                                          Hi!

                                          I'd like to use this sketch with a 5V Arduino Nano, do I need to use another type of MOSFET for this?
                                          From the OP I gather that the IRLZ44N is used because of the lower gate threshold in combination with the 3.3v operating voltage, but won't the IRLZ44N gate be saturated very quickly when using 5v?

                                          Creaky

                                          mfalkviddM Offline
                                          mfalkviddM Offline
                                          mfalkvidd
                                          Mod
                                          wrote on last edited by mfalkvidd
                                          #20

                                          @Creaky the dimmer uses PWM to control the light level, so the mosfet is always either in cutoff or fully saturated. So using IRLz44N with 5V will work just as well as 3.3V.

                                          CreakyC 2 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          9

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular