Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15287

Garage Door Opener using NRF24L01

$
0
0

Hello All:

Hope you all had a Wonderful Christmas and a happy new year. I'm trying to build a garage door opener using two Arduino Nano's and two NRF24L01 modules. I currently have a garage door opener but the main control pad is in the garage which is detached from my house. The unit that will go in the house (transmitter) will have a push button, and three LED's (one RGB LED.)

The garage unit (receiver) will contain a single relay which will be wired into the existing garage door opener main unit, which will close for 650 milliseconds triggering the door to close, and a reed switch which will send data back to the transmitter.

At the transmitter the three LED's will be used to display the status of the garage door, opened or closed. Green light means closed, red means opened, and blue means activity as when I press the button. When the button is pressed a signal is sent to the receiver which closes the relay. So far I got the relay to close.

The problem: I got the reed switch working at the receiver which lights up a red or green light but only at the receiver, I'm not coding it correctly to get the signal back to the transmitter so the remote lights light up. The reed switch is connected to the receiver and is working but I can't seem to get the signal back.

The code I have is in two parts, one for the transmitter and one for the receiver. Please see the attached code. Links to the hardware I'm using can be found below. Thanks to everyone in advance for your help.

Reed Switch

Arduino Nano

Relay

NRF24L01

Push Buttons

TRANSMITTER CODE

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define blueLed 2
#define redLed 4
#define greenLed 5
#define CE 7
#define CSN 8
#define buttonPin 3
int buttonState = 0;
int sensorState = 0;
int rdt = 650;

RF24 radio(CE, CSN);

byte addresses[][6] = {"pass1", "pass2"};

void setup() {
  Serial.begin(115200);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(blueLed, OUTPUT);
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  digitalWrite(blueLed, LOW);
  digitalWrite(greenLed, HIGH);
  digitalWrite(redLed, LOW);
  radio.begin();
  radio.setChannel(124);
  radio.setPALevel(RF24_PA_MAX);
  radio.openWritingPipe(addresses[1]);
  radio.openReadingPipe(1, addresses[0]);
  radio.stopListening();
}
void loop() {
  buttonState = digitalRead(buttonPin);
  //sensorState = digitalRead(Sensor);
  if (buttonState == 1) {
    buttonState = 1;
    digitalWrite(blueLed, LOW);
    digitalWrite(greenLed, HIGH);
    digitalWrite(redLed, LOW);
  } else if (buttonState == 0) {
    buttonState = 0;
    digitalWrite(blueLed, HIGH);
    digitalWrite(greenLed, LOW);
    digitalWrite(redLed, LOW);
  }

  //Serial.print("Button State ");
  //Serial.print(buttonState);
  // Serial.print(" Sensor State ");
  // Serial.println(sensorState);
  Serial.print("\t");
  radio.write(&buttonState, sizeof(buttonState));
}

RECEIVER CODE

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define redLed A0
#define Relay A1
#define greenLed A5
#define sensorPin 2
#define CE 7
#define CSN 8
int rdt(650);
int buttonState = 0;
int sensorState = 0;

RF24 radio(CE, CSN);

byte addresses[][6] = {"pass1", "pass2"};

void setup() {
  Serial.begin(115200);
  pinMode(sensorPin, INPUT_PULLUP);
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(Relay, OUTPUT);
  digitalWrite(redLed, HIGH);
  digitalWrite(greenLed, HIGH);
  digitalWrite(Relay, HIGH);
  radio.begin();
  radio.setChannel(124);
  radio.openWritingPipe(addresses[0]);
  radio.openReadingPipe(1, addresses[1]);
  radio.setPALevel(RF24_PA_MAX);
}
void loop() {

  sensorState = digitalRead(sensorPin);
  if (sensorState == 1) {
    digitalWrite(redLed, HIGH);
    digitalWrite(greenLed, LOW);
  } else if (sensorState == LOW) {
    digitalWrite(redLed, LOW);
    digitalWrite(greenLed, HIGH);
  }
  
  radio.startListening();
  while (!radio.available());
  radio.read(&buttonState, sizeof(buttonState));


  if (buttonState == 1) {
    digitalWrite(redLed, LOW);
    digitalWrite(Relay, HIGH);

  } else if (buttonState == 0) {
    delay(rdt);
    digitalWrite(redLed, HIGH);
    digitalWrite(Relay, LOW);
  }
}

4 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 15287

Trending Articles