1

I'm using arduino uno and nrf24l01. to monitor sensor data. But this is the message that master receives:

this is my slave code.

void monitoring() {
    delay(10);
    radio.stopListening();
    int soilMoisture = analogRead(A5);
    int light = analogRead(A4);
    float temp = analogRead(A3);
    temp = temp * 0.48828125;
    int ltemp = int(temp);
    String message = String(soilMoisture) + "," + String(light) + "," +    String(ltemp);
    Serial.println(message);
    delay(200);
    radio.write(&message, sizeof(message));
    delay(50);
    radio.startListening();
    delay(10);
}

and here is my master code.

while (1) {
    if (radio.available()) {
      char message[32] = "";
      radio.read(&message, sizeof(message));
      delay(500);
      Serial.println(message);
}
1

Remove the & in the master code line, change

 radio.read(message, sizeof(message));

to

radio.read(message, sizeof(message));

message is an array, so either you should pass the address of the first character (&message[0]), or simply pass message.

Another problem is sending a String in the slave code (using type String). It's better not to use this type anyway, but you probably have to convert it to a character array of the same type as in the master code.

You can use the function StringToCharArray for that, see StringToCharArray.

  • Thank you very much – alireza Nov 13 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.