WIRELESS RF TEMPERATURE AND RH

DHT RF tr

// Include needed libraries

#include <VirtualWire.h>

#include <DHT.h>

// Defininition

#define dhtPin 4

#define dhtType DHT11

#define txPowerPin 8 // virtual pin, allways different with vw_set_tx_pin

// using the DHT library

DHT dht(dhtPin, dhtType);

// Variables

char msg0[3];

char msg1[3];

int tem = 0;

int hum = 0;

// Setup function – run one time

void setup() {

pinMode(txPowerPin, OUTPUT);

pinMode(txPowerPin, LOW);

vw_setup(4800); // VirtualWire communication speed

vw_set_tx_pin(12); // VirtualWire transmit pin

}

// Loop function – runs forever

void loop() {

digitalWrite(txPowerPin, HIGH);

hum = dht.readHumidity(); // Variable holding humidity

tem = dht.readTemperature(); // Variable holding temperature

itoa(hum, msg1, 10); // Converting humidity to an array of chars

itoa(tem, msg0, 10); // Converting the temperature to an array of chars

strcat(msg0, msg1); // Adding/joining the two arrays

vw_send((uint8_t *)msg0, strlen(msg0)); // Sending the msg

vw_wait_tx(); // Wait for tx to finish

digitalWrite(txPowerPin, LOW);

delay(3000); // Wait three seconds and it again

}

DHT RF rcv

RECEIVER

// Include needed libraries

#include <VirtualWire.h>

#include <Wire.h>

#include <LCD.h>

#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x27

#define BACKLIGHT_PIN 3

#define En_pin 2

#define Rw_pin 1

#define Rs_pin 0

#define D4_pin 4

#define D5_pin 5

#define D6_pin 6

#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE);

LCD *myLCD = &lcd;

// “Drawing” the degree symbol

byte degreesymbol[8] = {

B01100,

B10010,

B10010,

B01100,

B00000,

B00000,

B00000,

B00000

};

// Variables

int tem = 0;

int i;

int led = 13;

// Setup function – run one time

void setup() {

lcd.begin(16,2); // Defining the LCD

lcd.createChar(1, degreesymbol); // Creating the degree symbol at place 1

Serial.begin(9600); // For debugging purpose

vw_setup(4800); // VirtualWire communication speed

vw_rx_start(); // Getting redy to receive

vw_set_rx_pin(2); // VirtualWiore receive pin

lcd.clear(); // Clear the LCD

}

// Loop function – runs forever

void loop() {

uint8_t buf[VW_MAX_MESSAGE_LEN]; // Variable to hold the received data

uint8_t buflen = VW_MAX_MESSAGE_LEN; // Variable to hold the length of the received data

lcd.setCursor(0,0);

lcd.print(“Temp: “);

if (vw_get_message(buf, &buflen)) // If data is received

{

digitalWrite(led, HIGH);

Serial.print(“Temp: “);

for (i=0;i<2;i++) // Get the two first bytes

{

Serial.write(buf[i]); // Debugging purpose

lcd.write(buf[i]); // Write the first bytes on the LCD

}

Serial.print(” degC”);

Serial.print(” “); // Debugging purpose

lcd.write(1); // Write the degree symbol on the LCD

lcd.print(” C”);

lcd.setCursor(0,1);

lcd.print(“Hum: “);

Serial.print(“Hum: “);

for (i=2;i<4;i++) // Get the two last bytes

{

Serial.write(buf[i]); // Debugging

lcd.write(buf[i]); // Write the last bytes on the LCD

}

Serial.print(” %”);

lcd.print(“% RH”);

Serial.println();

}

else{

digitalWrite(led, LOW);

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s