Problem with receive messages from RF transmitter 433 MHz to RF receiver 433MHz

Hello,
I've just started with programming on Arduino so, I wonder if you could tell me your best and simplest solution(s).

I'm trying to send messages between 2 Arduino's (Nano and Uno) using RF module 433 MHz (Arduino Nano + transmitter -----> Uno+receiver). I've connected two LEDs on each data pin of the RF module to see if the module works or not. And the 2 LEDs blink (it means that the transmitter and the receiver work). But if I want to read the messages from my Arduino Uno, it seems that my Uno couldn't print it out on my computer screen.

And here is my electric circuit of RF module:

-Transmitter:
VCC -> 5V (on Arduino Nano)
DATA -> digital pin (ex. pin 12)
GND -> GND

-Receiver:

VCC -> 5V (on Arduino Uno)
DATA/ATAD -> digital pin (ex. pin 12)
GND -> GND

Code for Transmitter:

#include <VirtualWire.h>

void setup()
{
Serial.begin(9600);
Serial.println("Ready.........");
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_tx_pin(8); // set tx pin at digital pin 8
}

void loop()
{
char text[20] = "";
byte i = 0;
while (Serial.available() == 0)
{
// nothing
}
while (Serial.available() > 0)
{
char ch = Serial.read();
text = ch;

  • i++;*
  • delay(5);*
  • }*
  • Serial.print("sent: ");*
  • Serial.println(text);*
    vw_send((byte *)text, sizeof(text));
  • vw_wait_tx();*
  • delay(2000);*
    }
    ---------------------------------------------------------------
    Code for Receiver
    ---------------------------------------------------------------
    #include <VirtualWire.h>
    byte msg[VW_MAX_MESSAGE_LEN];
    byte msgLen = VW_MAX_MESSAGE_LEN;
    int variable;
    void setup()
    {
  • Serial.begin(9600);*
  • Serial.println("READY..........");*
  • vw_setup(2000);*
  • vw_set_rx_pin(0);*
  • vw_rx_start();*
    }
    void loop()
    {
  • if (vw_get_message(msg, &msgLen))*
  • {*
  • Serial.print("got: ");*
  • for (int i = 0; i < msgLen; i++)*
  • {*
    _ Serial.write(msg*);_
    _
    }_
    _
    Serial.println();_
    _
    }_
    _
    }_
    _
    -------------------------------------------------------------------*_
    Photo of the module:
    http://img.dxcdn.com/productimages/sku_220194_2.jpg

I think I had same kind of radios. Mine had very short range. A few meters at best. I can't recommend them for anything else than opening a carage door. I had other difficulties too.

If the data flows, you might test lower speeds. I found some old code which may belong to this system. But the TX and RX have different speeds. I remember that I needed delays after every byte? to get something through the radios. So, buy better tx and rx, these are nothing but trouble even if you get them working.

int ledPin = 3;
int tx_on;
int serout,lask;
void setup() {
  // put your setup code here, to run once:
pinMode(ledPin, OUTPUT);
pinMode(tx_on, OUTPUT);
 digitalWrite(tx_on, LOW);   // sets the tx on
 Serial.begin(2400);
 serout=0;
}

void loop() {
  // put your main code here, to run repeatedly:
 digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(500);  
  if (lask>8)
  {
    lask=0;
  }
  else
  {
    lask++;
  }
  serout=lask;
  serout=serout & B00001111;
  //serout=serout | B00010000;//data on 1jotain
  
  //Serial.write(0x06) ;
  Serial.write(serout) ;
  delay(10); 
 // Serial.write(serout) ;
  delay(10);
 // Serial.write(serout) ;
}
int ledPin = 3;
int ld2=4;
int ld3=9;
int cportti;
int serin,laskuri, eka, toka,kolmas;
void setup() {
  // put your setup code here, to run once:
pinMode(ledPin, OUTPUT);
pinMode(ld2,OUTPUT);
pinMode(ld3,OUTPUT);
digitalWrite(ld2, LOW);
digitalWrite(ld3, LOW);
//pinMode(tx_on, OUTPUT);
//DDRC = DDRC | B00111111;//6=ld1, 5=bi
cportti=B00010000;
PORTC=cportti;
// digitalWrite(tx_on, LOW);   // sets the tx on
cportti=cportti & B11000000;
PORTC=cportti;
digitalWrite(ld2, HIGH);
digitalWrite(ld3, HIGH);
digitalWrite(ld2, LOW);
digitalWrite(ld3, LOW);
cportti=cportti & B11100000;
PORTC=cportti;
cportti=cportti & B11000000;
PORTC=cportti;
 Serial.begin(4800);
}

void loop() {
  // put your main code here, to run repeatedly:
   // delay(200);               // waits for a second
//  digitalWrite(ledPin, LOW);    // sets the LED off
 
 if (Serial.available() > 0) {
                // read the incoming byte:
      //  digitalWrite(ledPin, LOW); 
      digitalWrite(ledPin, LOW);
                serin = Serial.read();
        
      //  digitalWrite(ledPin, HIGH); 
        serin=serin & B00001111;
        cportti=serin;
        PORTC=cportti;
        digitalWrite(ld2, HIGH);
        digitalWrite(ld2, LOW);
        //digitalWrite(ledPin, LOW);
        // delay(10);
         cportti=0x00;
         PORTC=cportti;
         digitalWrite(ld3, LOW);
         digitalWrite(ld3, HIGH);
         digitalWrite(ld3, LOW);
         cportti=cportti & B11001111;
         PORTC=cportti;
         cportti=cportti | B00100000;
         PORTC=cportti;
         cportti=cportti & B11001111;
         PORTC=cportti;
 digitalWrite(ledPin, HIGH);
 // digitalWrite(ledPin, LOW);    // sets the LED off
    
//   digitalWrite(ledPin, HIGH);   // sets the LED on
  // delay(12);
                // say what you got:
               // Serial.print("I received: ");
             //   Serial.println(serin);
        }

Please edit your post to add code tags (if you have questions, read the "How to use this forum" post).

This won't work, because "text" is an array. You can read about C-strings here, among other places.

   char ch = Serial.read();
    text = ch;

The following code always sends 20 bytes, mostly of garbage. Send a C-string and use strlen() to determine its length.

 Serial.println(text);
  vw_send((byte *)text, sizeof(text));

About my code. I had two different speeds that is baudrates, because I made those boards myself and run out off correct crystals. When crystal is twice the correct frequency, baudrate or speed must be half.

Edit: My receiver code controls a plain LCD display with a 4543 chip. That is why the strange extra signals.

Hi jremington,
I'm happy that you have answered on my post.
I have changed my code just like what you said, but it couldn't work.
The real problem is that the receiver won't receive the message and the Arduino Nano can't decoding it.
Do you (or other people) have another solution for this problem?
Thanks

PS: I'm building a small drone using this module so I'll be very happy if you have (an) idea(s). :slight_smile:

Post the new code, using code tags.