Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Wi-Fi Controlled Relay with NRF24L01 Wireless Communication

View and Edit Project In Cirkit DesignerImage of Wi-Fi Controlled Relay with NRF24L01 Wireless Communication

Circuit Documentation

Summary

This circuit integrates a NodeMCU V3 ESP8266 microcontroller with an NRF24L01 wireless transceiver module, a relay module, an LED, a resistor, a pushbutton, and an electrolytic capacitor. The NodeMCU is programmed to control the relay and communicate with the NRF24L01 module. The relay can be triggered by a signal from the NRF24L01 or by pressing the pushbutton. The LED indicates the relay's status, and the capacitor provides power supply filtering.

Component List

NodeMCU V3 ESP8266

NRF24L01

Relay Module 5v-30v

LED: Two Pin (red)

Resistor

Pushbutton

Electrolytic Capacitor

Wiring Details

NodeMCU V3 ESP8266

NRF24L01

Relay Module 5v-30v

LED: Two Pin (red)

Resistor

Pushbutton

Electrolytic Capacitor

Documented Code

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <RF24.h>

// NRF24L01+ Pins
#define CE_PIN D2
#define CSN_PIN D1

// Relay and Push Button
#define RELAY_PIN D3
#define BUTTON_PIN D4

RF24 radio(CE_PIN, CSN_PIN); // Create NRF24L01 object

void setup() {
  Serial.begin(115200);
  
  // Initialize Relay and Button Pins
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW); // Ensure relay is off
  pinMode(BUTTON_PIN, INPUT_PULLUP); // Using internal pull-up resistor

  // Initialize NRF24L01
  radio.begin();
  radio.setPALevel(RF24_PA_HIGH);
  radio.openReadingPipe(1, "00001"); // Set address for reading
  radio.startListening();

  Serial.println("Setup Complete");
}

void loop() {
  // Check for incoming RF data
  if (radio.available()) {
    char receivedText[32] = "";
    radio.read(&receivedText, sizeof(receivedText));
    Serial.println(receivedText);

    // Example action: Toggle Relay on receiving specific command
    if (strcmp(receivedText, "ACTIVATE") == 0) {
      digitalWrite(RELAY_PIN, HIGH); // Turn on relay
      delay(2000); // Keep relay on for 2 seconds
      digitalWrite(RELAY_PIN, LOW); // Turn off relay
    }
  }

  // Check if button is pressed
  if (digitalRead(BUTTON_PIN) == LOW) {
    Serial.println("Button Pressed, Activating Relay");
    digitalWrite(RELAY_PIN, HIGH); // Turn on relay
    delay(2000); // Keep relay on for 2 seconds
    digitalWrite(RELAY_PIN, LOW); // Turn off relay
  }

  delay(100); // Small delay to avoid bouncing
}

This code is designed to run on the NodeMCU V3 ESP8266 microcontroller. It initializes the NRF24L01 module and sets up the relay and pushbutton for input and output, respectively. The microcontroller listens for incoming data from the NRF24L01 module and toggles the relay when the "ACTIVATE" command is received. Additionally, the relay can be activated by pressing the pushbutton. The relay remains active for 2 seconds before turning off.