Sending numbers with rf 433 MHz rx and tx modules

I am using an rf module to send numbers to two ardunos.
Using the radio head library I did the normal example of sending a msg(inthis case Welcome to the Workshop)
Which worked fine.
But using if statements I made it send the number 1 if it recieved input from pin 4
And 2 if input from pin 5.

All I'm getting on the reciver end is random numbers.

Any help would be amazing.

Troubleshooting code that we cannot see is difficult, doubly so now that my crystal ball is out for an oil change.

Post your transmit and receive codes. Please read the forum guidelines to see how to properly post code and some information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Post examples of what is sent and received.

There is a small bug on line 42, and I would double check the red wire, it seems a bit loose from what I can see from here...

cristal

1 Like

here is the reciver code

#include <RH_ASK.h>
#include <SPI.h>

RH_ASK driver;

void setup()
{
  Serial.begin(9600);
  driver.init();
}

void loop()
{
  uint16_t data;
  uint8_t datalen = sizeof(data);
  if (driver.recv((uint8_t*)&data, &datalen))
  {
    Serial.println(data);
  }
}

and the transmitter code

// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library 
#include <SPI.h> 

 const byte front = 6;
 const byte back = 7;
 const byte right = 8; 
 const byte left = 9; 

 byte motonum = 0;
  
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
 
void setup()
{
  pinMode(front,INPUT);
  pinMode(back,INPUT); 
  pinMode(right,INPUT); 
  pinMode(left,INPUT); 

  
    // Initialize ASK Object
    rf_driver.init();
}
 
void loop()
{

  if(digitalRead(front) == HIGH)
  {
    motonum = 1;
    }
 



   if(digitalRead(back) == HIGH)
  {
    motonum = 2;
    }




   if(digitalRead(right) == HIGH)
  {
    motonum = 3;
    }



   if(digitalRead(left) == HIGH)
  {
    motonum = 4;
    }


      
      
     char *msg = motonum ;
    rf_driver.send((uint8_t *)msg, strlen(msg));
    rf_driver.waitPacketSent();
    delay(100);
   
}

the input ports are 6,7,8,9

really ? what do you expect from this? turn on the warnings when compiling.

how are your buttons wired ?

two 3 pos switches both powered by arduino uno 3.3 v port.
switch1 = front,back, one pos to 6,other pos to 7
switch2 = left,right one pos to 8,other pos to 9

Please post a schematic. Written descriptions are always more ambiguous than a drawing. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.

yeah, we need a real circuit drawing. any resistor in the mix ?

also the code you posted does not make sense.

you could just send the data in binary format as

rf_driver.send((uint8_t *)&motonum, sizeof motonum);

Sry for the quality but here


u go

Wut do u mean .
Can u side by side compare and help.

I mean use that to send your value (define motonum as uint16_t)
I doubt the buttons work as you have no pull down.

Can u explain pulldown with my switches

read any button tutorial... here are a couple if google search is broken where you live

what will the receiver code for this look like
?

➜ if you send 1 byte, so you should just receive 1 byte

so like this?

#include <RH_ASK.h>
#include <SPI.h>

int rightfront = 1;
int rightback = 2;
int leftfront = 3;
int leftback = 4;

RH_ASK driver;

void setup()
{
  Serial.begin(9600);
  driver.init();
}

void loop()
{
  uint16_t data;
  uint8_t datalen = sizeof(data);
  if (driver.recv((uint8_t*)&data, &datalen))
  {
    Serial.println(data);
  }


  if(data == 1)
  {
    //switch on motor driver front pins
    
    digitalWrite(rightfront,HIGH);
    digitalWrite(leftfront,HIGH);
    
    //switch off other back pins
    
    digitalWrite(rightback,LOW);
    digitalWrite(leftback,LOW);
    
    }

   else if(data == 2)
  {
    //switch on motor driver back pins
    
    digitalWrite(rightback,HIGH);
    digitalWrite(leftback,HIGH);
    
  //switch off other front pins
  
     digitalWrite(rightfront,LOW);
    digitalWrite(leftfront,LOW);
    
  }

  else if(data == 3)
  {
    //switch on right back and left front pins to turn right
    
   digitalWrite(rightback,HIGH);
    digitalWrite(leftfront,HIGH); 
    
   //set left back and front back to off
   
    digitalWrite(rightfront,LOW);
    digitalWrite(leftback,LOW);
   
    }
    
   else if(data == 4)
  {
    //switch on right front and left back pins to turn right
    
   digitalWrite(rightfront,HIGH);
    digitalWrite(leftback,HIGH); 
    
   //set left front and right back to off
   
    digitalWrite(rightback,LOW);
    digitalWrite(leftfront,LOW);
    }
    
}

well no

if you send just one byte (a uint8_t) why would you want to receive two bytes (a uint16_t ) ?

idint know that one byte was uint8_t.
sry