433 mhz rf modules not working as expected

Hello, I am currently developing a maglev train location tracking system utilizing IR sensors, LEDs, and LCDs for monitoring a single station. These components are connected to an Arduino Uno. My objective is to replicate the setup on a second station, using an Arduino Nano, and to enable communication between the two stations through 433 MHz transmitter and receiver modules.

During the prototype phase, the communication between the transmitter and receiver worked as expected. However, in the final phase of the project, this functionality ceased. The code on the transmitter side indicates that data is being transmitted, but when running a separate sketch on the Nano, there is no indication that the receiver module is successfully receiving any data.

here is the transmitter code:

#include <LiquidCrystal_I2C.h>
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile

// LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2);

// RF setup
RH_ASK driver;

// IR sensor pins
const int pinIRd1 = 0;
int IRvalueD1 = 0;
const int pinIRd2 = 7;
int IRvalueD2 = 0;
const int pinIRd3 = 2;
int IRvalueD3 = 0;
const int pinIRd4 = 3;
int IRvalueD4 = 0;
const int pinIRd5 = 4;
int IRvalueD5 = 0;
const int pinIRd6 = 5;
int IRvalueD6 = 0;
const int pinIRd7 = 6;
int IRvalueD7 = 0;

// LED setup
const int pinLED = 13;

void setup() {
  // Initialize LCD
  lcd.init();
  lcd.backlight();
  lcd.setCursor(3, 0);
  lcd.print("Hello World!");
  lcd.setCursor(2, 1);
  lcd.print("Laksh Smart");

  // Initialize RF module
  Serial.begin(9600);
  if (!driver.init()) {
    Serial.println("init failed");
  }

  // Setup IR sensor pins
  pinMode(pinIRd1, INPUT);
  pinMode(pinIRd2, INPUT);
  pinMode(pinIRd3, INPUT);
  pinMode(pinIRd4, INPUT);
  pinMode(pinIRd5, INPUT);
  pinMode(pinIRd6, INPUT);
  pinMode(pinIRd7, INPUT);
  pinMode(pinLED, OUTPUT);
}

