My first project, KAKU RF reciever/transmitter



  • Hello,

    I build my first mysensor project around an Arduino nano and some cheap RF reciever/transmitter.

    The code could be optimized, maybe some kind of self learning, but don't know how to do that 🙂

    Also like to decode the recived signal to normal code like (KAKU code A,1)

    So feel free to give some advise 😉

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.1 - Arnold Geurtse
     * 
     * DESCRIPTION
     * This sketch is to control my RF433 KAKU plugins with mysensor
     * in this case i use the old rotating switch type recievers
     * Reciver connected to pin 3
     * Transmitter connected to pin 7
     * As transmitter/reciver library i use this site
     * https://bitbucket.org/fuzzillogic/433mhzforarduino/wiki/Home
     * 
     * also going to build a beter antene for the reciver and transmitter.
     * http://www.elektor.nl/Uploads/Forum/Posts/How-to-make-a-Air-Cooled-433MHz-antenna.pdf
     */ 
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <RemoteTransmitter.h>
    #include <RemoteReceiver.h>
    
    #define MY_NODE_ID 100
    #define NODE_TXT "RF433 interface" 
    
    #define CHILD_ID1 1   // Id of the sensor child
    #define CHILD_ID2 2   // Id of the sensor child
    #define CHILD_ID3 3   // Id of the sensor child
    #define CHILD_ID4 4   // Id of the sensor child
    #define CHILD_ID5 5   // Id of the sensor child
    
    #undef MY_DEBUG;
    
    MyMessage switch1(CHILD_ID1, V_LIGHT);
    MyMessage switch2(CHILD_ID2, V_LIGHT);
    MyMessage switch3(CHILD_ID3, V_LIGHT);
    MyMessage switch4(CHILD_ID4, V_LIGHT);
    MyMessage switch5(CHILD_ID5, V_LIGHT);
    
    bool State;
    
    // Intantiate a new KaKuTransmitter remote, also use pin 11 (same transmitter!)
    KaKuTransmitter kaKuTransmitter(7);
    
    MySensor gw;
    
    void setup()  
    {  
      gw.begin(incomingMessage,MY_NODE_ID);
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("RF 433 kaku interface", "1.0");
    
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID1, S_LIGHT, "Keuken", NODE_TXT);
      gw.present(CHILD_ID2, S_LIGHT, "Computer", NODE_TXT);
      gw.present(CHILD_ID3, S_LIGHT, "Bank", NODE_TXT);
      gw.present(CHILD_ID4, S_LIGHT, "Vensterbank", NODE_TXT);
      gw.present(CHILD_ID5, S_LIGHT, "TV", NODE_TXT);
    
    
        // Initialize receiver on interrupt 0 (= digital pin 2), calls the callback "showCode"
      // after 3 identical codes have been received in a row. (thus, keep the button pressed
      // for a moment)
      //
      // See the interrupt-parameter of attachInterrupt for possible values (and pins)
      // to connect the receiver.
      RemoteReceiver::init(0, 3, showCode);
      
    
    
    }
    
    
    /*
    *  Example on how to asynchronously check for new messages from gw
    */
    void loop() 
    {
      gw.process();
    } 
    
    
    void showCode(unsigned long receivedCode, unsigned int period) {
        switch (receivedCode) {
          case 24:
            gw.send(switch1.set(0));
          break;
          case 26:
            gw.send(switch1.set(1));
          break;
          case 4398: 
            gw.send(switch2.set(0));
          break;
          case 4400: 
            gw.send(switch2.set(1));
          break;
          case 1482: 
            gw.send(switch3.set(0));
          break;
          case 1484: 
            gw.send(switch3.set(1));
          break;
          case 354318: 
            gw.send(switch4.set(0));
          break;
          case 354320: 
            gw.send(switch4.set(1));
          break;
          case 358692: 
            gw.send(switch5.set(0));
          break;
          case 358694: 
            gw.send(switch5.set(1));
          break;
        }
    
    }
    
    
    
    void incomingMessage(const MyMessage &message) {
    
      if (message.type == V_LIGHT) {
         // Change relay state
        State = message.getBool();
    
        switch (message.sensor) {
          case 1:
            kaKuTransmitter.sendSignal('A',1,State);
          break;
          case 2:
            kaKuTransmitter.sendSignal('A',2,State);
          break;
          case 3:
            kaKuTransmitter.sendSignal('A',3,State);
          break;
          case 4:
            kaKuTransmitter.sendSignal('B',1,State);
          break;
          case 5:
            kaKuTransmitter.sendSignal('B',2,State);
          break;   
         }
       } 
    }
    

Log in to reply
 

Suggested Topics

  • 8
  • 1
  • 7
  • 2
  • 1
  • 44

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts