I'm getting the Ok. But I found an example on a blog:
So I took it, and merged it with the DHT11.
Transmitter:
//
// FILE: dht11_test1.pde
// PURPOSE: DHT11 library test sketch for Arduino
//
//Celsius to Fahrenheit conversion
#include <dht11.h>
dht11 DHT11;
#define DHT11PIN 2
#include <VirtualWire.h>
// LED's
const int ledPin = 13;
// Sensors
int Sensor1Data;
//int Sensor2Data;
char Sensor1CharMsg[4];
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}
//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
return celsius + 273.15;
}
// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}
// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}
void setup()
{
Serial.begin(9600);
// LED
pinMode(ledPin,OUTPUT);
// VirtualWire setup
vw_setup(2000); // Bits per sec
}
void loop()
{
// Read and store Sensor 1 data
int chk = DHT11.read(DHT11PIN);
Sensor1Data = DHT11.temperature;
delay(2000);
// Convert integer data to Char array directly
itoa(Sensor1Data,Sensor1CharMsg,10);
// DEBUG
Serial.print("Sensor1 Integer: ");
Serial.print(Sensor1Data);
Serial.print(" Sensor1 CharMsg: ");
Serial.print(Sensor1CharMsg);
Serial.print("RawSensor: ");
Serial.print(DHT11.temperature);
Serial.println(" ");
delay(1000);
// END DEBUG
digitalWrite(13, true); // Turn on a light to show transmitting
vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false); // Turn off a light after transmission
delay(200);
}
//
// END OF FILE
//
Reciever:
/*
Sensor Receiver
By Markus Ulfberg 2012-07-06
Gets a sensor reading 0-1023 in a char array
from RF Transmitter unit via VirtualWire
converts char array back to integer
*/
#include <VirtualWire.h>
// LED's
int ledPin = 13;
// Sensors
int Sensor1Data;
// RF Transmission container
char Sensor1CharMsg[4];
void setup() {
Serial.begin(9600);
// sets the digital pin as output
pinMode(ledPin, OUTPUT);
// VirtualWire
// Initialise the IO and ISR
// Required for DR3100
vw_set_ptt_inverted(true);
// Bits per sec
vw_setup(2000);
// Start the receiver PLL running
vw_rx_start();
} // END void setup
void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
// Non-blocking
if (vw_get_message(buf, &buflen))
{
int i;
// Turn on a light to show received good message
digitalWrite(13, true);
// Message with a good checksum received, dump it.
for (i = 0; i < buflen; i++)
{
// Fill Sensor1CharMsg Char array with corresponding
// chars from buffer.
Sensor1CharMsg[i] = char(buf[i]);
}
// Null terminate the char array
// This needs to be done otherwise problems will occur
// when the incoming messages has less digits than the
// one before.
Sensor1CharMsg[buflen] = '\0';
// Convert Sensor1CharMsg Char array to integer
Sensor1Data = atoi(Sensor1CharMsg);
// DEBUG
Serial.print("Temp Outside: ");
Serial.println(Sensor1Data);
// END DEBUG
// Turn off light to and await next message
digitalWrite(13, false);
}
}
Now it's working. Not sure I understand exactly how it parses the int over. I sure need to study arrays more. And just experiment with em.