MKinventions Madhan Chiruguri
Published

πŸ”§ DIY Wireless Sensor Hub with ESP32 + Arduino + NRF24L01

In this project, we design a wireless sensor hub using ESP32 and Arduino connected via NRF24L01 transceivers.

AdvancedProtip6 hours462
πŸ”§ DIY Wireless Sensor Hub with ESP32 + Arduino + NRF24L01

Things used in this project

Story

Read more

Schematics

Interface the NRF24L01 with the ESP32 Wroom.

Interface the OLED with the ESP32 Wroom.

Interface the Menu Buttons with the ESP32 Wroom.

Interface the Buzzer along with 1N4007 Diode the ESP32 Wroom.

Interface the NRF24L01 with the Arduino Uno(ATMEGA328P) IC.

Interface the LED’s with the Arduino Uno(ATMEGA328P) IC.

Interface the Buzzer along with the 1N4007 Diode to the Arduino Uno(ATMEGA328P) IC.

Code

Arduino Unit Code

C/C++
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


#define CE 9
#define CSN 10
#define BUZZER A0
#define DOOR_STATUS_LED 8


RF24 radio(CE, CSN);  // CE, CSN
const byte address[6] = "10001";


// Define data structure
struct data {
  uint8_t nodeId;
  uint8_t nodeState;
  uint8_t doorState;
};


unsigned long previousMillis = 0;
bool buzzerState = false;


// bool wasDisconnected = false; // Flag to track disconnection state


void setup() {
  Serial.begin(115200);
  Serial.println("\nInitializing...");


  pinMode(DOOR_STATUS_LED, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  NRF24_Init();
}






void loop() {
  if (radio.available()) {
    struct data receiveData;
    radio.read(&receiveData, sizeof(receiveData));


    Serial.print("ID: ");
    Serial.print(receiveData.nodeId);
    Serial.print(", Status: ");
    Serial.print(receiveData.nodeState);
    Serial.print(", Door: ");
    Serial.println(receiveData.doorState);


    digitalWrite(DOOR_STATUS_LED, receiveData.doorState);
    // digitalWrite(BUZZER, receiveData.doorState == 1 ? HIGH : LOW);
    buzzer(receiveData.doorState, 100);
  }
}


void NRF24_Init() {
  if (!radio.begin()) {
    Serial.println("❌ NRF24L01 Initialization Failed!");
    return;
  }
  radio.openReadingPipe(1, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  Serial.println("βœ… NRF24L01 Initialized Successfully!");
}


void buzzer(int signal, int delayTime) {
  if (signal == 1) {
    if (millis() - previousMillis >= delayTime) {
      previousMillis = millis();
      buzzerState = !buzzerState;
      digitalWrite(BUZZER, buzzerState);
    }
  } else {
    digitalWrite(BUZZER, LOW);
  }
}

ESP32 Hub

C/C++
As this is the door sensor alert, menu config is not required.
Coming soon in the next upcoming projects.

Credits

MKinventions Madhan Chiruguri
2 projects β€’ 4 followers
Contact

Comments

Please log in or sign up to comment.