//RECEIVER
#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#endif
RH_ASK driver(2000, 11, 12, 10, false);
String str_out;
void setup() {
#ifdef RH_HAVE_SERIAL
Serial.begin(9600); // Debugging only
#endif
if (!driver.init()) {
#ifdef RH_HAVE_SERIAL
Serial.println("init failed");
#else
;
#endif
}
}
void loop() {
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) {
Serial.println("Data received!"); // Add this line
buf[buflen] = 0;
str_out = String((char*)buf);
Serial.print("Received data: "); // Add this line
Serial.println(str_out); // Add this line
} else {
Serial.println("No data received"); // No data received
}
}
The result is that the LEDs blink in sync which I assume the data has sent and received. However the serial monitor of the receiver says "No data received", which confuses me.
Does anyone know why and how to fix it?
Remove both LEDs from your circuit, Arduino pins can't be used to supply current for LED without series resistor. And especially it can't supply current to transmitter AND LED.
Neither can receiver.
It must be a mistaken when I transfer my real-life circuit to digital diagram. My real-life tx pin actually connects to pin 12, so I have edited it.
About the LEDs, I use them to test whether the data has been sent and received. I will try providing the LEDs external sources and check the situation.
You have Vcc going into the transmitter's input, and an output pin where the TX expects power.
You can run the LED and the data off one pin, but as has been pointed out you need a series current limiting resistor for each LED. But you won't learn much from that, other than confirming that you haven't blown out an output pin along the way.
It is not clear you have not made the same kind of mistakes with the receiver.
Hope that you have not irreparably damaged your module.
Post a schematic of how you have actually hooked things up. Draw it with pencil and take a picture, that will be easiest and fastest and give us confidence that you are accurately describing the wiring.
Updated: I have removed the LED from the transmitter after re-cheking the schematic. Also, I changed the connection of the LED in the receiver into the images below since there are 2 data pins of the receiver which can work seperately.
The remaining LED still blinks after each 0.1 seconds as same as the transmitter's code. However, the serial monitor still displays "No data received".
It does not work, unfortunately. I rememeber that the modules used to work before with the same code.
Maybe I will buy a new couple from a more reliable source and rechallenge them. I just had a quick research and found out that many people also struggle with the modules as same as mine, turning out that the modules are unreliable.
Also, I want to know why cannot the LED connect to the receiver's pin. The LEDs seems good and blinks as the transmitter's code delay.
First, please confirm you have a series current limiting resistor, not just the LED.
Second, without knowing for sure, it is reasonable and safer to assume that the output of the receiver may have limited current supplying capability.
You can't even be sure of what the output circuit looks like. Just read it with an INPUT or an INPUT_PULLUP and drive the LED in sync on its own OUTPUT pin.