Im trying to send the temperature from one Arduino to an other. Im using LM35DT sensor and got it working when viewing the calculations in the transmitter Serial Monitor. The results are about 240-250. This means the temperature is about 24,0-25,0 celcius. The problem happens when trying to transmit these numbers to the receiving Arduino. Instead of receiving numbers between 240 and 250 I'm receiving numbers like these:
2
2
66
2
98
98
2
2
97
2
2
99
2
2
66
Im using RF links and the VirtualWire library.
Transmitter code:
#include <VirtualWire.h>
int potPin = 0;
int temperature = 0;
int ledPin = 10;
void setup()
{
Serial.begin(9600);
analogReference(INTERNAL);
pinMode(ledPin, OUTPUT);
//VitualWire Setup
vw_setup(2000);
vw_set_tx_pin(2);
}
void loop() {
int span = 20;
int aRead = 0;
//Getting a more reliable temperature reading
for (int i = 0; i < span; i++) {
aRead = aRead+analogRead(potPin);
}
aRead = aRead / 20;
// convert voltage to temperature
temperature = ((100*1.1*aRead)/1024)*10;
//Printing to Serial buffer
Serial.println(temperature);
//Transmitting the temperature
int msg = temperature;
vw_send((uint8_t *) msg, 3);
digitalWrite(ledPin, HIGH);
vw_wait_tx();
digitalWrite(ledPin, LOW);
delay(500);
}
Receiver code:
#include <VirtualWire.h>
void setup(){
vw_set_rx_pin(8);
vw_setup(2000);
vw_rx_start();
Serial.begin(9600);
}
void loop() {
uint8_t buflen = VW_MAX_MESSAGE_LEN;
uint8_t buf[buflen];
if (vw_get_message(buf, &buflen))
{
for(int i = 0; i < buflen;i++)
{
Serial.println(buf[i]);
}
}
}