I'm still waiting on my SparkFun Redboards. In the meantime, I received one 433 MHz transmitter and one 433 MHz receiver. Since I have a TI MSP430G2553 and a Duemilanove lying around, I thought I'd get them "talking" to each other.
Components
- 433 MHz receiver
- 433 MHz transmitter
- TI Launchpad w/MSP430G2553
- Arduino Duemilanove
- DHT22 temperature/humidity sensor
- Jumper cables, breadboard
Schematic
Note: For the MSP430G2, p9 is the same as P2_1 in
receiver.pde.
What It Does
Every two seconds, the Duemilanove reads the temperature and relative humidity data from the DHT22 and also calculates the dewpoint. These three data points are concatenated into a string, with each value separated by a comma. Then, the string is transmitted to the MSP430, which dumps these raw data to the serial monitor.
Receiver Code
I used the
VirtualWire library for both the Arduino and MSP430 boards. The MSP used a modified version of VirtualWire that can be found
here (caution: French). I simply modified one line in the
receiver.pde example. I changed line 47 from this:
Serial.print(buf[i], HEX);
To this:
Serial.write(buf[i]);
This small change just outputs the the string that's transmitted, rather than its hexadecimal representation.
Transmitter Code
This part was more complicated. VirtualWire makes the communication part easy, but the problem lies in manipulating the sensor data to the appropriate format for transmission. I tried to limit the use of the String class to keep the code leaner, but I couldn't figure out a good way to concatenate all of the sensor values at the end.
I'm not super familiar with C strings and I've been spoiled by programming in more abstract languages.
Show Code
// Author: Zac DeMeo
// Uses modified DHT22 library from https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib
// Uses VirtualWire library from http://www.airspayce.com/mikem/arduino/VirtualWire/
#include <dht.h>
#include <VirtualWire.h>
dht DHT;
short const DELAY = 2000;
unsigned long THEN = millis();
byte const DHT22_PIN = 5;
byte const LED_PIN = 13;
static char data[20];
void setup() {
Serial.begin(115200);
vw_setup(2000); // Set transmission rate
}
void loop() {
unsigned long NOW = millis();
// Execute if statement block every DELAY milliseconds
if ((NOW - THEN) >= DELAY) {
readTemp();
transmit();
THEN = millis();
}
}
// Reads the DHT22 sensor data. Only processes data if sensor returns DHTLIB_OK.
void readTemp() {
int chk = DHT.read22(DHT22_PIN);
if (chk == DHTLIB_OK) {
char sensors[20];
// Retrieve sensor values
double humidity = DHT.humidity;
double temperature = DHT.temperature;
double dpoint = dewpoint(temperature, humidity);
// Convert to Fahrenheit
dpoint = CtoF(dpoint);
temperature = CtoF(temperature);
// Convert sensor values to strings
char humidityBuffer[5];
char temperatureBuffer[5];
char dpointBuffer[5];
dtostrf(humidity, 4, 1, humidityBuffer);
dtostrf(temperature, 4, 1, temperatureBuffer);
dtostrf(dpoint, 4, 1, dpointBuffer);
// Convert to String and concatenate
String buffer = String(humidityBuffer) + String(",") + String(temperatureBuffer) + String(",") + String(dpointBuffer);
buffer.toCharArray(data, 20);
}
}
// Transmits a string using the VirtualWire library
void transmit() {
// Turn on LED to signal beginning of tx
digitalWrite(LED_PIN, true);
// Send buffer containing sensor data
vw_send((uint8_t*)data, strlen(data));
vw_wait_tx(); // Wait for the transmission to complete
// Turn off LED to signal tx completion
digitalWrite(13, false);
delay(200);
}
// Converts temperature from Celsius to Fahrenheit scale
double CtoF(double temp) {
return (temp * 1.8) + 32;
}
// Calculates the dew point in Celsius, from http://andrew.rsmas.miami.edu/bmcnoldy/Humidity.html
double dewpoint(double T, double RH) {
return 243.04 * (log(RH/100) + ((17.625 * T)/(243.04 + T))) / (17.625-log(RH/100)-((17.625 * T) / (243.04 + T)));
}
Results

It works! As you can see in the picture, the data are transmitted an astonishing 1/4'' wirelessly. Next up: Making quarter-wave whip antennae and range testing.