Data not transmitting between RF Modules

Our project consists of an MQ3 Gas sensor with 2 UNOs for transmitting data wirelessly with RF Modules.
For some odd reason, the boards seem to be unable to communicate with each other. Are we doing something wrong?

Sensor: MQ-3 Gas sensor
Board(s): Arduino UNO
RF Modules: FS1000A Transmitter and Receiver, 315 - 433 MHz
Also Included: Piezoelectric Buzzer, 1602A 16x2 LCD and 10K Ohm Potentiometer
(See codes below)

For transmitter:

#include <RH_ASK.h>  // Include RadioHead Amplitude Shift Keying Library
#include <SPI.h>     // Include dependant SPI Library
#include <MQUnifiedsensor.h>
#include <LiquidCrystal.h>


#define analog_pin A0
#define notDrunk 10  // Define max value that we consider not Drunk
#define Drunk 44     // Define min value that we consider drunk
// const int buzzer = 9;       // buzzer to arduino pin 9
// const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
// LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// const int ledPin = 9;
char *data;
char dataStr[10];


//properties
uint8_t x = 0;       //v ariable to be transmitted to slave board <== sensor_value
float sensor_value;  // variable to store sensor value

// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

void setup() {
  // Initialize ASK Object
  rf_driver.init();
  // Setup Serial Monitor
  Serial.begin(115200);
}

void loop() {

  float sensor_value = analogRead(analog_pin);
  if (sensor_value > 254) { sensor_value = 255; };
  sensor_value = (sensor_value / Drunk) * 100;
  x = sensor_value;
  char *msg = "Hello World";
  if (x < 22.07) {
    *msg = "Sober";
  } else if (x < 100) {
    *msg = "Legal";
  } else {
    *msg = "Drunk";
  };
  rf_driver.send((uint8_t *)msg, strlen(msg));
  rf_driver.waitPacketSent();
  {
    // Message Transmitted
    Serial.println("Message Transmitted: ");
    delay(1000);
  }
}

For Receiver:

#include <RH_ASK.h>  // Include RadioHead Amplitude Shift Keying Library
#include <SPI.h>     // Include dependant SPI Library

#include <LiquidCrystal.h>

const int buzzer = 9;  //buzzer to arduino pin 9
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

void setup() {
  pinMode(buzzer, OUTPUT);  // Set buzzer - pin 9 as an output
  // pinMode(ledPin, OUTPUT)
  Serial.begin(115200); //Init serial port
  Serial.println("MQ3 warming up!");
  lcd.begin(16, 2);
  // ;
  lcd.println("MQ3 warming up!");
  delay(500);
  lcd.clear();
  lcd.print("Waiting for Transmitter");
  delay(500);
  // Initialize ASK Object
  rf_driver.init();
  // Setup Serial Monitor
  Serial.begin(115200);
  // Serial.clear();
  Serial.print("Waiting for Transmitter");
  
}

void loop() {
  // Set buffer to size of expected message
  uint8_t buf[10];
  uint8_t buflen = sizeof(buf);
  // Check if received packet is correct size
   if (rf_driver.recv(buf, &buflen)){
     lcd.clear();
      // Message received with valid che-cksum
      Serial.print("Message Received: ");
      Serial.println((char*)buf);
      lcd.println((char*)buf);
  }
}

Did you confirm that the RF_ASK examples run properly on your setup?

Always check hardware with very simple "example" sketches before adding all the pieces to a project.

I am sure there are better examples, but this one was an easy find:

Arduino - 433mhz Wireless Transmitter & Receiver SWITCH Example FS1000A - Instructables

By the way: this is not valid C++ and probably won't work as you expect. Turn on ALL compiler warnings to see the error messages:

  char *msg = "Hello World";
  if (x < 22.07) {
    *msg = "Sober";
  } else if (x < 100) {
    *msg = "Legal";
  } else {
    *msg = "Drunk";
  };

This will work:

char msg[]="Hello World";
strcpy(msg,"Goodbye");

I just tested them. with the exact same pins. didnt work
Also, does FS1000A really have a built-in antenna?

