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. Development
  3. Newbie Problem! Get Started with NRF24L01+

Newbie Problem! Get Started with NRF24L01+

Scheduled Pinned Locked Moved Development
55 Posts 9 Posters 24.2k Views 2 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.
  • rvendrameR rvendrame

    Maybe you can you connect the node also in a USB port, and open a serial monitor for it? You would see if it is receiving the message correctly.

    F Offline
    F Offline
    fakeJake
    wrote on last edited by
    #33

    @rvendrame Sorry I forgot to include that, I edited the post

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fakeJake
      wrote on last edited by fakeJake
      #34

      It still doesn't open the light even if I change it to "2;255;1;1;2;1;"
      I checked the relay using relay.ino from an instructable controlling ac light with relay and it's working.

      1 Reply Last reply
      0
      • rvendrameR Offline
        rvendrameR Offline
        rvendrame
        Hero Member
        wrote on last edited by
        #35

        Can we see your sensor's sketch?

        Home Assistant / Vera Plus UI7
        ESP8266 GW + mySensors 2.3.2
        Alexa / Google Home

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fakeJake
          wrote on last edited by fakeJake
          #36

          I just changed the gw.begin();

          // Example sketch showing how to control physical relays. 
          // This example will remember relay state even after power failure.
          
          #include <MySensor.h>
          #include <SPI.h>
          
          #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
          #define NUMBER_OF_RELAYS 1 // Total number of attached relays
          #define RELAY_ON 1  // GPIO value to write to turn on attached relay
          #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
          
          MySensor gw;
          
          void setup()  
          {   
            // Initialize library and add callback for incoming messages
            gw.begin(incomingMessage, 2);
            // Send the sketch version information to the gateway and Controller
            gw.sendSketchInfo("Relay", "1.0");
          
            // Fetch relay status
            for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
              // Register all sensors to gw (they will be created as child devices)
              gw.present(sensor, S_LIGHT);
              // Then set relay pins in output mode
              pinMode(pin, OUTPUT);   
              // Set relay to last known state (using eeprom storage) 
              digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
            }
          }
          
          
          void loop() 
          {
            // Alway process incoming messages whenever possible
            gw.process();
          }
          
          void incomingMessage(const MyMessage &message) {
            // We only expect one type of message from controller. But we better check anyway.
            if (message.type==V_LIGHT) {
               // Change relay state
               digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
               // Store state in eeprom
               gw.saveState(message.sensor, message.getBool());
               // Write some debug info
               Serial.print("Incoming change for sensor:");
               Serial.print(message.sensor);
               Serial.print(", New status: ");
               Serial.println(message.getBool());
             } 
          }
          
          1 Reply Last reply
          0
          • rvendrameR Offline
            rvendrameR Offline
            rvendrame
            Hero Member
            wrote on last edited by
            #37

            @fakeJake said:

            > Incoming change for sensor:0
            

            Means your are asking to activate relay 'zero'.

            digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
            

            So digital pin will be 0 - 1 + RELAY_1 = 0 - 1 + 3 = 2

            Conclusion: Try activating relay 1 instead 0. ;-)

            Home Assistant / Vera Plus UI7
            ESP8266 GW + mySensors 2.3.2
            Alexa / Google Home

            F 1 Reply Last reply
            1
            • rvendrameR rvendrame

              @fakeJake said:

              > Incoming change for sensor:0
              

              Means your are asking to activate relay 'zero'.

              digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
              

              So digital pin will be 0 - 1 + RELAY_1 = 0 - 1 + 3 = 2

              Conclusion: Try activating relay 1 instead 0. ;-)

              F Offline
              F Offline
              fakeJake
              wrote on last edited by fakeJake
              #38

              @rvendrame The light is still not turning on :sweat:
              I even change it to "2;257;1;1;2;1" just incase 255 is the message.sensor but it still prints "2;1;1;1;2;1" so I there's no problem there.

              sensor started, id 2
              send: 2-2-0-0 s=255,c=0,t=17,pt=0,l=5,st=ok:1.4.1
              send: 2-2-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
              send: 2-2-0-0 s=255,c=3,t=11,pt=0,l=5,st=ok:Relay
              send: 2-2-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
              send: 2-2-0-0 s=1,c=0,t=3,pt=0,l=5,st=ok:1.4.1
              read: 0-0-2 s=1,c=1,t=2,pt=0,l=1:1
              send: 2-2-0-0 s=1,c=1,t=2,pt=0,l=1,st=ok:1
              Incoming change for sensor:1, New status: 1
              
              1 Reply Last reply
              0
              • rvendrameR Offline
                rvendrameR Offline
                rvendrame
                Hero Member
                wrote on last edited by
                #39

                how the relay is connected to arduino pin 3? Is there a transistor in between?

                Home Assistant / Vera Plus UI7
                ESP8266 GW + mySensors 2.3.2
                Alexa / Google Home

                F 1 Reply Last reply
                0
                • rvendrameR rvendrame

                  how the relay is connected to arduino pin 3? Is there a transistor in between?

                  F Offline
                  F Offline
                  fakeJake
                  wrote on last edited by fakeJake
                  #40

                  @rvendrame No transistor. I just followed MySensors: Build Relay Actuator. I directly connected the 5v, gnd and signal to the arduino.

                  1 Reply Last reply
                  0
                  • rvendrameR Offline
                    rvendrameR Offline
                    rvendrame
                    Hero Member
                    wrote on last edited by
                    #41

                    Do you have a standalone relay, or a arduino relay board, like this picture?
                    http://www.mysensors.org/relay/relayModule.png

                    The board contains a transistor. Some boards also have a 'hi-low' switch, if yours have it, you may try to play with it.

                    The arduino output is max of 40ma and will eventually burn or not operate correctly if connected directly to a relay. You must have a transistor in between.

                    Make sure you relay board contains at least this circuit: http://www.electroschematics.com/8975/arduino-control-relay/

                    Home Assistant / Vera Plus UI7
                    ESP8266 GW + mySensors 2.3.2
                    Alexa / Google Home

                    F 2 Replies Last reply
                    0
                    • rvendrameR rvendrame

                      Do you have a standalone relay, or a arduino relay board, like this picture?
                      http://www.mysensors.org/relay/relayModule.png

                      The board contains a transistor. Some boards also have a 'hi-low' switch, if yours have it, you may try to play with it.

                      The arduino output is max of 40ma and will eventually burn or not operate correctly if connected directly to a relay. You must have a transistor in between.

                      Make sure you relay board contains at least this circuit: http://www.electroschematics.com/8975/arduino-control-relay/

                      F Offline
                      F Offline
                      fakeJake
                      wrote on last edited by
                      #42

                      @rvendrame My relay is more like this http://www.elecdesignworks.com/images/stories/virtuemart/product/img_62112.jpg

                      Thank you for your reference.
                      It has a transistor. I hope it's ok to use. I have tested it by following an instructable.

                      1 Reply Last reply
                      0
                      • rvendrameR rvendrame

                        Do you have a standalone relay, or a arduino relay board, like this picture?
                        http://www.mysensors.org/relay/relayModule.png

                        The board contains a transistor. Some boards also have a 'hi-low' switch, if yours have it, you may try to play with it.

                        The arduino output is max of 40ma and will eventually burn or not operate correctly if connected directly to a relay. You must have a transistor in between.

                        Make sure you relay board contains at least this circuit: http://www.electroschematics.com/8975/arduino-control-relay/

                        F Offline
                        F Offline
                        fakeJake
                        wrote on last edited by
                        #43

                        @rvendrame You know what. I'm really thankful for you help and I'm really sorry for dragging you with me. I can turn the light on now. I just have to print "2;1;1;1;2;0;" instead of "2;1;1;1;2;1".

                        I will check if I will encounter any problem because of my relay module.
                        Again, thank you so much for your help. And I'm really sorry.

                        1 Reply Last reply
                        0
                        • rvendrameR Offline
                          rvendrameR Offline
                          rvendrame
                          Hero Member
                          wrote on last edited by
                          #44

                          Just swap the 0 & 1 here:

                          #define RELAY_ON 1  // GPIO value to write to turn on attached relay
                          #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
                          

                          and it will obey as you expect. Some relays boards have inverted input (Zero/GND is ON and VCC is OFF) ;-)

                          I'm glad it worked.

                          Home Assistant / Vera Plus UI7
                          ESP8266 GW + mySensors 2.3.2
                          Alexa / Google Home

                          1 Reply Last reply
                          1
                          • F Offline
                            F Offline
                            fakeJake
                            wrote on last edited by
                            #45
                            This post is deleted!
                            1 Reply Last reply
                            0
                            • F Offline
                              F Offline
                              fakeJake
                              wrote on last edited by
                              #46

                              Is there a way to receive only the last state of the sensors/actuators in the serial?

                              instead of:

                              0;0;3;0;9;read: 2-2-0 s=1,c=1,t=2,pt=2,l=2:1
                              0;0;3;0;9;send: 0-0-2-2 s=1,c=1,t=2,pt=2,l=2,st=ok:1
                              2;1;1;0;2;1
                              

                              it only print the "2;1;1;0;2;1" on the serial

                              1 Reply Last reply
                              0
                              • F Offline
                                F Offline
                                fakeJake
                                wrote on last edited by
                                #47

                                I placed if statement in serial function inside MyGateway.cpp
                                where 0 is the gateway address

                                void MyGateway::serial(MyMessage &msg) {
                                  if (msg.sender != 0); serial(PSTR("%d;%d;%d;%d;%d;%s\n"),msg.sender, msg.sensor, mGetCommand(msg), mGetAck(msg), msg.type, msg.getString(convBuf));
                                }
                                

                                Still it doesnt work.

                                Heres the format:

                                    msg.sender = GATEWAY_ADDRESS;
                                	msg.destination = destination;
                                	msg.sensor = sensor;
                                	msg.type = type;
                                	mSetCommand(msg,command);
                                	mSetRequestAck(msg,ack?1:0);
                                	mSetAck(msg,false);
                                	if (command == C_STREAM)
                                		msg.set(bvalue, blen);
                                	else
                                		msg.set(value);
                                
                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  Stric
                                  wrote on last edited by
                                  #48

                                  if (msg.sender != 0); serial(PSTR("%d;%d;%d;%d;%d;%s\n"),msg.sender, msg.sensor, mGetCommand(msg), mGetAck(msg), msg.type, msg.getString(convBuf));

                                  Note the ; after the 0) which should not belong there..

                                  F 1 Reply Last reply
                                  0
                                  • S Stric

                                    if (msg.sender != 0); serial(PSTR("%d;%d;%d;%d;%d;%s\n"),msg.sender, msg.sensor, mGetCommand(msg), mGetAck(msg), msg.type, msg.getString(convBuf));

                                    Note the ; after the 0) which should not belong there..

                                    F Offline
                                    F Offline
                                    fakeJake
                                    wrote on last edited by
                                    #49

                                    @Stric Removed it but still the read and send appears

                                    1 Reply Last reply
                                    0
                                    • F Offline
                                      F Offline
                                      fakeJake
                                      wrote on last edited by
                                      #50

                                      Should I post my new question on another board?

                                      Re: s there a way to receive only the last state of the sensors/actuators in the serial?

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

                                        The gateway itself doesn't buffer anything. It just forwards the data from your sensors.

                                        F 1 Reply Last reply
                                        0
                                        • hekH hek

                                          The gateway itself doesn't buffer anything. It just forwards the data from your sensors.

                                          F Offline
                                          F Offline
                                          fakeJake
                                          wrote on last edited by
                                          #52

                                          @hek can you please help me on what should I comment out?

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


                                          14

                                          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