void loop() {
  // Read IR sensor values first
  IRvalueD1 = digitalRead(pinIRd1);
  IRvalueD2 = digitalRead(pinIRd2);
  IRvalueD3 = digitalRead(pinIRd3);
  IRvalueD4 = digitalRead(pinIRd4);
  IRvalueD5 = digitalRead(pinIRd5);
  IRvalueD6 = digitalRead(pinIRd6);
  IRvalueD7 = digitalRead(pinIRd7);

  // Check each IR sensor and update the LCD, send messages, and handle LEDs
  if (IRvalueD1 == LOW) {
    const char *msg1 = "0";
    driver.send((uint8_t *)msg1, strlen(msg1));
    driver.waitPacketSent();
    Serial.println("Message Sent: 0");
    digitalWrite(LED_BUILTIN, HIGH);
    digitalWrite(pinLED, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Mile:");
    lcd.setCursor(0, 1);
    lcd.print("6");
  } else if (IRvalueD2 == LOW) {
    const char *msg2 = "1";
    driver.send((uint8_t *)msg2, strlen(msg2));
    driver.waitPacketSent();
    Serial.println("Message Sent: 1");
    digitalWrite(LED_BUILTIN, HIGH);
    digitalWrite(pinLED, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Mile:");
    lcd.setCursor(0, 1);
    lcd.print("5");
  } else if (IRvalueD3 == LOW) {
    const char *msg3 = "2";
    driver.send((uint8_t *)msg3, strlen(msg3));
    driver.waitPacketSent();
    Serial.println("Message Sent: 2");
    digitalWrite(LED_BUILTIN, HIGH);
    digitalWrite(pinLED, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Mile:");
    lcd.setCursor(0, 1);
    lcd.print("4");
  } else if (IRvalueD4 == LOW) {
    const char *msg4 = "3";
    driver.send((uint8_t *)msg4, strlen(msg4));
    driver.waitPacketSent();
    Serial.println("Message Sent: 3");
    digitalWrite(LED_BUILTIN, HIGH);
    digitalWrite(pinLED, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Mile:");
    lcd.setCursor(0, 1);
    lcd.print("3");
  } else if (IRvalueD5 == LOW) {
    const char *msg5 = "4";
    driver.send((uint8_t *)msg5, strlen(msg5));
    driver.waitPacketSent();
    Serial.println("Message Sent: 4");
    digitalWrite(LED_BUILTIN, HIGH);
    digitalWrite(pinLED, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Mile:");
    lcd.setCursor(0, 1);
    lcd.print("2");
  } else if (IRvalueD6 == LOW) {
    const char *msg6 = "5";
    driver.send((uint8_t *)msg6, strlen(msg6));
    driver.waitPacketSent();
    Serial.println("Message Sent: 5");
    digitalWrite(LED_BUILTIN, HIGH);
    digitalWrite(pinLED, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Mile:");
    lcd.setCursor(0, 1);
    lcd.print("1");
  } else if (IRvalueD7 == LOW) {
    const char *msg7 = "6";
    driver.send((uint8_t *)msg7, strlen(msg7));
    driver.waitPacketSent();
    Serial.println("Message Sent: 6");
    digitalWrite(LED_BUILTIN, HIGH);
    digitalWrite(pinLED, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Mile:");
    lcd.setCursor(0, 1);
    lcd.print("0");
  } 

  delay(500); // Delay to prevent rapid cycling of sensor reads
}

and Here is the reciver code:

#include <RH_ASK.h> // RadioHead Receiver Library (crucial)
#include <SPI.h> // Not actually used but needed to compile
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);
RH_ASK driver; // Create a driver to process the message being received

const int LED_PIN = 6;        // Pin connected to the LED
int EXPECTED_CODE; // Replace with the actual code to match

void setup()
{
    pinMode(LED_PIN, OUTPUT);   // Set the LED pin as output
    digitalWrite(LED_PIN, LOW); // Ensure the LED is off initially

    if (!driver.init()) {
         Serial.println("Initialization Process Failed.");
    } else {
         Serial.println("Initialization Process Success.");
    }
  Serial.println("BETATEST1");
    lcd.init();
    lcd.backlight();

}
//int i = 0; (deprecated)
void loop()
{
    lcd.setCursor(1,0);
    lcd.print("Mile:");

    lcd.setCursor(1,1);
    lcd.print("6");

    //Serial.println(i); (deprecated)
    uint8_t buf[2]; // Sets a buffer length limit to help read the message for LED (Eventually Train)
    uint8_t buflen = sizeof(buf); // Monitors the length of the variable buf (See above ^)
    if (driver.recv(buf, &buflen)) // Non-blocking
    {
        EXPECTED_CODE = atoi((char*)buf); // Converts the Integer to a String to Process for the println
        Serial.println("Code: ");
        //Serial.println((char*)buf); // Print the received message (deprecated)
        Serial.println(EXPECTED_CODE); // Print the received message
        
        // Check if the received message matches the expected code
           switch (EXPECTED_CODE) {
                //Stop Relay 2 and Reverse to Relay 1 After 15 secs and Start
            case 0:
                 Serial.println("Turning LED on!");
                 digitalWrite(LED_PIN, HIGH); // Turn LED on
                break;
            case 1: 
                 Serial.println("Turning LED off!");
                 digitalWrite(LED_PIN, LOW);  // Turn LED off
                break;
            case 2: 
                 Serial.println("Turning LED on!");
                 digitalWrite(LED_PIN, HIGH); // Turn LED on
                break;
            case 3:
                 Serial.println("Turning LED off!");
                 digitalWrite(LED_PIN, LOW);  // Turn LED off
                break;
            case 4:
                 Serial.println("Turning LED on!");
                 digitalWrite(LED_PIN, HIGH); // Turn LED on
                break;
            case 5:
                 Serial.println("Turning LED off!");
                 digitalWrite(LED_PIN, LOW);  // Turn LED off
                break;
            case 6:
                 Serial.println("Turning LED off!");
                 digitalWrite(LED_PIN, LOW);  // Turn LED off
                 
                break;
             
            default: // In case of any other code (not a case) being received by transmitter
                Serial.println("Unknown code received!");
                Serial.println(EXPECTED_CODE);
                break;
        }
    }
    //i++; (deprecated)
    //delay(5000); (deprecated)
}

Please note that I still need to integrate the LCD and LEDs into the receiver code; however, this serves as the baseline I am currently working with.

Any assistance with this issue would be greatly appreciated, as it has been a significant source of stress and frustration. The challenge has caused considerable setbacks in my project, and despite my best efforts, I am struggling to identify the root cause of the communication failure. Any guidance or insights from experienced individuals would mean a great deal to me at this stage.

can you give details of the 433MHz modules, e.g. links to a web page
also details of how you connected the modules to the UNOs?
what is the distance between the stations?

I purchased the modules from the following Amazon link: HiLetgo 5 Sets 433M Transmitter + Receiver Kit High Frequency Super Regenerative Transceiver Module for Burglar Alarm : Amazon.ca: Electronics

For the transmitter, I have connected the pins as follows: the leftmost pin is connected to digital pin 12, the middle pin is connected to 5V, and the rightmost pin is connected to ground, with the front-facing view of the transmitter considered.

Similarly, for the receiver module, the leftmost pin is connected to 5V, the rightmost pin is connected to ground, and the pin immediately to the left of the ground pin is connected to digital pin 11 on the Arduino Nano. The front-facing view of the receiver module is also considered as the point of orientation.

Can you list the differences between two phases.
Also your receiver is... ...not the best available.
Did you solder some antenna to them?

During the prototype phase, I focused on testing the equipment and verifying the functionality of the modules. The setup worked as expected: when the IR sensor detected the train, a transmission was successfully sent between the modules. I was able to observe the data transmission clearly, as I had connected the receiver module to a separate system for monitoring purposes.

In the final phase of the project, I assembled and wired all the components together. However, when I tested the system to confirm that the transmitter and receiver were still able to communicate, I encountered an issue: the transmission no longer worked. Since that point, progress has been stalled, and I’ve been unable to identify the cause of the failure.

Additionally, I did not solder an antenna onto the receiver, as it was previously able to receive signals from the required distance without one.

I asked that to get better idea if the problem is on the hardware or code changes...

you have not answered the question as to the distance between the stations?
when you are now testing the devices how far apart are they?
not attaching antennas may have damaged the radios

Hello godzillatiger

Welcome to the world's best Arduino forum ever :smile:

I have been following the topic of using this type of wireless module and the associated software functions for some time now.

For wireless projects, I recommend using the HC12 module.

What are the advantages:

  1. no external functions from a library are needed.
  2. the development of a communication protocol is in your hands
  3. the necessary development steps can be programmed and tested without using the wireless module
  4. the radio module can be easily configured for the project requirements
  5. both transmitter and receiver are contained in one radio module.

hth

Have a nice day and enjoy coding in C++.

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