My Relay Module

  • I started a project with Mysensors to automate some parts of my home, I made the first gateway with Arduino and an ethernet shield.

    My goal was to have a 220V controlled by Vera Lite.

    What you need:
    -Arduino Nano
    -Radio module NRF24L01 +
    -breadboard thousand holes
    -Relay Module 10A
    -cables and plugs

    The wiring diagram.

    is important to the condensoatore of VCC and GND of the radio to the stability and the good reception of the same.

    Here's my self-built PCB



    we put it all in a box of Gewiss 8cm x 12 cm

    We insert the power supply

    finally finished work:

    Vera display

    Link code

    Thanks to All

  • Very nice write up! Next add some current sensing ability to see what your load is pulling. ๐Ÿ™‚ Although if used for lighting, mostly negligible I suppose haha.

  • Admin

    Nice setup @gigi!

  • @NotYetRated said:

    Very nice write up! Next add some current sensing ability to see what your load is pulling. ๐Ÿ™‚

    A non invasive sensor would be ideal. I alredy use energimonitor for solar panels!!!!!

  • Bello GiGi! Nice GiGi.

    If you want pm me as I understand we are from the same country.
    May be we can exchange some experience in italian ๐Ÿ˜‰
    Will copy your design

  • if we put this box in wall then power supply will safe or not?

    5v power supply adapter's temperature will afact or not?

  • any one care to confirm whats happening with the AC wires in this? i cant quite make it out from the photos

  • Hello everyone , I have a problem . maybe it's stupid , I have a server with raspberry domoticz , I downloaded code, but by the following errorCattura.PNG

  • Admin

    You seem to have downloaded the development branch of the MySensors library. The code you're trying to run is 1.5.

  • I downloaded this , . I Submitted libraries entirely within the zip file in my briefcase Arduino library.
    however it from the library is the 1.5 readme. Where am I wrong ?
    il codice รจ il seguente

    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>
    #define RELAY_PIN 4 // Arduino Digital I/O pin number for relay
    #define BUTTON_PIN 3 // Arduino Digital I/O pin number for button
    #define CHILD_ID 1 // Id of the sensor child
    #define RELAY_ON 1
    #define RELAY_OFF 0
    Bounce debouncer = Bounce();
    int oldValue=0;
    bool state;
    MySensor gw;
    MyMessage msg(CHILD_ID,V_LIGHT);
    void setup()
    gw.begin(incomingMessage, AUTO, true);
    // Send the sketch version information to the gateway and Controller
    gw.sendSketchInfo("Relay & Button", "1.0");
    // Setup the button
    // Activate internal pull-up
    // After setting up the button, setup debouncer
    // Register all sensors to gw (they will be created as child devices)
    gw.present(CHILD_ID, S_LIGHT);
    // Make sure relays are off when starting up
    digitalWrite(RELAY_PIN, RELAY_OFF);
    // Then set relay pins in output mode
    pinMode(RELAY_PIN, OUTPUT);
    // Set relay to last known state (using eeprom storage)
    state = gw.loadState(CHILD_ID);
    digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
    * Example on how to asynchronously check for new messages from gw
    void loop()
    // Get the update value
    int value =;
    if (value != oldValue && value==0) {
    gw.send(msg.set(state?false:true), true); // Send new state and request ack back
    oldValue = value;
    void incomingMessage(const MyMessage &message) {
    // We only expect one type of message from controller. But we better check anyway.
    if (message.isAck()) {
    Serial.println("This is an ack from gateway");
    if (message.type == V_LIGHT) {
    // Change relay state
    state = message.getBool();
    digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
    // Store state in eeprom
    gw.saveState(CHILD_ID, state);
    // Write some debug info
    Serial.print("Incoming change for sensor:");
    Serial.print(", New status: ");

  • Admin

  • thank you! I apologize for my level , I hope to fix with your help.

  • Here is the improved code that I used on my Arduino Mega to create a home automation controller

    New optimized code to arduino mega

  • Update: Forget it, the code works with Arduino Mini and 2 relay. I tried one after the code of Arduino Mega and not working. Something wrong but I do not know what I require help

    I found mistakes on Arduino Mega solvable at the following link
    but I do not have this kind of problem you can get support? I connected NRF24L01 to Arduino Mega, as if it were an Arduino Nano, right?

  • Admin

    The SPI pins has different pin numbers on the Mega.

    Here is an example that runs the the Mega:

  • I connected the radio module as follows

    AtMega 2650 Arduino Step Down Module/Radio
    GND > GND
    5V > Step Down module VCC
    14 > SCK
    15 > MOSI
    16 > MISO
    17 > CE
    18 > CSN
    I tried but it did not work I tried to connect also IrQ
    2 > IRQ
    it did not work. I tried to connect to 3v3 with the capacitor. it did not work. I tried adding the line in the code
    #include <MyTransportNRF24.h>
    #include <MyHwATMega328.h>
    but to no avail. I am groping in the dark

  • Admin

    You haven't said what problem you experience. Logs or anything else...

  • I have "check wires" error on the serial arduino....
    where do I fit in debug mode there is a guide?
    I saw a video that uses MQTT program on mac.
    I have downloaded windows MYSController I can be of help? How do I connect my PC? It is all new and are a little confused. ๐Ÿ˜ต ๐Ÿˆณ

    I "atmega adk" is a problem?

  • Have you defined using softspi since using those pins?

    I'm using different pins with mega and everything started to work after adding capacitor to radio:
    GND > GND
    3.3 > VCC
    52 > SCK
    51 > MOSI
    50 > MISO
    9 > CE
    10 > CSN
    2 > IRQ

  • soon as I finish the project it will create a new post in the category myproject
    @pjr unfortunately I read your seat now but I confirm that pins are those that use exact thank - @salvato that helped me as an angel.

    the irq pin does not need to be connected

Log in to reply

Suggested Topics

  • 8
  • 1
  • 2
  • 2
  • 1
  • 3