Transmitting DHT11 data with 433 Mhz

First of all, I am a relative newbie to programming and Arduino. Most of the things I do with my Arduino are explained on the web and are well to do and understandable. The tutorials are easy to follow. The only thing I cannot find anything useful (understandable) about on the web is how to transmit data (Temp. and Hum.) from a DHT11 via 433 Mhz. I can and understand how to transmit words and text (the most basic sketch available) but cannot find much on transmitting actual data.

I would like to send the current temperature and humidity to a second Arduino with a lcd display, however serial would be enough as I can translate that to the lcd. Could someone give me a link to an understandable explanation on how to do this? Or may be a link to a project that uses only DHT11 and 433 MHz.

Thanks for your effort!!!

Kindest regards,

Arjan

The VirtualWire routines can send arbitrary messages. Just move the temperature and humidity data into a buffer and send it. Start with one of the simple examples to send a text message, then change that to send the data of interest.

Well, basically, all you need to do is to convert your readings to strings and send them in the same way you would transmit any other words and text. Or, you could just send the bytes themselves. I converted to strings in these examples.

I adapted these from one of the examples in VirtualWire. There's a sensor and transmitter on one Arduino, and a receiver hooked to the PC on the other board.

// Cloud_Sensor.ino - Uses Melexis MLX90614

#include <i2cmaster.h>
#include <VirtualWire.h>

long int tpl;
int CS_ObjTemp;
int CS_AmbTemp;
char buf[30];
byte packetnum = 0;
int voltage;
bool USBAttached;

void setup() {
  voltage = analogRead(A0);
   if (voltage < 350) {
    USBAttached = true;
  }
  vw_setup(1000); // bps
  if (USBAttached) {
    Serial.begin(19200);// start the serial
  }
  PORTC = (1 << PORTC4) | (1 << PORTC5);  //enable internal pullup resistors on i2c ports
  i2c_init();
}

void loop() {
  GetTemperature();
  sprintf(buf,"P%d S %d A %d :\n" ,packetnum, CS_ObjTemp, CS_AmbTemp);
  send(buf);
  packetnum++;
  if (USBAttached) {
    Serial.print(buf);
  }
  delay(5000);
}

void send (char *message){
    vw_send((uint8_t *)message, strlen(message));
    vw_wait_tx();
}

// read MLX90614 i2c ambient or object temperature
int ReadMLX(int TaTo) {
  long int lii;long 
  int dlsb,dmsb,pec;
  int dev = 0x5A<<1;

  i2c_start_wait(dev+I2C_WRITE);  // set device address and write mode

  switch(TaTo)  {
  case 0:
    i2c_write(0x07); // RAM address of TObj
    break;
  case 1:
    i2c_write(0x06); // RAM address of TAmb
    break;
  }

  i2c_rep_start(dev+I2C_READ);  // set device address and read mode
  dlsb = i2c_readAck();  // read data lsb
  dmsb = i2c_readAck();   // read data msb
  pec = i2c_readNak();
  i2c_stop();

  lii=dmsb*0x100+dlsb;
  return(lii);
}

void GetTemperature (void) {
  tpl=ReadMLX(0); // read sensor object temperature
  tpl = tpl *10;
  tpl = tpl / 5;
  tpl=tpl-27315;
  CS_ObjTemp = tpl/100;

  tpl=ReadMLX(1); // read sensor ambient temperature
  tpl = tpl *10;
  tpl = tpl / 5;
  tpl=tpl-27315;
  CS_AmbTemp = tpl/100;
}

And the receiver:

#include <VirtualWire.h>

void setup(){
  Serial.begin(19200);
  Serial.println("Ready");
  vw_setup(1000); //bps
}
void loop(){
  receive();
}

void receive() {
  byte bufr[30];
  char buf[30];
  byte bufrLength = VW_MAX_MESSAGE_LEN;

  vw_rx_start();

  if (vw_get_message(bufr, &bufrLength)){
    for (int i=8;i<30;i++) {
      buf[i] = '\0';
    }
    memcpy(buf,bufr,bufrLength);

    Serial.print (buf);
  }
}

Notes:
In Cloud_sensor: The USB Sttached stuff was to detect if we are attached to USB, and if not, to send Serial data as well. It doesn't matter if you do or not. I was just experimenting.

Remember, it's important that the receiver knows exactly what's being sent, so it can properly extract the data.

You'll want to put the code for your temp and humidity sensor in there, in place of my Melexis sensor code.

Feel free to ask questions.

Thanks!! I got it to work. It is now sending two variables (humidity and temperature) and showing them on the serial monitor as two separate values below eachother. How ever I would want them to show up on a 16.2 LCD display. I thought it would be an easy step, it isn't. If I copy the data send to the serial monitor (buf*) to the lcd I get completely different values. I got this far (see below for sketch, I hope I added it correctly). I also attached the .ino file*
How can I get the two values Sensor1CharMsg and Sensor2CharMsg from the buffer converted to int. and printed on my LCD.
Thanks!!
//RECEIVER
#include <VirtualWire.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup()
{

  • Serial.begin(9600); // Configure the serial connection to the computer*

  • vw_set_ptt_inverted(true); // Required by the RF module*

  • vw_setup(2000); // bps connection speed*

  • vw_set_rx_pin(3); // Arduino pin to connect the receiver data pin*

  • vw_rx_start(); // Start the receiver*

  • lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight*

  • lcd.print("TEST");*

}

