How to send a float number with a 433Htz transmitter?

Hi everybody,

I 'm trying to do a meteo station with a DHT22 sensor who give me temperature and humidity and a trans mitter and a receiver UHF433. I'm a beginner in programmation so I copy paste and modify codes I found on internet. I use the rc-switch bibliotheque and here is my transmitter code:

/* TEMPERATURE  SENSOR DHT22 + TRANSMITTER 433 MHTZ */
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
#include <DHT.h> //include DHT library

#define brocheBranchementDHT 6 //define "la broche de branchement"
#define typeDeDHT DHT22 //define the type of DHT

DHT dht(brocheBranchementDHT, typeDeDHT);

 
void setup() {
// initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  dht.begin();
 
// transmitter connected on the pin n° 10  
  mySwitch.enableTransmit(10);
  mySwitch.setProtocol(2); // best config after test
  mySwitch.setPulseLength(550); // best config after test
  mySwitch.setRepeatTransmit(6); // best config after test
}
 
void loop() {
  // reading data
  float tauxHumidite = dht.readHumidity();              // readiing of "taux d'humidité (en %)"
  float temperatureEnCelsius = dht.readTemperature();   // reading of the temperature in celsius degrees

  // verification if we received data
  if (isnan(tauxHumidite) || isnan(temperatureEnCelsius)) {
    Serial.println("Aucune valeur retournée par le DHT22. Est-il bien branché ?");
    delay(1000);
    return;         // if no data is received by arduino, wait 1 sec then restart the void loop()
  }

  // Feeling temperature calculation
  float temperatureRessentieEnCelsius = dht.computeHeatIndex(temperatureEnCelsius, tauxHumidite, false); // Le "false" est là pour dire qu'on travaille en °C, et non en °F
  
  // Displaying values
  Serial.print("Humidité: "); Serial.print(tauxHumidite); Serial.println(" %");
  Serial.print("Température: "); Serial.print(temperatureEnCelsius); Serial.println(" °C");
  Serial.print("Température ressentie: "); Serial.print(temperatureRessentieEnCelsius); Serial.println(" °C");
  Serial.println();

  delay(1000);

   mySwitch.send((888000 + tauxHumidite), 24); // send data to the UHF433 transmitter
   mySwitch.send((999000 + temperatureEnCelsius), 24);
   mySwitch.send((777000 + temperatureRessentieEnCelsius), 24);
 
  delay(1500); 
}

and here is the receiver code:

#include <RCSwitch.h>
// call 433 library
RCSwitch mySwitch = RCSwitch();

String temporaryValue ;
float temperatureout = 0 ;
float humiditeout = 0 ;
float temperatureressentieout = 0 ;
long oldDataTime;

void setup() {
  Serial.begin(115200);
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
}

void loop() {
  if (mySwitch.available()) {

    long value = mySwitch.getReceivedValue();

    if (value == 0) {
      Serial.print("Unknown encoding");
    } else /*{
      Serial.print("Received ");
      Serial.print( mySwitch.getReceivedValue() );
      Serial.print(" / ");
      Serial.print( mySwitch.getReceivedBitlength() );
      Serial.print("bit ");
      Serial.print("Protocol: ");
      Serial.println( mySwitch.getReceivedProtocol() );
    } */

    // get data and split values
    temporaryValue = String(mySwitch.getReceivedValue());
    if(temporaryValue.substring(0,3) == "999"){
      temperatureout = temporaryValue.substring(3).toFloat() ;
    }  
    if(temporaryValue.substring(0,3) == "888"){
      humiditeout = temporaryValue.substring(3).toFloat() ;
    }
    if(temporaryValue.substring(0,3) == "777"){
      temperatureressentieout = temporaryValue.substring(3).toFloat() ;
    }
  

    // reset 433
    mySwitch.resetAvailable();

    oldDataTime = millis();

  }
  // control if we lost information , 10 second 
  if(millis() > (oldDataTime + 10000) ){
    temperatureout = 999 ;
    humiditeout = 888 ;
    temperatureressentieout = 777 ;
  }

  // print value
  // displaying values
      Serial.print("Humidite: ");
      Serial.print(humiditeout);
      Serial.println(" %");
      Serial.print("Temperature: ");
      Serial.print(temperatureout);
      Serial.println(" °C");
      Serial.print("température ressentie: ");
      Serial.print(temperatureressentieout);
      Serial.println(" °C");
      Serial.println();

  delay(2000);
}

What is your problem? Does that code work at all, not including sending the value?

I don't receive decimal numbers (with the fonction "float")

What do you receive, then? What does happen when you run the code that you posted?

this is what I receive in my receiver serail monitor from the transmitter :
Humidite: 40.00 %

Temperature: 26.00 °C

température ressentie: 26.00 °C

and this is what I receive from the DHT sensor :
Humidité: 40.30 %

Température: 26.30 °C

Température ressentie: 26.04 °C

How did you obtain this output?

with the serial monitor.

What does the documentation for this function say about the data type it accepts as a parameter? Have you read the documentation, prior to posting your question?

I'm sorry but I don't know it because I copy paste it from internet and I didn't found the documentation

this is why I asked the question, because I'm a beginner and I need help :face_with_diagonal_mouth: :pleading_face:

From rc-switch library documentation:
Use your Arduino or Raspberry to operate remote radio controlled devices

That library is not designed to work with the type of data you intend to send.

The most suitable is RadioHead: RadioHead Packet Radio library for embedded microprocessors

Manuals are designed to help everyone, including beginners. It should always be your first response to read them. Someone has spent the time to answer most of the questions there, that people can ask.

If there was anything in there you didn't understand, you could post or link to it, and we could help you to understand it. I'm sorry if that seems cruel, but it is the reality of working with this kind of technology that you must learn to Read the Documentation.

I don't know it because I copy paste it from internet and I didn't found the documentation

That only means that you didn't research it on the internet. You know the name of the libraries and hardware, you can put those into a search engine to find the documentation.

Those skills are just as important as learning to connect wires.

thank you very much for this solution!!

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