Hello I am using two zigbee and two arduino one zigbee is connected each arduino and from router zigbee I am sending data to receiver zigbee I am receiving data successfully, but I'm getting the data in ASCII form
Receiver Code
#include<SoftwareSerial.h>
#include<XBee.h>
SoftwareSerial XBee(2,3);
int data=0;
char IncomingData[13];
String temperature;
String gas;
String readString;
int val;
void setup() {
Serial.begin(9600);
XBee.begin(9600);
}
void loop() {
while (XBee.available())
{
char IncomingData = XBee.read();
//val=atol(IncomingData);
Serial.println("temperature1:"+buttonState);
readString += IncomingData ;
temperature = readString.substring(0, 1); //get the first 13 characters
gas = readString.substring(1, 3);
Serial.println("temperature:"+temperature);
Serial.println("gas:"+gas);
}
}
Sender Code
#include<dht.h>
#include<SoftwareSerial.h>
#include<XBee.h>
#define dht_apin 8 //A3
dht DHT;
const int ledPin=7;
int buzzer=5;
int temp;
int humid;
int a;
const int threshold=33;
SoftwareSerial XBee(2,3); //Rx Tx
void setup()
{
Serial.begin(9600);
XBee.begin(9600);
delay(500);
pinMode(ledPin, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.println("DHT11 humidity and temperature sensor \n\n");
delay(1000);
}
void loop()
{
DHT.read11(dht_apin);
temp=DHT.temperature; // store the temperature values in temp variable
humid=DHT.humidity;// store the humidity values in humid variable
Serial.print("humidity=");
Serial.print(humid);
Serial.print("% ");
Serial.print(",");
//XBee.write("humidity="); //sending humidity value
//XBee.write('H');
//delay(500);
XBee.write(humid); //sending humidity value
// XBee.write("% "); //send percentage
//XBee.write(" ");
//delay(500);
Serial.print("temperature= ");
// XBee.write('T');
XBee.write(temp);
//delay(500);//sending temp value
Serial.print(temp);
Serial.print(" c ");
Serial.println();
delay(1000);
if (temp>threshold)
{
digitalWrite(ledPin, HIGH);
tone(buzzer, 1000, 200);
}
else
{
digitalWrite(ledPin, LOW);
noTone(buzzer);
}
}
And I am receiving the output showed in the image:
temperature:V
gas:[]V