No, you need to solder about 17 cm (433 MHz) or 23 cm (315 MHz) of straight wire to the ANT terminal, on both the transmitter and receiver. Don't expect the setup to work without those.

Please post a clear, focused picture of your setup.

I was unable to get a picture, as I am not the one holding the physical components
But I have a proteus schematic that shows the wirings
MQ3 Wireless with Display.PDF (33.8 KB)

I also changed up the wirings and updated the code

For the Transmitter:

#include <RH_ASK.h>
#include <SPI.h>
#include <MQUnifiedsensor.h>
#define         Board                   ("Arduino UNO")
#define         Pin                     (A0)  //Analog input 3 of your arduino
/***********************Software Related Macros************************************/
#define         Type                    ("MQ-3") //MQ3
#define         Voltage_Resolution      (5)
#define         ADC_Bit_Resolution      (10) // For arduino UNO/MEGA/NANO
#define         RatioMQ3CleanAir        (60) //RS / R0 = 60 ppm
/*****************************Globals***********************************************/
//Declare Sensor
MQUnifiedsensor MQ3(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
 
const uint8_t analogPin = A0;
RH_ASK driver;
const int txPin = 12;
void setup()
{
driver.init();
driver.setModeTx();
MQ3.init();
Serial.begin(115200);
pinMode(analogPin, INPUT);
analogRead(0);
pinMode(txPin, OUTPUT);
}
 
void loop()
{
   uint8_t data = analogRead(0);
  //  uint16_t data = getsomevalue();
  driver.send((uint8_t *)&data, sizeof(data));
   if (driver.send((uint8_t*)&data, sizeof(data)))
 {
//    Serial.print("init failed.");
//  }
//    else
//  {
    driver.waitPacketSent();
    Serial.println("Message Transmitted");
    delay(200);
 }
}
 


For the receiver:

#include <RH_ASK.h>
#include <SPI.h>
#include <LiquidCrystal.h>
#define notDrunk 10  // Define max value that we consider not Drunk
#define Drunk 44     // Define min value that we consider drunk
const int rs = 12, en = 10, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(12, 10, 5, 4, 3, 2);
const int buzzer = 9;  //buzzer to arduino pin 9
 
RH_ASK driver;
const int rxPin = 11;
void setup()
{
  driver.init();
  Serial.begin(115200);
  lcd.begin(16, 2);
  // if (!driver.init())
  // {
  //   lcd.println("init failed!");
  //   lcd.clear();
  //   lcd.noDisplay();
  // }
  // driver.setModeRx();
  pinMode(buzzer, OUTPUT);  // Set buzzer - pin 9 as an output
  pinMode(rxPin, INPUT);
  uint8_t data;
  uint8_t datalen = sizeof(data);
  driver.recv((uint8_t*)&data, &datalen);
}
 
void loop()
{
  uint8_t data;
  uint8_t datalen = sizeof(data);
  driver.recv((uint8_t*)&data, &datalen);
 
  if (!driver.recv((uint8_t*)&data, &datalen))
  {
    lcd.println("recv failed!");
    delay(1500);
    lcd.clear();
    lcd.noDisplay();
  }
 
  else// if (driver.recv((uint8_t*)&data, &datalen))
  {
    lcd.println("recv success!");
    delay(1500);
    lcd.clear();
    lcd.setCursor(0, 0);
    Serial.println(data);
    lcd.println(data);
  }
 
  if (data < notDrunk) {
    lcd.setCursor(0, 2);
    Serial.println("Sober");
    lcd.println("Sober");
  }
  else if (data >= notDrunk && data < Drunk)
  {
    lcd.setCursor(0, 2);
    Serial.println("Legal");
    lcd.println("Legal");
  }
  else if (data >= Drunk)
  {
    lcd.setCursor(0, 2);
    Serial.println("DRUNK");
    lcd.println("DRUNK");
    // lcd.blink();
    delay(1500);
  }
}


I then tested the new code and wirings on the simulator
But it fails to transmit the data between the boards on the simulation
This time it seems like the code does have issues

I am testing the code with the Proteus simulation software to simulate data reading with a sensor
I don't expect accurate results, but it doesn't seem to work
In the code, it will return a fail message if the data fails to send between the two boards
But i don't think i made any mistakes in the wiring.

Board Type: Arduino UNO R3
Sensor: MQ-3 Gas Sensor
Also Includes: RF modules and Display with POT.
MQ3 Wireless with Display.PDF (33.8 KB)

(See the code below)

For Transmitter board:

#include <RH_ASK.h>
#include <SPI.h>
#include <MQUnifiedsensor.h>
#define         Board                   ("Arduino UNO")
#define         Pin                     (A0)  //Analog input 3 of your arduino
/***********************Software Related Macros************************************/
#define         Type                    ("MQ-3") //MQ3
#define         Voltage_Resolution      (5)
#define         ADC_Bit_Resolution      (10) // For arduino UNO/MEGA/NANO
#define         RatioMQ3CleanAir        (60) //RS / R0 = 60 ppm
/*****************************Globals***********************************************/
//Declare Sensor
MQUnifiedsensor MQ3(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);
 
const uint8_t analogPin = A0;
RH_ASK driver;
const int txPin = 12;
void setup()
{
driver.init();
driver.setModeTx();
MQ3.init();
Serial.begin(115200);
pinMode(analogPin, INPUT);
analogRead(0);
pinMode(txPin, OUTPUT);
}
 
void loop()
{
   uint8_t data = analogRead(0);
  //  uint16_t data = getsomevalue();
  driver.send((uint8_t *)&data, sizeof(data));
   if (driver.send((uint8_t*)&data, sizeof(data)))
 {
//    Serial.print("init failed.");
//  }
//    else
//  {
    driver.waitPacketSent();
    Serial.println("Message Transmitted");
    delay(200);
 }
}
 

For the Receiver board:

#include <RH_ASK.h>
#include <SPI.h>
#include <LiquidCrystal.h>
#define notDrunk 10  // Define max value that we consider not Drunk
#define Drunk 44     // Define min value that we consider drunk
const int rs = 12, en = 10, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(12, 10, 5, 4, 3, 2);
const int buzzer = 9;  //buzzer to arduino pin 9
 
RH_ASK driver;
const int rxPin = 11;
void setup()
{
  driver.init();
  Serial.begin(115200);
  lcd.begin(16, 2);
  // if (!driver.init())
  // {
  //   lcd.println("init failed!");
  //   lcd.clear();
  //   lcd.noDisplay();
  // }
  // driver.setModeRx();
  pinMode(buzzer, OUTPUT);  // Set buzzer - pin 9 as an output
  pinMode(rxPin, INPUT);
  uint8_t data;
  uint8_t datalen = sizeof(data);
  driver.recv((uint8_t*)&data, &datalen);
}
 
void loop()
{
  uint8_t data;
  uint8_t datalen = sizeof(data);
  driver.recv((uint8_t*)&data, &datalen);
 
  if (!driver.recv((uint8_t*)&data, &datalen))
  {
    lcd.println("recv failed!");
    delay(1500);
    lcd.clear();
    lcd.noDisplay();
  }
 
  else// if (driver.recv((uint8_t*)&data, &datalen))
  {
    lcd.println("recv success!");
    delay(1500);
    lcd.clear();
    lcd.setCursor(0, 0);
    Serial.println(data);
    lcd.println(data);
  }
 
  if (data < notDrunk) {
    lcd.setCursor(0, 2);
    Serial.println("Sober");
    lcd.println("Sober");
  }
  else if (data >= notDrunk && data < Drunk)
  {
    lcd.setCursor(0, 2);
    Serial.println("Legal");
    lcd.println("Legal");
  }
  else if (data >= Drunk)
  {
    lcd.setCursor(0, 2);
    Serial.println("DRUNK");
    lcd.println("DRUNK");
    // lcd.blink();
    delay(1500);
  }
}


What could be the cause of the failiure?

How can a simulation determine whether an RF signal is sent or received?

In the real world, set up a pair of Arduinos with radio modules, and test it using the simple examples that come with the RadioHead library. When that is working to your satisfaction, add your sensor code.

Your two topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

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