Go Down

Topic: Wireless Temperature and Humidity Measurement with Arduino LCD Display (Read 101 times) previous topic - next topic

tugceko

Hi for all,
I need advice about my intention to create one sender (DHT11, NRF24L01 and UNO) and one receiver (NRF24L01 and UNO, 16x2 LCD). I test via serial monitor, sender says data can not sent but it can measure the temperature and humidity. I have a problem about LCD i guess, but when i tried to write hello world it works. Here is my codes. Please check. My LCD display photos are attached. I double checked my codes, solders and connections. They're all OK. What's wrong about my project? I guess it could be about something missing in my code.

Code: [Select]
#include <SPI.h>
#include <nRF24L01p.h>
#include <String.h>
#include <dht11.h>
#define DHT11PIN A0

dht11 DHT11;

nRF24L01p transmitter(9,10);
/* CSN - > 10, CE -> 9 defined */

float temp_variable;
float hum_variable;

static char temp[10];
static char hum[10];

void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  /* SPI initialize */
  transmitter.channel(80);
  transmitter.TXaddress("0xe7e7e7e7e7");
  transmitter.init();
  /* Transmitter settings done */
}
void loop() {
  int chk = DHT11.read(DHT11PIN);

  temp_variable = (float)DHT11.temperature;
  hum_variable      = (float)DHT11.humidity;
 
  Serial.print("Nem (%): ");
  Serial.println(hum_variable, 2);

  Serial.print("Sicaklik (Celcius): ");
  Serial.println(temp_variable, 2);
 
  dtostrf(hum_variable,5, 2, hum);
 
  dtostrf(temp_variable,5, 2, temp);
  /* float value converted to string value for temperature */
 
  transmitter.txPL(temp);
  transmitter.txPL(hum);
  boolean sendstate = transmitter.send(FAST);
  /* Temperature information transmitted to nRF24L01 */
  /* If there is a failure, sendstate's value will be false */
  if(sendstate==true){
        Serial.println("Data sent successfully");
  }else{
        Serial.println("Data can not sent!");
  } 
  delay(1000);
}


Code: [Select]
#include <SPI.h>
#include <nRF24L01p.h>
#include <LiquidCrystal.h>
#include "printf.h"
#include <stdlib.h>
#include <stdio.h>      /* printf, NULL */

LiquidCrystal lcd(10, 9, 5, 4, 3, 2);

nRF24L01p receiver(7,8);
/* CSN - > 7, CE -> 8 defined */

void setup(){
  Serial.begin(9600);
  lcd.begin(16, 2);
   
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  /* SPI initialized */
  receiver.channel(80);
  receiver.RXaddress("0xe7e7e7e7e7");
  receiver.init();
  /* Receiver settings done */
}

String temp_variable;
String hum_variable;

void loop(){
  while(receiver.available()){
    receiver.read();
    receiver.rxPL(temp_variable);
    delay(10); 
    receiver.rxPL(hum_variable);
   
    /* Temperature and humidity datas received*/
    if(temp_variable.length()>0)
    {
      Serial.print("temperature = ");
      Serial.println(temp_variable);
     
      Serial.print("humidity = ");
      Serial.println(hum_variable);

       lcd.clear();
       lcd.setCursor(0,0);
       lcd.print("Humidity = ");
       lcd.print(hum_variable);
       lcd.setCursor(0,1);
       lcd.print("Temp = ");
       lcd.print(temp_variable);

      temp_variable="";
      hum_variable="";
      /* old datas deleted */
   }
  }
}


By the way i get the same problem with a brand new lcd and i tested the nrf24's several times. They work.

PaulS

Code: [Select]
static char temp[10];
static char hum[10];

Why are your global variables static?

Code: [Select]
  dtostrf(hum_variable,5, 2, hum);
 
  dtostrf(temp_variable,5, 2, temp);

Do you REALLY believe that your temperature and humidity sensor is capable of +/- 0.01 degrees or +/- 0.01 percent humidity?

Code: [Select]
String temp_variable;
String hum_variable;

You are sending strings. Why are you receiving Strings?

Does the nRF24L01p library really know squat about Strings?
The art of getting good answers lies in asking good questions.

tugceko

OK OK. I'm very new at this. So i changed my library from maniacbug version of nrf24 to tmrh version. Then i wrote a new code. This time my lcd displays NAN. I search the discussions but non of the solutions did not worked for me. here are my codes.

Code: [Select]
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <DHT.h>

#define DHTPIN 5                // do not connect to pin 0 or pin 1
#define DHTTYPE DHT11           // Define DHT11 module
DHT dht(DHTPIN, DHTTYPE);

RF24 transmit (2,3);                            //create RF24 object called transmit
byte address [5] = "00001";                     //set address to 00001

struct package
  {
    float temperature = 0;
    float humidity = 0;
    float rainfall = 0;
  };

typedef struct package Package;
Package data;

void setup() {
  dht.begin();
  transmit.begin();
  transmit.openWritingPipe(address);            //open writing pipe to address 00001
  transmit.setPALevel(RF24_PA_MAX);             //set RF power output to maximum
  transmit.setDataRate(RF24_250KBPS);           //set datarate to 250kbps
  transmit.setChannel(100);                     //set frequency to channel 100
  transmit.stopListening();
  }

void loop() {
  data.temperature = dht.readTemperature();
  data.humidity = dht.readHumidity();
  transmit.write(&data,sizeof(data));
  delay(1000);                                 
}


Code: [Select]
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <LiquidCrystal.h>


RF24 receive (2,3);                         
byte address [5] = "00001";               
LiquidCrystal lcd(8,9,4,5,6,7);

int output_pin10 = 10;
int contrast = 75;

struct package
  {
    float temperature = 0;
    float humidity = 0;
  };

typedef struct package Package;
Package data;

void setup() {
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Receiving");
  pinMode(output_pin10, OUTPUT);
  analogWrite(output_pin10, contrast);
  receive.begin();
  receive.openReadingPipe(0,address);     
  receive.setPALevel(RF24_PA_MIN);       
  receive.setDataRate(RF24_250KBPS);     
  receive.setChannel(100);               
  receive.startListening();               
  }

void loop() {

  if (receive.available())                //check when received data available
  {
    receive.read(&data, sizeof(data));
    lcd.setCursor(0,1);
    lcd.print(data.temperature);
    lcd.print(" C  ");   
    lcd.print(data.humidity);
    lcd.print(" % ");
   
  }
}

PaulS

Code: [Select]
  data.temperature = dht.readTemperature();
  data.humidity = dht.readHumidity();

You assume, quite likely incorrectly, that your sensor is connected properly and is working perfectly.

Try the examples that came with the library BEFORE you assume anything like that.
The art of getting good answers lies in asking good questions.

tugceko

ok, finally i successfully make it work. thanks for your thoughts.

Go Up