I dont know how to send my temperature value through NRF24L01 RX to TX.
I hope someone can help me
Here is my TX code:
//TEMP:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <AccelStepper.h>
#include <SPI.h>
#include <RF24.h>
// Data wire er monteret på digital pin 2 på Arduino
#define ONE_WIRE_BUS 34
// PH-motor: Definere step konstant
#define HALFSTEP 8
// Temp: Progremmere en oneWire(1-leder) for at kommunikere med andre oneWire apparater
OneWire oneWire(ONE_WIRE_BUS);
// Temp: Led oneWire reference til DallasTemperature library
DallasTemperature sensors(&oneWire);
// PH-motor: Pins opsat i IN1-IN3-IN2-IN4 for korrekt step sequence
AccelStepper PH_stepper(HALFSTEP, 49, 46, 48, 44);
// Klor-motor: Pins opsat i IN1-IN3-IN2-IN4 for korrekt step sequence
AccelStepper Klor_stepper(HALFSTEP, 42, 38, 40, 36);
//create an RF24 object
RF24 radio(8, 9); // CE, CSN
//address through which two modules communicate.
const byte address[6] = "00001";
//PH:
unsigned long int PH_avgValue; //Gem den gennemsnitlige værdi fra sensor feedback
int PH_buffer_array[10];
//KLOR:
unsigned long int Klor_avgValue; //Gem den gennemsnitlige værdi fra sensor feedback
int Klor_buffer_array[10];
void setup()
{
//TEMP:
sensors.begin(); // Start library
Serial.begin(9600);
//PH-motor:
// Set the maksimal steps per sekund:
PH_stepper.setMaxSpeed(1000);
// Set the maksimal acceleration i steps per sekund:
PH_stepper.setAcceleration(100);
//Klor-motor:
// Set the maksimal steps per sekund:
Klor_stepper.setMaxSpeed(1000);
// Set the maksimal acceleration i steps per sekund:
Klor_stepper.setAcceleration(100);
radio.begin();
radio.openWritingPipe(address);
//Hvis modulerne flyttes længere fra hinanden, skal "setPAlevel" slettes
//og der skal monteres en støjafkopling over forsyningen.
radio.setPALevel(RF24_PA_MIN);
//Set module as transmitter
radio.stopListening();
}
void loop()
{
//TEMP:
// Send kommandoen for at få temperaturen
sensors.requestTemperatures();
//skriv temperaturen i Celsius
Serial.print("Temperatur: ");
Serial.print(sensors.getTempCByIndex(0));
Serial.println("°C");
delay(1000);
//PH:
for (int a = 0; a < 10; a++) //PH: 10 prøver for at få en mere præcis værdi
{
PH_buffer_array[a] = analogRead(A0);
delay(10);
}
for (int a = 0; a < 9; a++) //PH Sortere analog fra lille til stor
PH_avgValue = 0;
for (int a = 2; a < 8; a++) //Gennemsnitlig værdi fra 6 center prøver
PH_avgValue += PH_buffer_array[a];
float phValue = (float)PH_avgValue * 4.15 / 1024 / 6; //Konventere analog til Volt og finde summen af de 6 center prøver
phValue = 14 - 3.5 * phValue; //Konventere Volt til PH værdi
if (phValue < 5)
{
Serial.print("PH for lav: ");
Serial.println(phValue);
const char text[] = "PH for lav";
radio.write(&text, sizeof(text));
delay(2000);
}
else if (phValue > 8)
{
Serial.print("PH for høj: ");
Serial.println(phValue);
const char text[] = "PH for horj";
radio.write(&text, sizeof(text));
//PH-motor:
// Set slut position:
PH_stepper.moveTo(2038); //2038 steps svarer til en halv omgang
// Kør til den valgte position med den valgte hastighed og acceleration:
PH_stepper.runToPosition();
delay(1000);
// Kør tilbage til start position:
PH_stepper.moveTo(0);
// Kør til start med den valgt hastighed og acceleration:
PH_stepper.runToPosition();
delay(2000);
}
else
{
Serial.print("PH OK :");
Serial.println(phValue);
const char text[] = "PH OK";
radio.write(&text, sizeof(text));
// radio.write(&phValue, sizeof(phValue));
delay(2000);
}
{
for (int b = 0; b < 10; b++) //10 prøver for at få en mere præcis værdi
{
Klor_buffer_array[b] = analogRead(A1);
delay(10);
}
for (int b = 0; b < 9; b++) //Sortere analog fra lille til stor
Klor_avgValue = 0;
for (int b = 2; b < 8; b++) //Gennemsnitlig værdi fra 6 center prøver
Klor_avgValue += Klor_buffer_array[b];
float klorValue = (float)Klor_avgValue * 5.09 / 1024 / 6; //Konventere analog til Volt og finde summen af de 6 center prøver
if (klorValue <= 1.22)
{
Serial.print("Klor for lav: ");
Serial.println(klorValue);
const char text[] = "Klor for lav";
radio.write(&text, sizeof(text));
//Klor-motor:
// Set slut position:
Klor_stepper.moveTo(2038); //2038 steps svarer til en halv omgang
// Kør til den valgte position med den valgte hastighed og acceleration:
Klor_stepper.runToPosition();
delay(1000);
// Kør tilbage til start position:
Klor_stepper.moveTo(0);
// Kør til start med den valgt hastighed og acceleration:
Klor_stepper.runToPosition();
delay(2000);
}
else if (klorValue >= 1.47)
{
Serial.print("Klor for høj: ");
Serial.println(klorValue);
const char text[] = "Klor for hoej";
radio.write(&text, sizeof(text));
delay(2000);
}
else
{
Serial.print("Klor OK: ");
Serial.println(klorValue);
const char text[] = "Klor OK";
radio.write(&text, sizeof(text));
delay(2000);
}
}
}
RX code:
#include <LiquidCrystal.h>
#include <SPI.h>
#include <RF24.h>
RF24 radio(8, 9); // CE, CSN
// Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
const byte address[6] = "00001";
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
//Hvis modulerne flyttes længere fra hinanden, skal "setPAlevel" slettes
//og der skal monteres en støjafkopling over forsyningen.
radio.setPALevel(RF24_PA_MIN);
//Set module som receiver
radio.startListening();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Clears the LCD screen
lcd.clear();
}
void loop() {
if (radio.available())
{
char text[32] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
// Print a message to the LCD.
lcd.print(text);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// lcd.setCursor(0, 1);
// Print a message to the LCD.
//lcd.print(" ");
delay(3000);
lcd.clear();
//delay(100);
}
}