RFM12b SPI

Is there an example code for Arduino for RFM12B, where A switch is on the sender and A led is on the receiver. So you hit the switch and the led lights up on the receiver.

Here is some code I found. I would like it if some one would make it simple for me.
Like one switch to one led and one pot to one (pwm) led.

That would be great

//Simple RFM12B wireless demo - transimtter - no ack
//Glyn Hudson openenergymonitor.org GNU GPL V3 7/7/11
//Credit to JCW from Jeelabs.org for RFM12 

#include <JeeLib.h>  //from jeelabs.org
#include <Wire.h>
#include "nunchuck_funcs.h"

#define myNodeID 10          //node ID of tx (range 0-30)
#define network     210      //network group (can be in the range 1-250).
#define freq RF12_915MHZ     //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module

typedef struct // create structure - a neat way of packaging data for RF comms
{ 
  int jx, jy, acy, acx, zButton, cButton; // data from the controller. these have to match.
} 
PayloadTX;      
PayloadTX wiichuck;  
byte accx,accy,zbut,cbut,joyx,joyy; // names of the nunchuck data

void setup()
{
  rf12_initialize(myNodeID,freq,network);   //Initialize RFM12 with settings defined above  
  Serial.begin(9600);
  // Serial.println("RFM12B Transmitter - My Nunchuck RC Car");  // this is all pointless
  // Serial.print("Node: ");                                     // and a waste of space
  // Serial.print(myNodeID);                                     // but i keep it just
  // Serial.print(" Freq: ");                                    // in case something
  // if (freq == RF12_433MHZ) Serial.print("433Mhz");            // goes wrong
  // Serial.print(" Network: "); 
  // Serial.println(network);
  nunchuck_setpowerpins();
  nunchuck_init(); // send the initilization handshake
}

void loop()
{
  nunchuck_get_data();

  accx  = nunchuck_accelx(1); // ranges from approx 70 - 182
  accy  = nunchuck_accely(2); // ranges from approx 65 - 173
  zbut = nunchuck_zbutton(3);
  cbut = nunchuck_cbutton(4); 
  joyx = nunchuck_joyx(5);
  joyy = nunchuck_joyy(6);

  wiichuck.jx = joyx; // read wii angle and store value
  wiichuck.jx = map(wiichuck.jx, 30, 220, 0, 179); // map the joystick data for servo use
  wiichuck.jy = joyy;
  wiichuck.jy = map(wiichuck.jy, 30, 220, 0, 179); 
  wiichuck.acy = accy;
  wiichuck.acx = accx;
  wiichuck.acx = map(wiichuck.acx, 65, 173, 135, 45); // mapp the accelerometer data to drive the car
  wiichuck.cButton = cbut;
  wiichuck.zButton = zbut;

  int i = 0; 
  while (!rf12_canSend() && i<10)
  {
    rf12_recvDone(); 
    i++;
  }

  rf12_sendStart(0, &wiichuck, sizeof wiichuck);


  //Serial.print("JX Axis: "); //not necessary
  //Serial.println(wiichuck.jx);
  //Serial.print("JY Axis: "); //not necessary
  //Serial.println(wiichuck.jy);
  //Serial.print("Y Axis: "); //not necessary
  //Serial.println(wiichuck.acy);
  //Serial.print("X Axis: "); //not necessary
  //Serial.println(wiichuck.acx);
  //Serial.print("C Button: "); //not necessary
  //Serial.println(wiichuck.cButton);
  //Serial.print("Z Button: "); //not necessary
  //Serial.println(wiichuck.zButton);

  delay(20);
}
//RX REC



#include <Servo.h>

//credit for RFM12B code from
//Glyn Hudson openenergymonitor.org GNU GPL V3 12/4/12
//Credit to JCW from Jeelabs.org for RFM12 

#include <JeeLib.h>

#define myNodeID 30          //node ID of Rx (range 0-30) 
#define network     210      //network group (can be in the range 1-250).
#define freq RF12_915MHZ     //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module