void loop()
{

  • uint8_t buf[VW_MAX_MESSAGE_LEN];*
  • uint8_t buflen = VW_MAX_MESSAGE_LEN;*
  • if (vw_get_message(buf, &buflen)) // We check if we have received data*
  • {*
  • int i;*
  • // Message with proper check *
  • for (i = 0; i < buflen; i++)*
  • {*
    _ Serial.write(buf*); // The received data is stored in the buffer*_
    * // and sent through the serial port to the computer*

* }*
* Serial.println();*
* }*
}
Weer_433receiver_DHT11.ino (1.05 KB)

Please use code tags to post code. Highlight your code, then click on the # icon above the editor. You can edit your post to put the tags in.

  1. Does "TEST" show up on the LCD?

  2. Can you tell us what values show up on the Serial Monitor and what values show up on the LCD? I don't see any lcd operations other than "TEST" on the receiving side.

Please post your final transmit code, too. We need to see exactly what you are sending, in order to know how to receive it.

Didn't know about the code tags, sorry. Here is the code I am setup for using with the display. I have edited it somewhat. Test does appear (at the moment set to be 1 sec), the screen functions normally. On my serial monitor I get the values as they are (at the moment 20 (Sensor1Data = DHT11.temperature;) and 42 (Sensor2Data = DHT11.humidity;)). On my display (16x02 at the moment) I get varying values but most of the time just 1. Below are the sketches for sending and receiving. I have been tinkering about with 'atoi' but can not get it to work. There might be a bit more code in it than needed but it is going to be cleaned later.

I hope I copied the code like it needs the be copied an thats enough information.

//RECEIVER
#include <VirtualWire.h>

 #include <LiquidCrystal_I2C.h>
 #include <Wire.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
 
 
void setup()
{
    Serial.begin(9600);          // Configure the serial connection to the computer
    vw_set_ptt_inverted(true);  // Required by the RF module
    vw_setup(2000);            // bps connection speed
    vw_set_rx_pin(3);         // Arduino pin to connect the receiver data pin
    vw_rx_start();           // Start the receiver
    
     lcd.begin(16,2);   // initialize the lcd for 16 chars 2 lines, turn on backlight
  
  lcd.print("TEST");
  delay(1000);
  lcd.clear();
    
}
 
void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen))      // We check if we have received data
  {
    int i;
    // Message with proper check    
    for (i = 0; i < buflen; i++)
    {
      Serial.write(buf[i]);  // The received data is stored in the buffer
                            // and sent through the serial port to the computer
       
    }
    Serial.println();
   
    // NOTE: Cursor Position: (CHAR, LINE) start at 0  
 
  lcd.setCursor(0,0);
  lcd.print(buf[i]);
  //delay(000);
  //lcd.setCursor(0,1); //Start at character 4 on line 0
  //lcd.print(LDRValue);
  }
}

This is my sender code

   //TRANSMITTER

/*-----( Import needed libraries )-----*/
#include <VirtualWire.h>
#include <dht11.h>

/*-----( Declare objects )-----*/
dht11 DHT11;

/*-----( Declare Constants, Pin Numbers )-----*/
#define DHT11PIN 2

int Sensor1Data;
int Sensor2Data;
char Sensor1CharMsg[4];
char Sensor2CharMsg[4];

void setup()
{
    vw_set_ptt_inverted(true);  // Required by the RF module
    vw_setup(2000);            // bps connection speed
    vw_set_tx_pin(4 );         // Arduino pin to connect the receiver data pin
    
     Serial.begin(9600);
   Serial.println("DHT11 TEST PROGRAM ");
   Serial.print("LIBRARY VERSION: ");
   Serial.println(DHT11LIB_VERSION);
   Serial.println();
    
}
 
void loop()
{
  Serial.println("\n");
  
  int chk = DHT11.read(DHT11PIN);
  Sensor1Data = DHT11.temperature;
  Sensor2Data = DHT11.humidity;
  delay(2000);
  // Convert integer data to Char array directly 
  itoa(Sensor1Data,Sensor1CharMsg,10);
  itoa(Sensor2Data,Sensor2CharMsg,10);
  
  Serial.print("Read sensor: ");
  switch (chk)
  {
    case 0: Serial.println("OK"); break;
    case -1: Serial.println("Checksum error"); break;
    case -2: Serial.println("Time out error"); break;
    default: Serial.println("Unknown error"); break;
  }
  
  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);
  
delay(2000);
  
   //Message to send:
   digitalWrite(13, true); // Turn on a light to show transmitting
 vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));
 vw_send((uint8_t *)Sensor2CharMsg, strlen(Sensor2CharMsg));
 vw_wait_tx(); // Wait until the whole message is gone
 digitalWrite(13, false); // Turn off a light after transmission
 delay(200);                
}

I´ve Got the same Problem!