433mhz outputs garbage

I am trying to make 4 LEDs that are controlled by a 433mhz transmitter and receiver, using analog joysticks connected to the transmitter. In the serial monitor on the transmitter, the values on the joystick are correct, however, when checking the serial monitor on the receiver, the data transmitted very quickly turns into garbage, after which it remains in this state until the board is reset.
transmitter

#include <RH_ASK.h>
#include <SPI.h>
 
 int JoystickX1 =0 ;
 int JoystickX2 =0 ;
 
  String str_J1;
  String str_J2;
  String str_out;

RH_ASK rf_driver;

void setup() {
  Serial.begin(9600);
  rf_driver.init();
  pinMode(A1,INPUT);
  pinMode(A0,INPUT);
}


void loop() {
delay(300);
JoystickX1=(analogRead(A0));
JoystickX2=(analogRead(A1));
 
str_J1 = String(JoystickX1);
str_J2 = String(JoystickX2);
str_out = str_J1 + "," + str_J2;

static char *msg = str_out.c_str();

rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();









Serial.println("J1: ");
   Serial.println(str_J1);
   Serial.println("J2: ");
    Serial.println(str_J2);




}

receiver


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




RH_ASK rf_driver;
 String str_J1;
 String str_J2;
 String str_out;
 

void setup() {
  // put your setup code here, to run once:
  rf_driver.init();
  Serial.begin(9600);
  pinMode(10,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(7,OUTPUT);
}

void loop() {
  uint8_t buf [8];
  uint8_t buflen = sizeof(buf);
  
  if (rf_driver.recv(buf, &buflen))
  {
     str_out = String((char*)buf);
     Serial.println(str_out);
    
     
  for(int i=0; i< str_out.length(); i++) {
   if (str_out.substring(i, i+1) == ","){
    str_J1 = str_out.substring(0, i);
    str_J2 = str_out.substring(i+1);
    break;
   }

   }
    Serial.print(str_J1);
     Serial.print(".");
     Serial.print(str_J2);
  
     int J1=str_J1.toInt();
     int J2=str_J2.toInt();
  
    if (J1<100){
      digitalWrite(10,HIGH);
  
    }
    else if(J1 >600){
       digitalWrite(9,HIGH);

    }
    else{
   digitalWrite(10,LOW);
   digitalWrite(9 ,LOW);
      
    }
  
   if (J2<100){
      digitalWrite(8,HIGH);
  
    }
    else if(J2 >600){
       digitalWrite(7,HIGH);

    }
    else{
   digitalWrite(8,LOW);
   digitalWrite(7,LOW);
      
    }




  
  
  }

 
 
  

}


Please share:

  • A schematic of your project
  • Links to (datasheets of) the modules and boards/Arduino you're using
  • A photo of the physical setup that clearly shows how everything is connected
  • Example output of the 'garbage' you mention (receiver side) and the data as it's supposed to look (transmitter side).

This implies that initially, you're getting correct data on the receiver, but it 'breaks' after some time - correct?

I'd recommend setting up a transmitter sketch that just sends the same package of data to the receiver all the time so you can test with that. Forget about reading the joysticks etc. for now; focus on the radio stuff first.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.