typedef struct
{ 
  int jx, jy, acy, acx, zButton, cButton; // this is the data from the controller. they must match.
} 
PayloadTX;      
PayloadTX wiichuck;   // the payload, named wiichuck

const int wiichuck_NodeID=10;            //emonTx node 

Servo steerServo;
int servopin1=9;
int steer = 90;
int joyx; // Joystick X axis
int joyy; // joystick Y axis
int accy; // Accelerometer Y axis
int acyf; // Forward
int acyr; // Reverse
int accx; // Accelerometer X axis
int brake; // Brake function
int whatever; // i never used this for anything, but it's here
int motorpos=5; // output to motor driver
int motorneg=6; // output to motor driver
int counter=0; // counter for brake function

void setup() {

  rf12_initialize(myNodeID,freq,network);   //Initialize RFM12 with settings defined above  
  Serial.begin(9600); 
  //  Serial.println("RF12B demo Receiver - Simple demo"); //pointless memory waste
  //  Serial.print("Node: ");                              // but i keep it all here
  //  Serial.print(myNodeID);                              // just in case
  //  Serial.print(" Freq: ");                             // something screws up
  //  if (freq == RF12_433MHZ) Serial.print("433Mhz");
  //  Serial.print(" Network: "); 
  //  Serial.println(network);
  steerServo.attach(servopin1);
  steerServo.write(steer);
  pinMode(motorpos, OUTPUT); // drive forward
  pinMode(motorneg, OUTPUT); // drive reverse
}

void loop() {

  if (rf12_recvDone()){    
    if (rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0) // i have no idea what this does but i guess its important
    {
      int node_id = (rf12_hdr & 0x1F);		  //extract nodeID from payload

      if (node_id == wiichuck_NodeID)  {             //check data is coming from node with the corrct ID
        wiichuck=*(PayloadTX*) rf12_data;            // Extract the data from the payload 

        joyx = wiichuck.jx;
        joyy = wiichuck.jy;
        accy = wiichuck.acy;
        accx = wiichuck.acx;
        brake = wiichuck.cButton;
        whatever = wiichuck.zButton;

        if(brake == 1) // if the brake button (c button on the nunchuck) gets pressed, increase the counter
        {
          counter++;
          delay(200); // debounce time
        }
        if(counter == 0 || counter == 2) // turn on the brake
        {
          digitalWrite(motorpos, HIGH);
          digitalWrite(motorneg, HIGH); 
          steerServo.write(90); //centers steering
        }
        else
        {
          acyf = map(accy, 110, 177, 30, 255); // remaps the accelerometer readings for driving forward
          acyr = map(accy, 100, 70, 30, 200); // reverse

          if(accy > 110 && accy <182) // Drive forward!
          {
            //forward
            digitalWrite(motorpos, HIGH);
            digitalWrite(motorneg, LOW);
            analogWrite(3, acyf); // speed
          }

          if(accy < 100) // Reverse!
          {
            //backward
            digitalWrite(motorpos, LOW);
            digitalWrite(motorneg, HIGH);
            analogWrite(3, acyr);   //speed
          }

          if(accy > 100 && accy < 110 || brake == 1)  //if the accelerometer is inbetween the forward and reverse, dont do anything.
          {
            digitalWrite(motorpos, LOW);
            digitalWrite(motorneg, LOW);
            steerServo.write(90); //centers steering
          }
          else
          {
            steerServo.write(accx); //steering control
          }
        }
        if(counter==2) //resets counter
        {
          counter=0;
        }
      }
    }
  }
  // used for testing
  //Serial.print("JX Axis: "); //not necessary
  //Serial.println(wiichuck.jx);
  //Serial.print("JY Axis: "); //not necessary
  //Serial.println(wiichuck.jy);
  //Serial.print("YF Speed: "); //not necessary
  //Serial.println(acyf);
  //Serial.print("YR Speed: "); //not necessary
  //Serial.println(acyr);
  //Serial.print("X Axis: "); //not necessary
  //Serial.println(wiichuck.acx);
  //Serial.print("C Button: "); //not necessary
  //Serial.println(wiichuck.cButton);
  //Serial.print("Z Button: "); //not necessary
  //Serial.println(wiichuck.zButton);
}

