Hello, in this project I am using 2 Arduino boards Transmitter and Receiver. I am planing to transmit temperature and humidity via RF24L01 radio module. Everything works fine, but it would be preferable to display temperature and humidity separately. Does anybody know how to menage it.
Here is the sketch for Transmitter:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "DHT.h"
#define DHTPIN A0 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
float h;
float t;
RF24 radio(8, 10); //digital pins for CE and SCN
const byte rxAddr[6] = "00001";
void setup()
{
radio.begin();
radio.setRetries(15, 15);
radio.openWritingPipe(rxAddr);
radio.stopListening();
}
void loop()
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
h = dht.readHumidity();
t = dht.readTemperature();
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
}
const float dataTemp = t;
radio.write(&dataTemp, sizeof(dataTemp));
// delay (1000);
const float dataHumid = h;
radio.write(&dataHumid, sizeof(dataHumid));
delay(1000);
dht.begin();
}
Here is the sketch for Receiver:
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity
RF24 radio(8, 10); //digital pins for CE and SCN
const byte rxAddr[6] = "00001";
void setup()
{
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines
lcd.setCursor(2,0);
lcd.print("METEO STATION");
lcd.setCursor(5,1);
lcd.print("SETUP");
delay(2000);
lcd.clear();
while (!Serial);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, rxAddr);
radio.startListening();
}
void loop()
{
if (radio.available())
{
float data = 0;
radio.read(&data, sizeof(data));
Serial.print(data);
Serial.print(" ");
lcd.setCursor(4,1);
lcd.print(data,0);
delay(500);
// Serial.print("C*");
// Serial.print("%");
}
}