WIRELESS THERMOHYGROMETER DHT22

For best alternative you can use in https://arduinoproyek.wordpress.com/thermohygrometer-by-wet-and-dry-thermometer/

DHT22 RF24tr

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/WIRELESS%20DHT22%20RF24.zip

TRANSMITTER

#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”
#include “DHT.h”
RF24 radio(8,7);
const float fVerNum = 0.03;
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setupRadio()
{
// Initiate the radio
radio.begin();

// Define the number of retries sending a packet
radio.setRetries(15,15);

// Define the radio’s broadcast channel (0 – 127)
radio.setChannel(30);

// Define the radio’s bitrate (using cards lowest bitrate)
radio.setDataRate(RF24_250KBPS);

// Define the radio’s power amplifier level (RF24_PA_MIN for debugging, RF24_PA_HIGH for longest range)
radio.setPALevel(RF24_PA_MIN);

// Enable dynamic payloads for packets
radio.enableDynamicPayloads();
}
struct package
{
int temperature ;
int humidity ;
};
typedef struct package Package;
Package data;
void setup()
{

setupRadio();
dht.begin();

}

void loop()
{

data.temperature = dht.readTemperature();
data.humidity = dht.readHumidity();

// Open a writing pipe on the radio
radio.openWritingPipe(0xE9E8F0F0E1LL);

// Write the temperature to the pipe
radio.write(&data, sizeof(data));

}

DHT22 RF24rcvLCD

RECEIVER

#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
// — Global variables —

RF24 radio(8,7);
//int packetCounter = 0;

// — Functions —

void setupRadio()
{
// Initiate the radio
radio.begin();

// Define the number of retries sending a packet
radio.setRetries(15,15);

// Define the radio’s broadcast channel (0 – 127)
// Must be the same on the sensor and the master node
radio.setChannel(30);

// Define the radio’s bitrate (using cards lowest bitrate)
radio.setDataRate(RF24_250KBPS);

// Define the radio’s power amplifier level (RF24_PA_MIN for debugging, RF24_PA_HIGH for longest range)
radio.setPALevel(RF24_PA_MIN);

// Enable dynamic payloads for packets
radio.enableDynamicPayloads();

// Open reading pipe
radio.openReadingPipe(1, 0xE9E8F0F0E1LL);

// Start listening for packets
radio.startListening();
}
struct package
{
int temperature ;
int humidity ;
};
typedef struct package Package;
Package data;
#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;

void setup()
{
// Initiate serial connection
Serial.begin(9600);
lcd.begin(16,2); // initialize the lcd
lcd.home ();
// RF Radio setup
setupRadio();
}

void loop()
{
// Check if the radio has received any data
if(radio.available()) {
//int temperature = 0;

// Read the packet received into the temperature variable
if(!radio.read(&data, sizeof(data))) {
// The sensor did not receive the ACK packet
//Serial.println(“ACK not received by client.”);
}

// Print the temperature
lcd.clear();
Serial.print(“T = “);
Serial.print(data.temperature);
Serial.print(” “);
Serial.print(“RH = “);
Serial.println(data.humidity);
lcd.setCursor(0, 0);
lcd.print(“TEMPERATURE:”);
lcd.setCursor(12, 0);
lcd.print(data.temperature);
lcd.setCursor(14, 0);
lcd.print(” C”);
lcd.setCursor(0, 1);
lcd.print(“HUMIDITY:”);
lcd.setCursor(12, 1);
lcd.print(data.humidity);
lcd.setCursor(14, 1);
lcd.print(” %”);

// Wait for serial print to complete
delay(1000);
}
}

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