Look at low power labs RFM12 library, and the following examples: LED_Control_Gateway and LED_Control_Node.

Is this A start…

TX

int val;
int new_val;


#include <JeeLib.h>  //from jeelabs.org
#include <Wire.h>

#define myNodeID 10          //node ID of tx (range 0-30)
#define network     210      //network group (can be in the range 1-250).
#define freq RF12_915MHZ     //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module

typedef struct // create structure - a neat way of packaging data for RF comms
{ 
  int new_val; //the data that we are transmitting to the RC Car
} 
PayloadTX;      
PayloadTX rcCar;  


void setup()
{
  rf12_initialize(myNodeID,freq,network);   //Initialize RFM12 with settings defined above  
  Serial.begin(9600);
 
 void loop();

 {

val = analogRead(0);


new_val = map(val, 0, 1023, 253, 0); 

delay(150);

rf12_sendStart(uint8_t,new_val);
}
#include <JeeLib.h>
const int rcCar_NodeID=10;

#define myNodeID 30          //node ID of Rx (range 0-30) 
#define network     210      //network group (can be in the range 1-250).
#define freq RF12_915MHZ     //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module

typedef struct
{ 
  int new_val; // the data that we are recieving from the controller
} 
PayloadTX;      
PayloadTX rcCar;  

void setup()
{
 rf12_initialize(myNodeID,freq,network);   //Initialize RFM12 with settings defined above  
  Serial.begin(9600); 
pinMode (5, OUTPUT);
}
void loop()

{
   if (rf12_recvDone()){    
    if (rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0)
    {
      int node_id = (rf12_hdr & 0x1F);		  //extract nodeID from payload
    }
      if (node_id == rcCar_NodeID)  {             //check data is coming from node with the corrct ID
        rcCar=*(PayloadTX*) rf12_data;            // Extract 
  }
{
analogWrite (5, pot);
}

A few months ago, I wasted an IMMENSE amount of time trying to get jeelib to do something, and now I won't even look at it. So, good luck.

Thank you for your help....

I found this simple code, but it's now the RX side, is not compiling.

Here is where I found it......

https://github.com/zookzook/RFM12

TX TX

#include "rfm12.h"

typedef struct {
  uint16_t temp;
  uint8_t counter;
} Payload;

Payload payload;    

void setup() { rfm12_setup( 2, RF12_915MHZ, 200 ); }

void loop() {   
  if( rfm12_canSend() ) {
    payload.temp= 20.10;
    payload.counter= 1;
    rfm12_send( &payload, sizeof payload );
  }

}

RX RX

#include "rf12m.h"

typedef struct {
  uint16_t temp;
  uint8_t counter;
} Payload;

void setup () { rf12m_init( 1, RF12_868MHZ, 200 ); }

void loop () {
  
  rf12mListen();  
  
   if (didReceive() ) {
     Payload* p= (Payload*)&rf12Buffer[ 2 ];        
     Serial.print( p->counter );
     Serial.print( ". Temperature:" );
     Serial.println( (float)p->temp / 100.0 );
     didProcess();
    }      
}

I gave you a suggestion in reply #2, and which I know to work. Beyond that, maybe someone else can help you.

Alright, here you go. I cant verify this works as I’m at work right now, but im pretty sure the rfm12b code works, you may have to fine tune the rest of it. All this does is have a button on one side and an led on the other. if you study the code you’ll see that not only do you have to have INT names for everything you want to send (you’ll see from the original code you copied from my rc car, there are several names for all my car functions). You also need to have a payload name. In order for you to send anything, you have to combine those 2. i named the payload MyData, and the INT is named buttonState. in order to use it (at all) you have to call it “MyData.buttonState” . ALWAYS. that is now the INT name as far as the arduino is concerned. So, here is the code.

Transmit Side

#include <JeeLib.h>  //from jeelabs.org
#include <Wire.h>

#define myNodeID 10          //node ID of tx (range 0-30)
#define network     210      //network group (can be in the range 1-250).
#define freq RF12_915MHZ     //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module

typedef struct // create structure - a neat way of packaging data for RF comms
{ 
  int buttonState; //the data that we are transmitting
} 
PayloadTX;      
PayloadTX MyData;  //MyData is the name of your payload

int button1 = 3;

void setup()
{
  rf12_initialize(myNodeID,freq,network);   //Initialize RFM12 with settings defined above  
  Serial.begin(9600);
}
void loop()

{

  MyData.buttonState = digitalRead(button1);

  while (!rf12_canSend() && i<10)
  {
    rf12_recvDone(); 
    i++;
  }

  rf12_sendStart(0, &MyData, sizeof MyData);

  delay(20);
}

Receive Side

#include <JeeLib.h>
const int rcCar_NodeID=10;

#define myNodeID 30          //node ID of Rx (range 0-30) 
#define network     210      //network group (can be in the range 1-250).
#define freq RF12_915MHZ     //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module

typedef struct
{ 
  int buttonState; // the data that we are recieving from the controller
} 
PayloadTX;      
PayloadTX MyData;  //the name of your payload

int led1 = 5;

void setup()
{
  rf12_initialize(myNodeID,freq,network);   //Initialize RFM12 with settings defined above  
  Serial.begin(9600); 
  pinMode (led1, OUTPUT);
}
void loop()

{
  if (rf12_recvDone()){    
    if (rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0)
    {
      int node_id = (rf12_hdr & 0x1F);		  //extract nodeID from payload
    }
    if (node_id == MyData_NodeID)  {             //check data is coming from node with the corrct ID
      MyData=*(PayloadTX*) rf12_data;            // Extract 
    }

    if(MyData.buttonState == 1)
    {
      digitalWrite(led1, HIGH);
    }
    else
    {
      digitalWrite(led1, LOW);
    }
  }
}

Make note that you will need the jeelibs library.

Have fun, hope it works.

Is there A way to use An 16-byte encryption KEY like lowpowerlab’s has on this program, and use it on my TX and RX code?

Thank you

Lowpowerlabs code

#include <RFM12B.h>
#include <avr/sleep.h>

// You will need to initialize the radio by telling it what ID it has and what network it's on
// The NodeID takes values from 1-127, 0 is reserved for sending broadcast messages (send to all nodes)
// The Network ID takes values from 0-255
// By default the SPI-SS line used is D10 on Atmega328. You can change it by calling .SetCS(pin) where pin can be {8,9,10}
#define NODEID        2  //network ID used for this unit
#define NETWORKID    99  //the network ID we are on
#define GATEWAYID     1  //the node ID we're sending to
#define ACK_TIME     50  // # of ms to wait for an ack
#define SERIAL_BAUD  115200

//encryption is OPTIONAL
//to enable encryption you will need to:
// - provide a 16-byte encryption KEY (same on all nodes that talk encrypted)
// - to call .Encrypt(KEY) to start encrypting
// - to stop encrypting call .Encrypt(NULL)
uint8_t KEY[] = "ABCDABCDABCDABCD";

int interPacketDelay = 1000; //wait this many ms between sending packets
char input = 0;

// Need an instance of the Radio Module
RFM12B radio;
byte sendSize=0;
char payload[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*(){}[]`|<>?+=:;,.";
bool requestACK=false;

void setup()
{
  Serial.begin(SERIAL_BAUD);
  radio.Initialize(NODEID, RF12_433MHZ, NETWORKID);
  radio.Encrypt(KEY);
  radio.Sleep(); //sleep right away to save power
  Serial.println("Transmitting...\n\n");
}

void loop()

TX

int val;
int new_val;
int power1;
int buttonState = 0;
const int buttonPin = 7;

#include <JeeLib.h> 

#define myNodeID 10          //node ID of tx (range 0-30)
#define network     210      //network group (can be in the range 1-250).
#define freq RF12_915MHZ     //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module


typedef struct { int power1, power2, power3, battery,brian; } PayloadTX;      // create structure - a neat way of packaging data for RF comms
PayloadTX emontx;  

void setup() {
  rf12_initialize(myNodeID,freq,network);   //Initialize RFM12 with settings defined above  
Serial.begin(9600);
pinMode(buttonPin, INPUT); 


}

void loop() {
  
  
  val = analogRead(0);
  
  new_val = map(val, 0, 1023, 253, 0); 
  
 buttonState = digitalRead(buttonPin);
  
 emontx.power1=emontx.power1=new_val;
 emontx.power2=emontx.power2=buttonState;
 emontx.power3=emontx.power3+3;
 emontx.battery=emontx.battery+4;
 emontx.brian=emontx.brian+1000;
 
  int i = 0; while (!rf12_canSend() && i<10) {rf12_recvDone(); i++;}
    rf12_sendStart(0, &emontx, sizeof emontx);
    
  Serial.print("power1: "); Serial.println(emontx.power1); 
  Serial.print("power2: "); Serial.println(emontx.power2); 
  Serial.print("power3: "); Serial.println(emontx.power3); 
  Serial.print("battery: "); Serial.println(emontx.battery); 
  Serial.print("brian: "); Serial.println(emontx.brian);
  Serial.print(new_val);
  Serial.println("  "); 
         
  delay(1000);
}

RX

byte power1;
const int ledPin =  9;

#include <JeeLib.h>

#define myNodeID 30          //node ID of Rx (range 0-30) 
#define network     210      //network group (can be in the range 1-250).
#define freq RF12_915MHZ     //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module

typedef struct { int power1, power2, power3, battery,brian; } PayloadTX;      // create structure - a neat way of packaging data for RF comms
PayloadTX emontx;  

const int emonTx_NodeID=10;            //emonTx node ID

void setup() {
  
  rf12_initialize(myNodeID,freq,network);   //Initialize RFM12 with settings defined above  
  Serial.begin(9600); 
 
  
 pinMode(ledPin, OUTPUT); 
 pinMode (6, OUTPUT); 
}

void loop() {
  
 if (rf12_recvDone()){    
  if (rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0) {
    
    int node_id = (rf12_hdr & 0x1F);		  //extract nodeID from payload
        
    if (node_id == emonTx_NodeID)  {             //check data is coming from node with the corrct ID
        emontx=*(PayloadTX*) rf12_data;            // Extract the data from the payload 
       Serial.print("power1: "); Serial.println(emontx.power1); 
       Serial.print("power2: "); Serial.println(emontx.power2); 
       Serial.print("power3: "); Serial.println(emontx.power3); 
       Serial.print("battery: "); Serial.println(emontx.battery);
       Serial.print("brian: "); Serial.println(emontx.brian);
       Serial.println("  "); 
       analogWrite (9, emontx.power1);
       
        if (emontx.power2 == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
       
  }
 }
}
}

Why not plug in the encryption code key and try it?

I tried to put the encryption KEY in the code, and it tells me (RFM12B does not name a type).
When I compile the code.

int val;
int new_val;
int power1;
int buttonState = 0;
const int buttonPin = 7;

#include <JeeLib.h> 

#define myNodeID 10          //node ID of tx (range 0-30)
#define network     210      //network group (can be in the range 1-250).
#define freq RF12_915MHZ     //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module

uint8_t KEY[] = "ABCDABCDABCDABCD";
RFM12B radio;

typedef struct { int power1, power2, power3, battery,brian; } PayloadTX;      // create structure - a neat way of packaging data for RF comms
PayloadTX emontx;  

void setup() {
rf12_initialize(myNodeID,freq,network);   //Initialize RFM12 with settings defined above  
Serial.begin(9600);
pinMode(buttonPin, INPUT); 

radio.Encrypt(KEY);

}

void loop() {
  
  
  val = analogRead(0);
  
  new_val = map(val, 0, 1023, 253, 0); 
  
 buttonState = digitalRead(buttonPin);
  
 emontx.power1=emontx.power1=new_val;
 emontx.power2=emontx.power2=buttonState;
 emontx.power3=emontx.power3+3;
 emontx.battery=emontx.battery+4;
 emontx.brian=emontx.brian+1000;
 
  int i = 0; while (!rf12_canSend() && i<10) {rf12_recvDone(); i++;}
    rf12_sendStart(0, &emontx, sizeof emontx);
    
  Serial.print("power1: "); Serial.println(emontx.power1); 
  Serial.print("power2: "); Serial.println(emontx.power2); 
  Serial.print("power3: "); Serial.println(emontx.power3); 
  Serial.print("battery: "); Serial.println(emontx.battery); 
  Serial.print("brian: "); Serial.println(emontx.brian);
  Serial.print(new_val);
  Serial.println("  "); 
         
  delay(1000);
}

Here what I came up with. I am missing something, because when I change the state from high on pin 7 on Tx side,
the Rx side show 254.

Here is what I need help on is, I am trying to make one led turn on and off with one push bottom.
One led go from 0 to 255 with A (pwm) pot.

Can some one help me out…

TX

int val;
int new_val;
int power1;
int buttonState = 0;
const int buttonPin = 7;

#include <RFM12B.h>
#include <avr/sleep.h>


#define NODEID        2  //network ID used for this unit
#define NETWORKID    99  //the network ID we are on
#define GATEWAYID     1  //the node ID we're sending to
#define ACK_TIME     50  // # of ms to wait for an ack
#define SERIAL_BAUD  115200

uint8_t KEY[] = "ABCDABCDABCDABCD";

RFM12B radio;
typedef struct { 
int power1, power2, power3, battery,brian; 
} 
PayloadTX;
PayloadTX emontx; 


void setup()
{
  Serial.begin(SERIAL_BAUD);
  radio.Initialize(NODEID, RF12_433MHZ, NETWORKID);
  radio.Encrypt(KEY);
  radio.Sleep(); //sleep right away to save power
  Serial.println("Transmitting...\n\n");
}

void loop()
{
   val = analogRead(0);

  new_val = map(val, 0, 1023, 253, 0); 

  buttonState = digitalRead(buttonPin);

  emontx.power1=emontx.power1=new_val;
  emontx.power2=emontx.power2=buttonState;
  emontx.power3=emontx.power3+3;
  emontx.battery=emontx.battery+4;
  emontx.brian=emontx.brian+1000;
  
 radio.Wakeup();
 {
 radio.Send(0, &emontx, sizeof emontx);
 }
 

  Serial.print("power1: "); 
  Serial.println(emontx.power1); 
  Serial.print("power2: "); 
  Serial.println(emontx.power2); 
  Serial.print("power3: "); 
  Serial.println(emontx.power3); 
  Serial.print("battery: "); 
  Serial.println(emontx.battery); 
  Serial.print("brian: "); 
  Serial.println(emontx.brian);
  Serial.print(new_val);
  Serial.println("  "); 

  delay(1000);
}

RX

byte power1;
const int ledPin =  9;
const int ledPin2 =  7;
#include <RFM12B.h>


#define NODEID           1  //network ID used for this unit
#define NETWORKID       99  //the network ID we are on
#define SERIAL_BAUD 115200

typedef struct { int power1, power2, power3, battery,brian; } PayloadTX;
PayloadTX emontx;  

const int emonTx_NodeID=2;            //emonTx node ID

uint8_t KEY[] = "ABCDABCDABCDABCD";


RFM12B radio;
void setup()
{
  radio.Initialize(NODEID, RF12_433MHZ, NETWORKID);
  radio.Encrypt(KEY);      //comment this out to disable encryption
  Serial.begin(SERIAL_BAUD);
  Serial.println("Listening...");
  pinMode (7, OUTPUT); 
}

void loop()
{
  if (radio.ReceiveComplete())
  
  {
    if (radio.CRCPass())
    {
  
  
  
  
  // if (NodeID == emonTx_NodeID)  {             
        emontx=*(PayloadTX*)radio.DataLen;

  }
        
       Serial.print("power1: "); Serial.println(emontx.power1); 
       Serial.print("power2: "); Serial.println(emontx.power2); 
       Serial.print("power3: "); Serial.println(emontx.power3); 
       Serial.print("battery: "); Serial.println(emontx.battery);
       Serial.print("brian: "); Serial.println(emontx.brian);
       
       Serial.print(emontx.power1); 
       Serial.println("  "); 
       analogWrite (9, emontx.power1);
       
         if (emontx.power2 == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin2, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin2, LOW); 
  }
     
  }
  }

Here you go. took just a couple minutes looking through the jeelib library to find the encryption code. please do some research if you feel the need to modify this further. I’m happy to help, but i cant keep writing your code for you.

Transmitter Code

#include <JeeLib.h>  //from jeelabs.org THIS IS IMPORTANT! YOU NEED THIS!
#include <Wire.h>

#define myNodeID 10          //node ID of tx (range 0-30)
#define network     210      //network group (can be in the range 1-250).
#define freq RF12_915MHZ     //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module

typedef struct // create structure - a neat way of packaging data for RF comms
{ 
  int buttonState; //the data that we are transmitting
} 
PayloadTX;      
PayloadTX MyData;  //MyData is the name of your payload
uint8_t KEY[] = "ABCDABCDABCDABCD"; // you encryption key

int button1 = 3; //button, switch, whatever

void setup()
{
  rf12_initialize(myNodeID,freq,network);   //Initialize RFM12 with settings defined above  
  rf12_encrypt(KEY); //enable encryption
  Serial.begin(9600);
 pinMode(button1, INPUT);
}
void loop()

{

  MyData.buttonState = digitalRead(button1);
  int i=0;
  while (!rf12_canSend() && i<10)
  {
    rf12_recvDone(); 
    i++;
  }

  rf12_sendStart(0, &MyData, sizeof MyData);

  delay(20);
}

Reciever Code

#include <JeeLib.h>


#define myNodeID 30          //node ID of Rx (range 0-30) 
#define network     210      //network group (can be in the range 1-250).
#define freq RF12_915MHZ     //Freq of RF12B can be RF12_433MHZ, RF12_868MHZ or RF12_915MHZ. Match freq to module

typedef struct
{ 
  int buttonState; // the data that we are recieving from the controller
} 
PayloadTX;      
PayloadTX MyData;  //the name of your payload
uint8_t KEY[] = "ABCDABCDABCDABCD"; 
const int MyData_NodeID=10;
int led1 = 5;

void setup()
{
  rf12_initialize(myNodeID,freq,network);   //Initialize RFM12 with settings defined above  
  rf12_encrypt(KEY);
  Serial.begin(9600); 
  pinMode (led1, OUTPUT);
}
void loop()

{
  if (rf12_recvDone()){    
    if (rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0)
    {
      int node_id = (rf12_hdr & 0x1F);		  //extract nodeID from payload

      if (node_id == MyData_NodeID)  {             //check data is coming from node with the corrct ID
        MyData=*(PayloadTX*) rf12_data;            // Extract 
      }

      if(MyData.buttonState == 1)
      {
        digitalWrite(led1, HIGH);
      }
      else
      {
        digitalWrite(led1, LOW);
      }
    }
  }
}