433 MHz RF Module message division into several parts.

Hey,

I’m new to the group and now a few months crafting with Arduino and no previous experience in coding is not, so to speak, then started from zero.

I have under construction temperature monitoring in the basement. The hardware is currently a transmitter from the Nano with 4 DallasTemperature DS18B20 sensors and the transmitter is a 433 MHz RF Module and the receiver is Uno.

I need help when my own ideas and skills run out and there doesn’t seem to be any help on the internet.

The device works well with two sensors and the temperatures are displayed and the serial monitor correctly,
but the addition of temperature sensors causes trouble when I don’t get the 433 MHz RF message divided into more than two parts?

Now the code is next and the message seems to be coming in the right length and works with two sensors ok but with more it doesn’t have enough lines.

// Divide the string into two values
for (int i = 0; i <str_out.length (); i ++) {
if (str_out.substring (i, i + 1) == “,”) {
str_temp1 = str_out.substring (0, i);
str_temp2 = str_out.substring (i + 1);
break;

There is a need to divide the received message into four lines when there are four temperature sensors.

What needs to be added / changed in that code?

Please edit your post to include ALL the code, using code tags, as described in "How to use the forum".

Avoid using Strings with the Arduino Uno. They cause memory problems and program crashes.

mreid_fi:
Hey,

I’m new to the group and now a few months crafting with Arduino and no previous experience in coding is not, so to speak, then started from zero.

I have under construction temperature monitoring in the basement. The hardware is currently a transmitter from the Nano with 4 DallasTemperature DS18B20 sensors and the transmitter is a 433 MHz RF Module and the receiver is Uno.

I need help when my own ideas and skills run out and there doesn’t seem to be any help on the internet.

The device works well with two sensors and the temperatures are displayed and the serial monitor correctly,
but the addition of temperature sensors causes trouble when I don’t get the 433 MHz RF message divided into more than two parts?

Now the code is next and the message seems to be coming in the right length and works with two sensors ok but with more it doesn’t have enough lines.

// Haetaan käytettävät kirjastot

#include <RH_ASK.h>
   #include <LiquidCrystal.h>

//Määritetään LCD-näytön tarvitsemat pinnit
   const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
   LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

//Määritetään merkkivalojen pinnit
     int pun = 8;
     int pun1 = 9;
     int vihr = 13;
 
  // Määritetään lähtevä stirng  
     String str_temp1;
     String str_temp2;
     String str_temp3;
     String str_temp4;      
     String str_out;

// Määritetään radion nopeus ja pinni
     RH_ASK rf_driver(2000, 7);

void setup() {

// Alustetaan radiovastaanotin
       rf_driver.init();
    // Asennetaan Serial Monitor
       Serial.begin(9600);
    // Alustetaan LCD ja määritetään sarakkeet ja rivit
       lcd.begin(20, 4);    // Alustetaan Serial Monitor
       Serial.begin(9600);
 
   //Alustetaan ledien pinnit
       pinMode(pun, OUTPUT);
       pinMode(pun1, OUTPUT);
       pinMode(vihr, OUTPUT);
  // Varmistetaan, että ledit ovat sammuksissa
       digitalWrite (pun, LOW);
       digitalWrite (pun1, LOW);
       digitalWrite (vihr, LOW);

}

void loop() {
   //Stabiloidaan lämpötila-anturi pienellä tauolla
       delay (2000);
   
  // Asennetaan bufferi ja koko viestille
      uint8_t buf[23];
      uint8_t buflen = sizeof(buf);
  // Tarkastetaan onko vastaanotettu paketti oikean kokoinen
       if (rf_driver.recv(buf, &buflen))
   
{
  // Viesti vastaanotettu kelvollisella tarkistussummalla
  // Hae arvoja merkkijonosta
  // Muuntaa vastaanotetut tiedot merkkijonoksi
       str_out = String((char*)buf);
     
  // Jaa merkkijono kahteen arvoon
       for (int i = 0; i < str_out.length(); i++) {
       if (str_out.substring(i, i+1) == “,”) {
       str_temp1 = str_out.substring(0,i);
       str_temp2 = str_out.substring(i+1);
       break;
   
}
}
  // Tulostetaan lämpötila Serial Monitoriin
       Serial.print("1 on ");
       Serial.print(str_temp1);
       Serial.println(“C”);
       Serial.print("2 on ");
       Serial.print(str_temp2);
       Serial.println(“C”);
       Serial.print("3 on ");
       Serial.print(str_temp3);
       Serial.println(“C”);
       Serial.print("4 on ");
       Serial.print(str_temp4);
       Serial.println(“C”);

// Asetetaan kursori näytölle column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
       lcd.setCursor(0, 0);
       lcd.print("Ulkona ");
       lcd.print(str_temp1);
       lcd.print(“C”);
       lcd.setCursor(0, 1);
       lcd.print("Sisalla ");
       lcd.print(str_temp2);
       lcd.print(“C”);      
       lcd.setCursor(0, 2);
       lcd.print("Ylakerta ");
       lcd.print(str_temp3);
       lcd.print(“C”);
       lcd.setCursor(0, 3);
       lcd.print(“ulkoseina”);
       lcd.print(str_temp4);
       lcd.print(“C”);      
       
       delay (1000); //Viive 1 sekuntti (1000 millisekunttia)
}
{
  //Asetetaan ledien syttymis- ja sammumislämpötilat
      if (str_temp2>= “25”) digitalWrite (vihr, HIGH);
      if (str_temp2<= “23”) digitalWrite (vihr, LOW);
      if (str_temp2<= “24”) digitalWrite (pun1, HIGH);
      if (str_temp2>= “25”) digitalWrite (pun1, LOW);
      if (str_temp2<= “22”) digitalWrite (pun, HIGH);
      if (str_temp2>= “23”) digitalWrite (pun, LOW);
}
}





There is a need to divide the received message into four lines when there are four temperature sensors.

What needs to be added / changed in that code?

Put the 4 data items into one packet. Here is a page that shows how.

Here is examples from the aforementioned page using a struct to hold the four temperatures. Read the cautions on the page that apply to sending and receiving data in a struct. Tested using my 433MHz transmitter and receiver on 2 Unos.

Sender:

// Include RadioHead Amplitude Shift Keying Library
// data to Uno pin 12
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>

// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

typedef struct
{
   float temp1;
   float temp2;
   float temp3;
   float temp4;
} Temps;

 Temps temps;

void setup()
{
   // Initialize ASK Object
   rf_driver.init();
}

void loop()
{
   temps.temp1 = 32.9;
   temps.temp2 = 54.5;
   temps.temp3 = 67.8;
   temps.temp4 = 17.2;
   //const char *msg = "Hello Charlie";
   rf_driver.send((uint8_t*)&temps, sizeof(temps));
   rf_driver.waitPacketSent();
   delay(1000);
}

Receiver:

// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library 
// data to pi8n 11
#include <SPI.h> 
 
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

typedef struct
{
   float temp1;
   float temp2;
   float temp3;
   float temp4;
} Temps;

Temps temps;
 
void setup()
{
    // Initialize ASK Object
    rf_driver.init();
    // Setup Serial Monitor
    Serial.begin(9600);
}
 
void loop()
{
    uint8_t buflen = sizeof(temps);
    // Check if received packet is correct size
    if (rf_driver.recv((uint8_t*)&temps, &buflen) && buflen == sizeof(temps))
    {      
      // Message received with valid checksum
      Serial.println("Message Received: ");
      Serial.print("temp 1 = ");
      Serial.println(temps.temp1);  
      Serial.print("temp 2 = ");
      Serial.println(temps.temp2);
      Serial.print("temp 3 = ");
      Serial.println(temps.temp3); 
      Serial.print("temp 4 = ");
      Serial.println(temps.temp4);
      Serial.println();  
    }
}

No Strings attached.:slight_smile:

This is a problem. We strongly recommend to use C-strings (zero terminated character arrays) instead.

      String str_temp1;
      String str_temp2;
      String str_temp3;
      String str_temp4;      
      String str_out;

Thanks for the answers. I will use these instructions to try to solve that problem.

Hey,

Thank you for your previous advice and now I’ve got that data over a distance and to print serial monitor and display correctly.

A new problem is translating data into chapter format.

I get the following error message “invalid operands of types’ float ’and‘ const char [3] ‘to binary’ operator <= ’”.

How do I get that change done? I have tried to "float and int 'sentences have changed, but I have not succeeded.

Here is the current receiver code:

 // Haetaan käytettävät kirjastot
    #include <RH_ASK.h>
    // Include dependant SPI Library 
    #include <SPI.h> 
    #include <LiquidCrystal.h>

    //Määritetään LCD-näytön tarvitsemat pinnit
    const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
    LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

    //Määritetään merkkivalojen pinnit
      int pun = 8;
      int pun1 = 9; 
      int vihr = 13;

typedef struct
{
   float temp0;
   float temp1;
   float temp2;
   float temp3;
   
} Temps;

Temps temps;
      
   // Määritetään radion nopeus ja pinni
      RH_ASK rf_driver(2000, 7);
 

void setup() {

      delay (2000);
     // Alustetaan radiovastaanotin
        rf_driver.init();
     // Asennetaan Serial Monitor
        Serial.begin(9600);
     // Alustetaan LCD ja määritetään sarakkeet ja rivit
        lcd.begin(20, 4);    // Alustetaan LCD Monitor
       
  
    //Alustetaan ledien pinnit
        pinMode(pun, OUTPUT);
        pinMode(pun1, OUTPUT);
        pinMode(vihr, OUTPUT);
   // Varmistetaan, että ledit ovat sammuksissa
        digitalWrite (pun, LOW);
        digitalWrite (pun1, LOW);
        digitalWrite (vihr, LOW);
  
}

void loop() 
{
    {
        uint8_t buflen = sizeof(temps);
    // Tarkastetaan paketin koko
    if (rf_driver.recv((uint8_t*)&temps, &buflen) && buflen == sizeof(temps))
    {      
      // Viesti vastaanotettu kelvollisella tarkistussummalla
      Serial.println("Vastaanotetut lämpötilat: ");
      Serial.print("temp 1 = ");
      Serial.print(temps.temp0);
      Serial.println("C");
      Serial.print("temp 2 = ");
      Serial.print(temps.temp1);
      Serial.println("C");  
      Serial.print("temp 3 = ");
      Serial.print(temps.temp2);
      Serial.println("C");
      Serial.print("temp 4 = ");
      Serial.print(temps.temp3);
      Serial.println("C");
      Serial.println();  


      
   // Asetetaan kursori näytölle column 0, line 1
        lcd.setCursor(0, 0);
        lcd.print("1 ");
        lcd.print(temps.temp0);
        lcd.print("C");
        lcd.setCursor(0, 1);
        lcd.print("2 ");
        lcd.print(temps.temp1); 
        lcd.print("C");      
        lcd.setCursor(0, 2);
        lcd.print("3 ");
        lcd.print(temps.temp2);
        lcd.print("C");
        lcd.setCursor(0, 3);
        lcd.print("4 ");
        lcd.print(temps.temp3); 
        lcd.print("C");   
        
     delay (1000); //Viive 1 sekuntti (1000 millisekunttia)

    }
  
   //Asetetaan ledien syttymis- ja sammumislämpötilat
       if (("Serial(temps.temp3")>= "25")( digitalWrite (vihr, HIGH));
       if (temps.temp3 <= "23") digitalWrite (vihr, LOW);
       if (temps.temp3 <= "22") digitalWrite (pun1, HIGH);
       if (temps.temp3 >= "24") digitalWrite (pun1, LOW);
       if (temps.temp3 <= "21") digitalWrite (pun, HIGH);
       if (temps.temp3 >= "23") digitalWrite (pun, LOW);
} 
}
  if (("Serial(temps.temp3")>= "25")( digitalWrite (vihr, HIGH));
       if (temps.temp3 <= "23") digitalWrite (vihr, LOW);
       if (temps.temp3 <= "22") digitalWrite (pun1, HIGH);
       if (temps.temp3 >= "24") digitalWrite (pun1, LOW);
       if (temps.temp3 <= "21") digitalWrite (pun, HIGH);
       if (temps.temp3 >= "23") digitalWrite (pun, LOW);

You are comparing numbers of the float data type (temps.temp3) to string constants (“23”). Don’t do that. It is meaningless and the compiler doesn’t like it.

Compare numbers to numbers.

if (("Serial(temps.temp3") >= "25")( digitalWrite (vihr, HIGH));
      if (temps.temp3 <= 23) digitalWrite (vihr, LOW);
      if (temps.temp3 <= 22) digitalWrite (pun1, HIGH);
      if (temps.temp3 >= 24) digitalWrite (pun1, LOW);
      if (temps.temp3 <= 21) digitalWrite (pun, HIGH);
      if (temps.temp3 >= 23) digitalWrite (pun, LOW);

With that change the code compiles with some warnings.

if (("Serial(temps.temp3") >= "25")( digitalWrite (vihr, HIGH));

What is that supposed to do? It does not make any sense to me.

if (temps.temp3 >= 25)( digitalWrite (vihr, HIGH));

That makes sense in the context of the following code.

To compare strings, use strcmp() not =.

That code I was trying to get the LED to light is on the trail of various experiments and had to be limited to a comment.

But in that code there is that one sensor value “Serial.print (temps.temp3);” that is on that line of the serial monitor and the value of that sensor is crucial here, the value of the other sensors is general information.

So I just started these Arduino projects in the past and I have not indulged in coding. Therefore, I would like this advice as an iron wire model.

I was trying to find instructions for that strcmp() not =. unfortunately I can't connect it to that code.