RcSwitch: available() does always return false

Hello,
I´m currently trying to connect two Arduinos using 433 MHz radio modules.
Therefore I´m using the following code:

Transmitter:

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();
void setup() {
  mySwitch.enableTransmit(2);
  Serial.begin(9600);
}
void loop() {
  mySwitch.send(1234, 24); // sending  „1234“
  Serial.println("sent");
  delay(1000);  

}  

Receiver:

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() 
{
  Serial.begin(9600);
  mySwitch.enableReceive(0);  //connecting to Interrupt pin 0 (D2)
}

void loop() {
  if (mySwitch.available()) // always returns false
  {
    int value = mySwitch.getReceivedValue(); // received data stored with "value"
  
    if (value == 0) 
    {
      Serial.println("unknown code");
    } 
    
    else 
    {
      Serial.print("received: ");
      Serial.println( mySwitch.getReceivedValue() );
    }

  }
  else {   // debugging
    Serial.println("connection failed");   
    delay(2000);
  }
  mySwitch.resetAvailable(); 
}

Connected to the transmitter module is an Arduino Nano on Pin D2, the receiver is connected to an Arduino Mega 2560, also Pin D2 (= Interrupt 0).

The problem is though, that the function available() does always return false.

Any ideas why this could be?

Thanks in advance

modify this line to:

Serial.println( value);

Thanks for your answer, that might have become a problem in the future, but in this case it still doesn´t work; the program still returns "connection failed".
I thought about it as maybe being a hardware issue, I´m actually using clones ("Funduino").

Is there some way to find out whether the Arduinos do communicate with the modules correctly?

And does anyone know what exacly the function myswitch.available() does?

It tells you the number of characters waiting to be processed from the stream "myswitch". A stream can be various things like the serial monitor, a file on an SD card, or, in this case, received from the transmitter.

  if (mySwitch.available())

works because zero is interpreted as false and any other value is interpreted as true, because that's the way C code works.

If there are zero characters waiting, that could mean nothing has been received because the receiver circuit isn't working, or because nothing has been transmitted, because the transmitter circuit is not working. What you need to figure out, as you have already realised, is which is those two things it is.

The library you are using with the radio modules will probably come with some example transmitter and receive sketches. Load these up to find out.

It's rare that using clones is the reason that something doesn't work. Arduino hardware is "open source", so the cloners don't have to struggle to figure out how the original/genuine Arduino board works, they are free to copy the published schematics perfectly legally.

It can happen, of course. There was a brand of "clones" a little while ago that did not use genuine AVR chips in their Unos/Nanos. These caused a lot of problems. Instead they used chips that had been designed to replicate the operation of genuine AVR chips. AVR chips are not open source, so the replica chips, inevitably, were unable to behave 100% identically to the genuine chips.

I have at least one Funduino Nano. It uses a genuine AVR chip and has always performed perfectly.

Ok, I tried to use the example sketches, unfortunally still doesn´t work, but I found out something interesting.
I´m now using these sketches:
Transmitter:

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  mySwitch.enableTransmit(10);  // Using Pin #10
}

void loop() {
  mySwitch.send("000000000001010100010001");
  delay(1000);  
}

Receiver:

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
}

void loop() {
  //if (mySwitch.available()) {
    output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
    mySwitch.resetAvailable();
    delay(2000);
  //}
}

As you can see I simply deactivated the if (mySwitch.available()) function in the receiver code.
Now I get an output that looks like this:

Decimal: 0 (0Bit) Binary: Tri-State: PulseLength: 0 microseconds Protocol: 0
Raw data: 3308,

You see, all the data is 0 or not available, except the raw data, where I get an output that is most of the time somewhere between 3200 and 3420 .
For some reason some numbers are more likely to come as an output than others, I don´t know if that is important.

But if I deactivate the transmitter, the raw data output are completely random numers, most of the time between 100 and 10000 (but still only one number per incoming data block).

I have now idea what this does mean (except that there is some kind of communication between transmitter and receiver), can anyone make sense out of that?

Then there's probably something wrong with your hardware. Post schematics and pictures of both circuits.

Here they are:

I´ve checked every single connection.
Where current is supposed to flow through, there current is able to flow through.

That probably means that I need to get new modules, right?

And, just as a matter of interest, the phenomena I described in my last post do indicate that there is at least some communication, don´t they?

You have not soldered header pins to your Nano. Pushing wires into the holes will not make reliable connections.

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