Water level monitoring system using Xbee

Power_Broker:
GET RID OF THAT ATOI() CALL.

I hate to yell, but I don’t think it’s the only way you’ll notice. See my previous post for why atoi() is innapropriate in your case.

It's ok sir. i've been trying to manipulate your suggestions with the coding. When i tried to remove the atoi(), the reading that I receive are, 10, 13, and number ranging from 40 - 58. I think i am getting the -1 if the xbee isnt receiving anything. But when i turn on the sensor, the arduino on the receiver side starts to print 10, 13, 40-58 values.

when the sensor is close to a surface, it prints out 10 or 13.

when the sensor is a little far from a surface, it prints the larger values ranging from 40-58.

and when i try to serial monitor the sensor side in another laptop, the values sent and received are not the same.

this also happens when the atoi() is there.

here's my code

#include <SoftwareSerial.h>
SoftwareSerial XBee(10, 11); // RX, TX

#define relay 5
//int message;

void setup()
{
  pinMode(relay, OUTPUT);
  XBee.begin(9600);
  Serial.begin(9600);
}

void loop()
{
 {
  if (XBee.available() > 0)
  { char message[5]; // holds the C-string
      for (int i=0; i<3; i++) 
      message[i] = XBee.read(); // read the characters from Serial
      message[3] = '\0'; // null termination
    int intValue = atoi(message); // convert to int
  }
  
}
  { // If data comes in from XBee, send it out to serial monitor
    //message = XBee.read();
    Serial.println(XBee.read());
  }
  
    if (XBee.read() >=100 ) 
    {
    digitalWrite(relay, LOW);
    }
    
  else 
  {
    digitalWrite(relay,HIGH);
  }
  delay(3000);
}

I dont have any idea where the numbers 10, 13, 40-58 are coming from. But it is there when i power the sensor side.

Thank you very much!
i