Hello, I am having trouble getting my 433MHz modules to communicate. I have verified my code works as intended by directly connecting pins 11/12 together and verifying my switch changes the led on both arduinos (the receiver is essentially supposed to act as a repeater for the led color of the transmitter). When I go to do it via the 433 MHz modules, it seems like the transmitter is working properly (I threw an LED in line of the tx DATAOUT to be sure, and its blinking a couple times a second). But I have yet to get the receiver to receive a single transmission in the few days I have been working on this.
Here is the code for the transmitter:
#include <RH_ASK.h>
#include <SPI.h>
const int switchPin = 2;
int error = LOW;
RH_ASK driver;
void setup() {
Serial.begin(115200);
for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500));
if (!driver.init()) {
error = HIGH;
};
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDB, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
// Turn off LEDs
digitalWrite(LEDR, HIGH);
digitalWrite(LEDG, HIGH);
digitalWrite(LEDB, HIGH);
digitalWrite(LED_BUILTIN, LOW);
Serial.println("Init Complete.");
}
void loop() {
digitalWrite(LEDR, HIGH);
digitalWrite(LEDB, HIGH);
int switchState = digitalRead(switchPin);
if (switchState == HIGH) {
digitalWrite(LEDB, LOW);
const char *msg = "ON ";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
Serial.println("Message Sent: ON ");
} else {
digitalWrite(LEDR, LOW);
const char *msg = "OFF";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
Serial.println("Message Sent: OFF");
}
delay(500);
}
And here it is for the receiver:
#include <RH_ASK.h>
#include <SPI.h>
int error = LOW;
RH_ASK driver;
void setup() {
Serial.begin(115200);
for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500));
if (!driver.init()) {
error = HIGH;
};
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDB, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LEDR, HIGH);
digitalWrite(LEDG, HIGH);
digitalWrite(LEDB, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("Receiver Init Complete.");
}
void loop() {
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) { // Check if a message is received
Serial.print("Message Received: ");
Serial.println((char*)buf);
// Message received.
if (strcmp((char*)buf, "ON ") == 0) {
digitalWrite(LEDR, HIGH);
digitalWrite(LEDG, HIGH);
digitalWrite(LEDB, LOW);
digitalWrite(LED_BUILTIN, LOW);
} else if (strcmp((char*)buf, "OFF") == 0) {
digitalWrite(LEDR, LOW);
digitalWrite(LEDG, HIGH);
digitalWrite(LEDB, HIGH);
digitalWrite(LED_BUILTIN, LOW);
}
}
}
I am using two brand new Arduino R4 Nano's, manual here: https://docs.arduino.cc/tutorials/nano-r4/user-manual/
Here is my setup:
Transmitter:
Receiver:
RF Modules:
The RF modules have a 17.3cm 14 gauge solid core wire soldered on. I have tried the setup with and without the antennae, as well as with the little coil antennaes the came with the modules. Not a single one has worked. I have tried putting them close together and far apart. I have tried now two sets of 433MHz modules from different suppliers. I feel like I have some sort of hardware issue, but I am pretty new at this and can't quite figure out what I'm doing wrong. Any help would be appreciated. Thank you.





