RTC + NRF24l01 + LCD problem

HELLO ;]

I’m trying to build a controllable relay. On the LCD displays the time from rtc and using 4 buttons you can change the time on / off, to have independent control by the pilot (second arduino with nRF24L01), which will switch on / off relay regardless of the time on lcd.

currently it does not respond on time (despite being on the lcd time still flows) or to switch the remote control (second arduino with nRF24L01).

what is wrong??
thanks so much ;]

timer_ON-OFF_1022.ino (5.46 KB)

nrf24l01_LED_ON.ino (826 Bytes)

Which Arduino is that code for? Why do you assume that the problem is with that Arduino?

Why
does
all
of
your
code
start
in
column
one?

Use Tools + Auto Format, to at least look like you know what you are doing.

const int DOWN_BUTTONon =9;        //Buttons Pins
const int UP_BUTTONon =8;
const int DOWN_BUTTONoff =13;       
const int UP_BUTTONoff =10;

Why don’t they have pin in the name? Which Arduino are you using that needs int for holding pin numbers? Do you have something connected to pin 12873?

Why does the code for setting the time to do something READ from the radio? I would expect that code to WRITE to the radio, to tell the other device to turn the relay on or off, at the appropriate time (or to tell it what time to turn the relay on of off).

I use arduino uno (analog pins can be connected to as digital [15,16,17,18,19]) I use two arduino uno; one to operate the LCD and RTC and nRF24L01 module and relay (with 4 buttons to set the time of the ON / OFF button on the LCD, and this causes on / off relay). Second arduino has a form of remote control (arduino + button)independently may switch on wireless relay

Have you written a pair of programs to prove that you can send wireless messages from one Arduino to the other?

This code will send a ridculous number of messages when the button is pressed. It should only send one message.

void loop(void){
 if (digitalRead(switchButton) == HIGH){ // When the push button has been press it will send radio signal to the RX to turn the LED into HIGH
 msg[0] = 111; //Send the 111 to the reciever 
 radio.write(msg, 1);}}

Have a look at this Simple nRF24L01+ Tutorial

...R PS. Please include short programs in your Posts so we don't have to download them.

Programs from Original Post

//Arduino UNO + RTC 1307 + 16X2 LCD + 4 buttons


#include <LiquidCrystal.h>   //Libraries
#include <RTClib.h>

#include "nRF24L01.h" //Include NRF24L01 Code Library which can be downloaded below 
#include "RF24.h" //Inlcude NRF24 Code Library which can be downloaded below 

// do radia

int msg[1]; 
RF24 radio(9,10); // NRF24L01 Pin 
const uint64_t pipe = 0xE8E8F0F0E1LL; //Start Pipe Communication Address 






LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //Arduino pins to lcd
//LCD 1602
//RS to 2pin, EN to 3pin, D4 to 4pin, D5 to 5pin, D6 to 6pin, D7 to 7pin
//Contrast=  10K potentiometer: 1 to Vcc, 2(center)to VO, 3 to GND
//Backlight= K to GND(with 1K resistor), A to Vcc
//Vss to GND , Vdd to +5v

RTC_DS1307 RTC;                     // define the Real Time Clock object
//RTC 1307
//SDA to analog 4,  SCL to analog 5

//You need 4 buttons like this,to enter the set points, with 10K resistor to ground (for each one)

//                  To arduino pins(8, 9, 10, 11)
//                        |
//                        |
//              switch    |   
//              _______   |         10K          
//    +5V  0-----0   0----0------/\/\/\/\-------0  to GND

const int DOWN_BUTTONon =9;        //Buttons Pins
const int UP_BUTTONon =8;
const int DOWN_BUTTONoff =13;       
const int UP_BUTTONoff =10;
const int Relay =12;             //Relay pin

//-----Variables for debouncing------//

boolean lastDownONButton = LOW;
boolean currentDownONButton = LOW;
boolean lastUpONButton = LOW;
boolean currentUpONButton = LOW;
boolean lastDownOFFButton = LOW;
boolean currentDownOFFButton = LOW;
boolean lastUpOFFButton = LOW;
boolean currentUpOFFButton = LOW;



int set_on = 12;        //The default "ON" desired time
int set_off= 12;        //The default "OFF" desired time

boolean  przekaznik = LOW;  // zmienna przekaznika

void setup(){
  pinMode(Relay, OUTPUT);
  
     Wire.begin();
     RTC.begin();
     lcd.begin(16, 2); // Configura lcd numero columnas y filas
     
     lcd.setCursor(0,0);  //Show "TIME" on the LCD
     lcd.print("TIME");
     lcd.setCursor(0,1);
     lcd.print("ON");    //Show "ON" on the lcd
     lcd.setCursor(6,1);
     lcd.print("OFF");  //Show "OFF" on the lcd


     // do radia
radio.begin(); 
radio.openReadingPipe(1,pipe); 
radio.startListening(); 

}
     
   //----Debouncing function for all buttons----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(5);
