Unable to receive integers while using transmitter and receiver 433mhz module

Hi i have been using transmitter and receiver module for ardiuno,I am able to transmit and receive data but the integers that i received are coming in wierd characters in the serial monitor,I have uploaded the code pls tell me whats wrong thanks
//RECEIVER

// RadioHead - Version: Latest
#include <RH_ASK.h>
#include <SPI.h>

RH_ASK driver;

void setup()
{
Serial.begin(9600);
if (!driver.init())
Serial.println("init failed");
}

void loop()
{
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen))
{
int i;
Serial.print("Message: ");
Serial.println((char*)buf);
}
}
transmitter code
#include <RH_ASK.h>
#include <SPI.h>

RH_ASK rf_driver;
int Ypin=A0;
int Yval;
void setup()
{
// Initialize ASK Object
rf_driver.init();
// Setup Serial Monitor
Serial.begin(9600);
pinMode(Ypin,INPUT);
}

void loop(){
Yval=analogRead(Ypin);

const char *msg = Yval;
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();

// Message Transmitted
Serial.print("Message Transmitted: ");
delay(100);
Serial.println(Yval);

}
note- i am just using y value of the joystick just to accelerate my dc motar but i havent uploaded my dc motar code as integers are not being able to be received properly, i am pretty sure i have a problem converting the data into bits i think because string values are easily being able to be received and transmitted without error,i have also tried virtual wire but the msgs are not being transmitted in that too.

Please edit your post to add code tags.

Here is one way to send an integer value (as binary):

Yval=analogRead(Ypin);
rf_driver.send((uint8_t *)&Yval, 2); //two bytes on AVR Arduino

and receive:

int value=0;
int buflen = 2; // max number of bytes allowed in message
if (driver.recv((uint8_t *) &value, &buflen))
  { if (buflen == 2)  //got correct message size?
     {  // do something with "value"
2 Likes

hello an error is coming,it says driver was not declared in scope

^^^ this prob

it is happening in the receiver side the transmitter code is working :slight_smile:

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

// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

void setup()
{
// Initialize ASK Object
rf_driver.init();
// Setup Serial Monitor
Serial.begin(9600);
}

void loop()
{
int value=0;
int buflen = 2;
if (driver.recv((uint8_t *) &value, &buflen))
{ if (buflen == 2)
{
Serial.println(value);
}
}
}

Please use code tags when posting code.

Corrected call is "rf_driver.recv()" :

if (rf_driver.recv((uint8_t *) &value, &buflen))
   { if (buflen == 2)
      {
        Serial.println(value);
       }
   }

its still showing an error
#include <RH_ASK.h> // Include RadioHead Amplitude Shift Keying Library
#include <SPI.h> // Include dependant SPI Library
RH_ASK rf_driver;
void setup()
{
rf_driver.init();

Serial.begin(9600);
}

void loop()
{
int value=0;
int buflen = 2;
if (rf_driver.recv((uint8_t ) &value, &buflen))
{ if (buflen == 2)
{
Serial.println(value);
}
}
error is- no matching function for call to 'RH_ASK::recv(uint8_t
, int*)'

hello sorry will do so from now on and thanks a lot for your help :slight_smile:

receiver part is a little tricky i always find an error in that

uint8_t buflen = 2;

At some point, you should actually read and make an attempt to understand the error messages.

yes i know i am sorry i am a new to ardiuno and unfamiliar with transmitter library :pensive: thanks a lot for your help tho :slight_smile:

i am so happy it finally worked thanks alot i couldnt have done it without your help :slight_smile: ill try to get better in it