I am working on a project at school with arduino,
The intention is actually that we have to measure the temprature in different places and send it to 1centralle which then records everything.
The only thing I have problems with is the code itself. When I look at the sender through the adrenal program itself, I see that he is recording the temprature, but when I look at the receiver I only see 00 so he does not receive it. (probably this will be something stupid since I am a beginner with arduino)
hopefully someone can check my code and help me to get the errors out.
What I use for it:
arduino Nano as mother of the sensor
dht22 as a sensor
arduino due as central
nRF24L01 to send the data.
these are my sketches:
codes:
Receiver:
#include "DHT.h"
#include <SPI.h>
#include "RF24.h"
#define DHTPIN 4
#define DHTTYPE DHT22
RF24 myRadio (7, 8);
byte address[][6] = {"00001"};
const int led_pin = 13;
struct package
{
float temperature ;
float humidity ;
};
typedef struct package Package;
Package data;
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
Serial.begin(9600);
pinMode(led_pin, OUTPUT);
dht.begin();
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openReadingPipe(0, address);
myRadio.startListening();
}
void loop()
{
if (myRadio.available()) {
char text[32]= "";
myRadio.read(&text, sizeof(text));
Serial.println(text);
}
}
transmitter
#include "DHT.h"
#include <SPI.h>
#include "RF24.h"
#define DHTPIN 4
#define DHTTYPE DHT22
RF24 myRadio (7, 8);
byte addresses[][6] = {"00001"};
const int led_pin = 13;
struct package
{
float temperature ;
float humidity ;
};
typedef struct package Package;
Package data;
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
Serial.begin(9600);
pinMode(led_pin, OUTPUT);
dht.begin();
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openWritingPipe( addresses[0]);
delay(1000);
}
void loop()
{
digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
readSensor();
Serial.println(data.humidity);
Serial.println(data.temperature);
myRadio.write(&data, sizeof(data));
digitalWrite(led_pin, LOW);
delay(1000);
}
void readSensor()
{
data.humidity = dht.readHumidity();
data.temperature = dht.readTemperature();
const char text[] = "dht.readTemperature()";
myRadio.write(&text, sizeof(text));
delay(1000);
}