Hi guys
First of all I want to say this threat have nothing to do with robotics. Instead its about using some Arduinos to make a weather station. I've seen some of you are using RF links and VirtualWire in your projects so I hope you can help me anyway! :-)
As written above Im in the middle of making a weather station. Im using an Arduino outside the house with a couple of sensors (At this point temperature and humidity). In side the house an other Arduino will be displaying the data from the sensors on a screen. The communication happens wirelessly using RF links.
I managed to read the data from the sensors and transmit the data to the receiving Arduino. The receiving Arduino print the data in the serial monitor. It looks about right (22.1 is temperature and 46.0 is humidity):
22.1, 46.0,
22.1, 46.0,
22.1, 46.0,
22.1, 46.0,
The problem is that I need to "split" the data apart to print it on a LCD screen. Like, in this case, storing 22.1 in one float and 46.0 in another.
This is the code I wrote:
Transmitter:
#include <VirtualWire.h>
#include <DHT.h>
//Defining DHT sensor
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
float H = 0;
int tempPin = 0;
float calTemp;
char tString[24];
char hString[24];
char msg[27];
void setup()
{
Serial.begin(9600);
//VirtualWire setup
vw_set_tx_pin(12);
vw_setup(2000);
dht.begin();
}
void loop() {
H = dht.readHumidity();
analogReference(INTERNAL);
temp(analogRead(tempPin)); //Calculating temperature in celcius
analogReference(DEFAULT);
sendData();
delay(100);
}
void temp(int value) {
long temperature = 0;
//Reading the sensor 20 times and finding the average reading
int aRead = 0;
for (int i = 0; i < 20; i++) {
aRead = aRead+value;
}
aRead = aRead / 20;
//Converting the temperature to celsius
temperature = ((100*1.1*aRead)/1024)*10;
// prints a value of 123 as 12.3
long hele = temperature / 10;
float deci = (temperature % 10)/10.0;
calTemp = hele + deci;
}
int sendData (){
//Converting temperature to a string
dtostrf(calTemp, 5, 1, tString);
//Converting humidity to a string
dtostrf(H, 5, 1,hString);
//Combining to one string
sprintf(msg, "%s, %s,", tString, hString);
Serial.print("message to send: [");
Serial.print(msg);
Serial.println("]");
//Sending the string
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();
}
Receiver:
#include <VirtualWire.h>
void setup()
{
Serial.begin(9600);
//VirtualWire Setup
vw_setup(2000);
vw_set_rx_pin(10);
vw_rx_start();
}
void loop()
{
uint8_t buflen = VW_MAX_MESSAGE_LEN; //Maximum length of the message
uint8_t buf[buflen]; // The buffer that holds the message
if (vw_get_message(buf, &buflen))
{
buf[buflen] = '\0';
Serial.println((char *)buf);
}
}
My questions is therefore: Can anyone help me with separating the different variables that the RF links receives?
Thanks a lot!