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. My Project
  3. Automatic LED light - high WAF inside :)

Automatic LED light - high WAF inside :)

Scheduled Pinned Locked Moved My Project
16 Posts 4 Posters 3.5k Views 4 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.
  • ben999B Offline
    ben999B Offline
    ben999
    wrote on last edited by ben999
    #1

    Hi guys

    A new project came on top of the others : ceiling light

    The wife kinda likes the idea behind MySensors and openHab, as home automation and security system
    But i had to hit hard to get it fully accepted. So here comes the "cat shaped ceiling light" !!!

    (0_1508911480537_IMG_6161[1].JPG
    (Ok I know, ceiling is not finished yet... it has to be spotless as this kind of light reveals everything...)
    LED strip is glued on the edge of the board, powered via a 12V power supply which is controlled via an OMRON SSR relay

    Some AutoCad and CNC later... :

    0_1508914575098_IMG_6156.JPG

    0_1508914588720_IMG_6157.JPG

    This is highly inspired by Aproxx's work
    https://www.openhardware.io/view/77/AC-DC-double-solid-state-relay-module

    What I want it to do :

    • switch on the light when motion (PIR sensor)
    • switch itself off with delay (PIR kind enough to do that as well)
    • measure room light level so as to switch light on only when needed
    • have 3 modes controlled via openHab : fully automatic, always ON, always OFF

    So far i have managed to create a 3-state selector in openhab with this:

    • ".items" file: String HouseMode "House Mode [%s]"
    • ".sitemap" file: Switch item=LightMode mappings=[ON=1, AUTO=2, OFF=1]

    0_1508920812417_IMG_6164.PNG

    Now I am having some trouble with the sketch...
    I guess I should be using S_CUSTOM and V_CUSTOM (instead of S_BINARY and V_STATUS) as the "LightMode" variable can take up to 3 states...
    How do i then retreive that value?

    void receive(const MyMessage &message)
    int lightMode = message.getInt();
    

    Thanks for your input and comments :)

    dbemowskD 1 Reply Last reply
    6
    • gohanG Offline
      gohanG Offline
      gohan
      Mod
      wrote on last edited by
      #2

      Maybe you could add a second binary switch to toggle AUTO mode and leave light as binary, otherwise you probably need to use something like S_LEVEL or similar

      ben999B 1 Reply Last reply
      1
      • gohanG gohan

        Maybe you could add a second binary switch to toggle AUTO mode and leave light as binary, otherwise you probably need to use something like S_LEVEL or similar

        ben999B Offline
        ben999B Offline
        ben999
        wrote on last edited by
        #3

        @gohan

        Thank you for your suggestion

        It does work the way you suggested, with 2 binary switches

        But that is not what i would like to achieve ;)

        1 Reply Last reply
        0
        • ben999B Offline
          ben999B Offline
          ben999
          wrote on last edited by ben999
          #4

          Guys

          Based on

          • ".items file:" String lightMode "lightMode [%s]
          • ".sitemap" file: Switch item=lightMode mappings=[ON=1, AUTO=2, OFF=1]

          I would like to retreive the value of "lightMode" at the node side

          This is what I am doing at the moment :

          void receive(const MyMessage &message)
          {
            if (message.type == V_VAR1) {    
              char lightMode[MAX_MESSAGE_LENGTH];
              strncpy(lightMode, message.data, MAX_MESSAGE_LENGTH);
            }
          

          Compiles and uploads fine

          But state of lightMode doesn't change in node serial monitor...
          Nothing is returned (empty field) when doing a Serial.println(lightMode)"

          Could you please point me towards my mistake ? Am I (one more time) mixing data types (int and char and so on) ?

          Thanks a lot for your time :)

          1 Reply Last reply
          0
          • ben999B Offline
            ben999B Offline
            ben999
            wrote on last edited by
            #5

            Sorted :)

            It is probably a bad idea to send data to node while sleeping...

            Complete sketch for the record

            // Enable debug prints
            #define MY_DEBUG
            
            #define MY_RADIO_NRF24
            
            #define MY_PARENT_ID 0
            #define MY_NODE_ID 19
            
            #include <MySensors.h>
            
            // (Only input 2 and 3 generates interrupt!)
            #define PIN_MOTION 2      // Motion sensor input
            #define PIN_RELAY 5       // Omron relay output
            #define MOTION_ID 1       // Id of the motion sensor child
            #define RELAY_ID 2        // Id of the relay child
            
            int lightMode = 2;         // 0=OFF - 1=ON - 2=auto
            bool prevTripped = 0;          // previous state of motion sensor
            
            MyMessage msgMotion(MOTION_ID, V_TRIPPED);    // Initialize motion message
            
            void setup()
            {
              pinMode(PIN_MOTION, INPUT);
              delay(3000);  // wait for motion sensor voltage to stabilize
              pinMode(PIN_RELAY, OUTPUT);     // Then set relay pins in output mode
              digitalWrite(PIN_RELAY, LOW);  // Make sure relays are off when starting up
            }
            
            
            void presentation()
            {
              sendSketchInfo("Toilet Light", "27.10.2017");
              present(MOTION_ID, S_MOTION);
              present(RELAY_ID, S_CUSTOM);
            }
            
            
            void loop()
            {
            
              bool tripped = digitalRead(PIN_MOTION) == HIGH;
            
              if ( tripped =! prevTripped ) { //only send data when there is a change
                send(msgMotion.set(tripped ? "1" : "0")); // Send tripped value to gw
                prevTripped = tripped;
              }
            
              if ( lightMode == 0 ) {
                digitalWrite(PIN_RELAY, LOW);
              }
            
              if ( lightMode == 1 ) {
                digitalWrite(PIN_RELAY, HIGH);
              }
            
              if ( (tripped == 1) && ( lightMode == 2 ) )  {
                digitalWrite(PIN_RELAY, HIGH);
              }
            
              if ( (tripped == 0) && ( lightMode == 2 ) )  {
                digitalWrite(PIN_RELAY, LOW);
              }
            }
            
            
            void receive(const MyMessage &message)
            {
              if (message.type == V_VAR1) {
                lightMode = atoi(message.data);
              }
            }
            

            Thanks for reading ! Next project !!!

            dbemowskD 1 Reply Last reply
            0
            • ben999B Offline
              ben999B Offline
              ben999
              wrote on last edited by
              #6

              Hi guys

              Could you please comment on this :

              bool tripped = digitalRead(PIN_MOTION) == HIGH;
              if ( tripped =! prevTripped ) {     //only send data when there is a change
                send(msgMotion.set(tripped ? "1" : "0")); // Send tripped value to gw
                prevTripped = tripped;
                }
              

              Goal is to send update to gateway when state of PIR sensor changes
              Trouble is that node sends state of sensor every cycle and floods karaf console...
              Any clue ?
              Also can anyone explain this

              bool tripped = digitalRead(PIN_MOTION) == HIGH;
              

              I dont quite understand.... read, store, and compare... all at once?

              Thanks a lot for your help

              Cheers

              B 1 Reply Last reply
              0
              • ben999B ben999

                Hi guys

                Could you please comment on this :

                bool tripped = digitalRead(PIN_MOTION) == HIGH;
                if ( tripped =! prevTripped ) {     //only send data when there is a change
                  send(msgMotion.set(tripped ? "1" : "0")); // Send tripped value to gw
                  prevTripped = tripped;
                  }
                

                Goal is to send update to gateway when state of PIR sensor changes
                Trouble is that node sends state of sensor every cycle and floods karaf console...
                Any clue ?
                Also can anyone explain this

                bool tripped = digitalRead(PIN_MOTION) == HIGH;
                

                I dont quite understand.... read, store, and compare... all at once?

                Thanks a lot for your help

                Cheers

                B Offline
                B Offline
                billgoolsby
                wrote on last edited by
                #7

                @ben999,
                As for your last question, this line is simply converting the pin state (either HIGH or LOW) to a boolean. The right side expression evaluates to a boolean that is true when the pin is HIGH. This is assigned to the boolean variable "tripped". This makes it logically easy to use in the following IF statement.

                First question: I'm not sure why it would send every cycle. The logic of the IF statement seems correct, and since prevTripped is global, its state will be preserved between loops.

                ben999B 1 Reply Last reply
                0
                • ben999B ben999

                  Hi guys

                  A new project came on top of the others : ceiling light

                  The wife kinda likes the idea behind MySensors and openHab, as home automation and security system
                  But i had to hit hard to get it fully accepted. So here comes the "cat shaped ceiling light" !!!

                  (0_1508911480537_IMG_6161[1].JPG
                  (Ok I know, ceiling is not finished yet... it has to be spotless as this kind of light reveals everything...)
                  LED strip is glued on the edge of the board, powered via a 12V power supply which is controlled via an OMRON SSR relay

                  Some AutoCad and CNC later... :

                  0_1508914575098_IMG_6156.JPG

                  0_1508914588720_IMG_6157.JPG

                  This is highly inspired by Aproxx's work
                  https://www.openhardware.io/view/77/AC-DC-double-solid-state-relay-module

                  What I want it to do :

                  • switch on the light when motion (PIR sensor)
                  • switch itself off with delay (PIR kind enough to do that as well)
                  • measure room light level so as to switch light on only when needed
                  • have 3 modes controlled via openHab : fully automatic, always ON, always OFF

                  So far i have managed to create a 3-state selector in openhab with this:

                  • ".items" file: String HouseMode "House Mode [%s]"
                  • ".sitemap" file: Switch item=LightMode mappings=[ON=1, AUTO=2, OFF=1]

                  0_1508920812417_IMG_6164.PNG

                  Now I am having some trouble with the sketch...
                  I guess I should be using S_CUSTOM and V_CUSTOM (instead of S_BINARY and V_STATUS) as the "LightMode" variable can take up to 3 states...
                  How do i then retreive that value?

                  void receive(const MyMessage &message)
                  int lightMode = message.getInt();
                  

                  Thanks for your input and comments :)

                  dbemowskD Offline
                  dbemowskD Offline
                  dbemowsk
                  wrote on last edited by
                  #8

                  @ben999 Nice CNC work on the PCB.

                  Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                  Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                  ben999B 1 Reply Last reply
                  0
                  • ben999B ben999

                    Sorted :)

                    It is probably a bad idea to send data to node while sleeping...

                    Complete sketch for the record

                    // Enable debug prints
                    #define MY_DEBUG
                    
                    #define MY_RADIO_NRF24
                    
                    #define MY_PARENT_ID 0
                    #define MY_NODE_ID 19
                    
                    #include <MySensors.h>
                    
                    // (Only input 2 and 3 generates interrupt!)
                    #define PIN_MOTION 2      // Motion sensor input
                    #define PIN_RELAY 5       // Omron relay output
                    #define MOTION_ID 1       // Id of the motion sensor child
                    #define RELAY_ID 2        // Id of the relay child
                    
                    int lightMode = 2;         // 0=OFF - 1=ON - 2=auto
                    bool prevTripped = 0;          // previous state of motion sensor
                    
                    MyMessage msgMotion(MOTION_ID, V_TRIPPED);    // Initialize motion message
                    
                    void setup()
                    {
                      pinMode(PIN_MOTION, INPUT);
                      delay(3000);  // wait for motion sensor voltage to stabilize
                      pinMode(PIN_RELAY, OUTPUT);     // Then set relay pins in output mode
                      digitalWrite(PIN_RELAY, LOW);  // Make sure relays are off when starting up
                    }
                    
                    
                    void presentation()
                    {
                      sendSketchInfo("Toilet Light", "27.10.2017");
                      present(MOTION_ID, S_MOTION);
                      present(RELAY_ID, S_CUSTOM);
                    }
                    
                    
                    void loop()
                    {
                    
                      bool tripped = digitalRead(PIN_MOTION) == HIGH;
                    
                      if ( tripped =! prevTripped ) { //only send data when there is a change
                        send(msgMotion.set(tripped ? "1" : "0")); // Send tripped value to gw
                        prevTripped = tripped;
                      }
                    
                      if ( lightMode == 0 ) {
                        digitalWrite(PIN_RELAY, LOW);
                      }
                    
                      if ( lightMode == 1 ) {
                        digitalWrite(PIN_RELAY, HIGH);
                      }
                    
                      if ( (tripped == 1) && ( lightMode == 2 ) )  {
                        digitalWrite(PIN_RELAY, HIGH);
                      }
                    
                      if ( (tripped == 0) && ( lightMode == 2 ) )  {
                        digitalWrite(PIN_RELAY, LOW);
                      }
                    }
                    
                    
                    void receive(const MyMessage &message)
                    {
                      if (message.type == V_VAR1) {
                        lightMode = atoi(message.data);
                      }
                    }
                    

                    Thanks for reading ! Next project !!!

                    dbemowskD Offline
                    dbemowskD Offline
                    dbemowsk
                    wrote on last edited by
                    #9

                    @ben999 I would rewrite some of the logic in your code to shorten it up a bit. I would change this:

                      if ( lightMode == 0 ) {
                        digitalWrite(PIN_RELAY, LOW);
                      }
                    
                      if ( lightMode == 1 ) {
                        digitalWrite(PIN_RELAY, HIGH);
                      }
                    
                      if ( (tripped == 1) && ( lightMode == 2 ) )  {
                        digitalWrite(PIN_RELAY, HIGH);
                      }
                    
                      if ( (tripped == 0) && ( lightMode == 2 ) )  {
                        digitalWrite(PIN_RELAY, LOW);
                      }
                    

                    To this:

                      if ( ( (tripped == 1) && ( lightMode == 2 ) ) ||   lightMode == 1  )  {
                        digitalWrite(PIN_RELAY, HIGH);
                      }
                    
                      if ( ( (tripped == 0) && ( lightMode == 2 ) ) ||   lightMode == 0  )  {
                        digitalWrite(PIN_RELAY, LOW);
                      }
                    

                    Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                    Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                    ben999B 1 Reply Last reply
                    0
                    • dbemowskD dbemowsk

                      @ben999 I would rewrite some of the logic in your code to shorten it up a bit. I would change this:

                        if ( lightMode == 0 ) {
                          digitalWrite(PIN_RELAY, LOW);
                        }
                      
                        if ( lightMode == 1 ) {
                          digitalWrite(PIN_RELAY, HIGH);
                        }
                      
                        if ( (tripped == 1) && ( lightMode == 2 ) )  {
                          digitalWrite(PIN_RELAY, HIGH);
                        }
                      
                        if ( (tripped == 0) && ( lightMode == 2 ) )  {
                          digitalWrite(PIN_RELAY, LOW);
                        }
                      

                      To this:

                        if ( ( (tripped == 1) && ( lightMode == 2 ) ) ||   lightMode == 1  )  {
                          digitalWrite(PIN_RELAY, HIGH);
                        }
                      
                        if ( ( (tripped == 0) && ( lightMode == 2 ) ) ||   lightMode == 0  )  {
                          digitalWrite(PIN_RELAY, LOW);
                        }
                      
                      ben999B Offline
                      ben999B Offline
                      ben999
                      wrote on last edited by
                      #10

                      @dbemowsk thanks a lot :) i like that!

                      Do you rekon that would "speed" things up? Not that i need more speed to switch that light on but would this simplify and shorten the sketch processing time?

                      1 Reply Last reply
                      0
                      • B billgoolsby

                        @ben999,
                        As for your last question, this line is simply converting the pin state (either HIGH or LOW) to a boolean. The right side expression evaluates to a boolean that is true when the pin is HIGH. This is assigned to the boolean variable "tripped". This makes it logically easy to use in the following IF statement.

                        First question: I'm not sure why it would send every cycle. The logic of the IF statement seems correct, and since prevTripped is global, its state will be preserved between loops.

                        ben999B Offline
                        ben999B Offline
                        ben999
                        wrote on last edited by
                        #11

                        @billgoolsby thanks a lot for your comments that make more sense now :)

                        Trouble is that if sketch remains as above it doesn't get into the if ( tripped =! prevTripped ) loop (i have put Serial.print here and there and i never get to it)
                        On top of that tripped stays locked on HIGH but light is off...

                        Any clue? Sketch seems fine to you?

                        Thanks for your time :)

                        ben999B 1 Reply Last reply
                        0
                        • dbemowskD dbemowsk

                          @ben999 Nice CNC work on the PCB.

                          ben999B Offline
                          ben999B Offline
                          ben999
                          wrote on last edited by
                          #12

                          @dbemowsk said in Automatic LED light - high WAF inside :):

                          @ben999 Nice CNC work on the PCB.

                          I have some neat little tools in my workshop:

                          3x1.5m working area
                          0_1510121225655_P1000290small.JPG

                          500x300mm working area
                          0_1510121707486_IMG_6233small.JPG

                          dbemowskD 1 Reply Last reply
                          0
                          • ben999B ben999

                            @dbemowsk said in Automatic LED light - high WAF inside :):

                            @ben999 Nice CNC work on the PCB.

                            I have some neat little tools in my workshop:

                            3x1.5m working area
                            0_1510121225655_P1000290small.JPG

                            500x300mm working area
                            0_1510121707486_IMG_6233small.JPG

                            dbemowskD Offline
                            dbemowskD Offline
                            dbemowsk
                            wrote on last edited by
                            #13

                            @ben999 OK, NO FAIR. Is the bottom one a laser cutter/engraver??

                            Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                            Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                            ben999B 1 Reply Last reply
                            0
                            • dbemowskD dbemowsk

                              @ben999 OK, NO FAIR. Is the bottom one a laser cutter/engraver??

                              ben999B Offline
                              ben999B Offline
                              ben999
                              wrote on last edited by
                              #14

                              @dbemowsk :D i know i'm lucky to have all those toys handy

                              This is a 2.2kW spindle... other one is 13kW in case i need more :D

                              dbemowskD 1 Reply Last reply
                              0
                              • ben999B ben999

                                @dbemowsk :D i know i'm lucky to have all those toys handy

                                This is a 2.2kW spindle... other one is 13kW in case i need more :D

                                dbemowskD Offline
                                dbemowskD Offline
                                dbemowsk
                                wrote on last edited by
                                #15

                                @ben999 .oO{ JEALOUS }Oo.

                                Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                                Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                                1 Reply Last reply
                                0
                                • ben999B ben999

                                  @billgoolsby thanks a lot for your comments that make more sense now :)

                                  Trouble is that if sketch remains as above it doesn't get into the if ( tripped =! prevTripped ) loop (i have put Serial.print here and there and i never get to it)
                                  On top of that tripped stays locked on HIGH but light is off...

                                  Any clue? Sketch seems fine to you?

                                  Thanks for your time :)

                                  ben999B Offline
                                  ben999B Offline
                                  ben999
                                  wrote on last edited by
                                  #16

                                  @ben999 just for the record... =! is wrong. Should have been !=
                                  Makes quite a difference :(

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  20

                                  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