I am currently doing a project reading Body temperature and pulse sensor that will sent the result wirelessly through XBee.
I started by trying each components separately and everything works fine.
Problem:
Inaccurate result when I combine the XBee and LM35 sensor.
The sensor keep giving the same result. Here’s the sketch output.
LM35 Thermometer
Analog in reading: 1023 - Calculated Temp: 109.8
Analog in reading: 1023 - Calculated Temp: 109.8
Analog in reading: 1023 - Calculated Temp: 109.8
Analog in reading: 1023 - Calculated Temp: 109.8
Here’s the code I used:
#include <SoftwareSerial.h>
SoftwareSerial xbee(2, 3); //RX, TX
int potPin = 0;
float temperature = 0;
void setup()
{
Serial.begin(9600);
Serial.println("LM35 Thermometer ");
analogReference(INTERNAL);
xbee.begin(9600);
}
void printTenths(int value) {
// prints a value of 123 as 12.3
Serial.print(value / 10);
xbee.print(value/10);
Serial.print(".");
xbee.print(".");
Serial.println(value % 10);
xbee.print(value % 10);
}
void loop() {
int span = 20;
int aRead = 0;
for (int i = 0; i < span; i++) {
aRead = aRead+analogRead(potPin);
}
aRead = aRead / 20;
temperature = ((100*1.1*aRead)/1024)*10;
// convert voltage to temperature
Serial.print("Analog in reading: ");
Serial.print(long(aRead));
// print temperature value on serial monitor
Serial.print(" - Calculated Temp: ");
xbee.print(" - Calculated Temp: ");
printTenths(long(temperature));
delay(500);
}
I am very sure that before combining it with XBee everything works just fine.
Can anyone explain to me what’s the problem here?
Do it need any voltage adjustment or something?