current = digitalRead(pin);
}
return current;
}
     
 

void loop(){
//--------Show current Time On LCD--------//


DateTime now = RTC.now();        // Clock call
now = RTC.now();

lcd.setCursor(5,0);                 
if(now.hour() < 10)
{
lcd.print("0");
}
lcd.print(now.hour(), DEC); //Print hour
lcd.print(':');
if(now.minute() < 10)
{
lcd.print("0");
}
lcd.print(now.minute(), DEC); //Print min
lcd.print(':');
if(now.second() < 10)
{
lcd.print("0");
}
lcd.print(now.second(), DEC); //Print sec

//----Debounce  buttons---//
currentDownONButton = debounce(lastDownONButton, DOWN_BUTTONon);
currentUpONButton = debounce(lastUpONButton, UP_BUTTONon);
currentDownOFFButton = debounce(lastDownOFFButton, DOWN_BUTTONoff);
currentUpOFFButton = debounce(lastUpOFFButton, UP_BUTTONoff);

//-----Turn down the set "ON"-----//
if (lastDownONButton== LOW && currentDownONButton == HIGH)
{
if(set_on>0){    //"ON" Set point  down never lower than 0
set_on--;        
}
else{
  lcd.setCursor(3,1);
  lcd.print("0");
}
}

//----Turn up the set "ON"----//
else if (lastUpONButton== LOW && currentUpONButton == HIGH)
{
  if(set_on<23){   //"ON" Set point up never higher than 23
  set_on++;
}
else{
  lcd.setCursor(3,1);
  lcd.print("23");
}
}

//---Print the set "ON"---//
lcd.setCursor(3,1);
if(set_on < 10){   
  lcd.print("0");
}
lcd.print(set_on);
lastDownONButton = currentDownONButton;
lastUpONButton = currentUpONButton;

//-----Turn down the set "OFF"-----//
if (lastDownOFFButton== LOW && currentDownOFFButton == HIGH)
{
if(set_off>0){    //"OFF" Set point  down never lower than 0
set_off--;
}
else{
  lcd.setCursor(10,1);
  lcd.print("0");
}
}

//----Turn up the set "OFF"----//
else if (lastUpOFFButton== LOW && currentUpOFFButton == HIGH)
{
  if(set_off<23){   //"OFF" Set point up never higher than 23
  set_off++;
}
else{
  lcd.setCursor(10,1);
  lcd.print("23");
}
}

//---Print the set "OFF"---//
lcd.setCursor(10,1);
if(set_off < 10){   
  lcd.print("0");
}
lcd.print(set_off);
lastDownOFFButton = currentDownOFFButton;
lastUpOFFButton = currentUpOFFButton;



//----Relay Function----//
if(set_on == set_off){
   przekaznik = LOW; 
}

if(set_on < set_off){
  
             if(now.hour() >= set_on && now.hour() < set_off ){             //Start
             przekaznik = HIGH; 
             }
             else if(now.hour() >= set_off) {
             przekaznik = LOW; 
             }
             else{
             przekaznik = LOW; 
             }
}
if (set_on > set_off){

            if(now.hour() >= set_on && now.hour() <= 23){                  //Start
            przekaznik = HIGH;   
            }
            else if(now.hour() < set_off){
            przekaznik = HIGH; 
            }
            else if(now.hour() >= set_off && now.hour() < set_on){
            przekaznik = LOW;  
            }
}

// Wlaczanie radiowe //////////////
if (radio.available() == true){radio.read(msg, 1);}
if(msg[0] == 111){if (przekaznik == LOW){przekaznik = HIGH;} else {przekaznik = LOW;}}


// wlaczanie przekaników

if (przekaznik == LOW){digitalWrite(Relay, LOW);} else {digitalWrite(Relay, HIGH);}

}// The End
#include  <SPI.h> //Include SPI Code Library which can be downloaded below
#include "nRF24L01.h" //Include NRF24L01 Code Library which can be downloaded below
#include "RF24.h" //Inlcude NRF24 Code Library which can be downloaded below
 
int msg[1];
RF24 radio(7,8); // The NRF24L01 Pin CE and Pin CSN
const uint64_t pipe = 0xE8E8F0F0E1LL; //Communication Pip Address
int switchButton = 4; // Push button connected to Arduino pin 7
 
void setup(void){
 Serial.begin(9600); //Start Serial Communication at baud rate 9600
 radio.begin();
 radio.openWritingPipe(pipe);} //Open Communication Pipe
 
void loop(void){
 if (digitalRead(switchButton) == HIGH){ // When the push button has been press it will send radio signal to the RX to turn the LED into HIGH
 msg[0] = 111; //Send the 111 to the reciever 
 radio.write(msg, 1);}}

…R