Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
Outlet Checker

Outlet Checker


This project involves a system of D1 Mini microcontrollers configured for peer-to-peer communication using their built-in WiFi capabilities. The primary function of this system is to identify which circuit breakers control specific outlets. Each D1 Mini, serving as a transmitter, is programmed with a unique identifier and transmits a signal when powered. The system also includes a receiver equipped with a strip of WS2812b addressable LEDs, each corresponding to a transmitter (1-5). The transmitters are housed in 3D-printed cases, numbered for easy identification. The process involves plugging the transmitters into outlets and toggling circuit breakers to observe which LED extinguishes, indicating the associated breaker for each outlet.

3D Files and Code are below...

TX Parts:

TX

RX Parts
RX

Power: Use red and black wire from a USB cable...
TXandRX-Power_2048x2048.jpg

LEDs for RX: Use pin D0 for WS2812b LEDs on the RX. It's good to use a 120-240 Ohm resistor between DIN on the LEDs and the D0 PIN, however it's not required.
RX-LEDs_2048x2048.jpg

3D Files: https://a360.co/3U091tW


Code for the Transmitter:

Arduino Code:
// ESP8266 Outlet Checker TX // Created by: HackMakeMod Inc 4/24/24
//
// Description:
// This script configures an ESP8266 module to act as an ESP-NOW transmitter,
// sending power status data to a predefined receiver. The script sends a signal
// indicating whether the transmitter is powered (ON).
//
// Configuration:
// - transmitterId: Identifier for this transmitter (1-5). Unique for each transmitter unit.
// - receiverMAC: MAC address of the receiver module. Must be set to the receiver's actual MAC address.
//
// Hardware Setup:
// - Ensure the ESP8266 is connected to power.
// - The onboard LED indicates the power status and data transmission activity.
//
// Libraries Used:
// - ESP8266WiFi: For handling the WiFi features of the ESP8266.
// - espnow: For implementing the ESP-NOW protocol for efficient local communication between ESP devices.
//
// Important Notes:
// - Initialize the Serial Monitor at 115200 baud rate to view the transmission status and any initialization errors.
// - The receiverMAC array needs to be updated to the actual MAC address of the receiver. This can be found by checking the receiver's serial output during its setup.
// - Adjust the delay in the loop() function based on how frequently you want to send the power status.
//
// Functionality:
// The script continuously sends a 'power on' status at regular intervals, which can be adjusted in the loop.
// Monitor the onboard LED for a visual indication of data transmission (LED is on when transmitting).

#include <ESP8266WiFi.h>
#include <espnow.h>

// Structure to send data
struct dataStruct {
    int id;
    bool powerStatus;
} data;

const int transmitterId = 5; // Set to 1, 2, 3, 4, or 5 for each transmitter
uint8_t receiverMAC[] = {0xC4, 0x5B, 0xBE, 0x71, 0x18, 0xF9}; // Replace XX with receiver's MAC address

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);

  pinMode(LED_BUILTIN, OUTPUT); // Set the onboard LED pin as an output
  digitalWrite(LED_BUILTIN, LOW); // Turn the onboard LED on (active low)

  if (esp_now_init() != 0) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
  esp_now_add_peer(receiverMAC, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);

  data.id = transmitterId;
  data.powerStatus = true; // Assume power is on initially
}

void loop() {
  // Send data to the receiver
  esp_now_send(receiverMAC, (uint8_t *) &data, sizeof(dataStruct));
  Serial.println("Transmit ON");
  delay(250); // Adjust based on your needs
}

Code for the Receiver:

Arduino Code:
// ESP8266 Outlet Checker RX // Created by: HackMakeMod Inc 4/24/24
//
// Description:
// This script sets up an ESP8266 module to act as an ESP-NOW receiver,
// displaying the power status of the transmitters on a strip of WS2812B LEDs. Each LED (1-5)
// represents a different transmitter (1-5). LEDs turn green when the
// corresponding transmitter is powered on and revert to red if no signal
// is received within a defined timeout.
//
// Configuration:
// - NUM_LEDS: Number of LEDs on the strip.
// - DATA_PIN: GPIO pin connected to the data input of the LED strip.
// - TIMEOUT_INTERVAL: Duration in milliseconds before an LED indicates no signal.
// - IDLE_BRIGHTNESS: Brightness level for LEDs when no signal is detected.
//
// Hardware Setup:
// - Connect the data input of your WS2812B LED strip to the defined DATA_PIN.
// - Ensure the ESP8266 is powered and can support the LED strip's power requirements.
//
// Libraries Used:
// - ESP8266WiFi: For operating the WiFi features of the ESP8266.
// - espnow: For utilizing ESP-NOW protocol for local communication between ESP devices.
// - FastLED: For controlling the WS2812B LEDs.
//
// Functions:
// - onDataReceive: Callback function triggered when data is received via ESP-NOW.
//
// Note:
// Initialize the Serial Monitor at 115200 baud rate to view the MAC address to be used in the code for each Transmitter.

#include <ESP8266WiFi.h>
#include <espnow.h>
#include <FastLED.h>

// LED setup
#define NUM_LEDS 5
#define DATA_PIN D0
#define TIMEOUT_INTERVAL 250  // Time in milliseconds after which the LED goes to no signal state
CRGB leds[NUM_LEDS];
unsigned long lastUpdate[NUM_LEDS];  // Array to store the last update time for each LED

#define IDLE_BRIGHTNESS 10  // Brightness level for no signal (10% of 255)

// Structure to receive data
struct dataStruct {
    int id;
    bool powerStatus;
} receivedData;

// Function declarations
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len);

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);

  if (esp_now_init() != 0) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
  esp_now_register_recv_cb(onDataReceive);

  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(255);

  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::White;
    leds[i].nscale8(IDLE_BRIGHTNESS);  // Initialize LEDs to dim white
    lastUpdate[i] = millis();
  }
  FastLED.show();
  // Print the MAC address
  delay(1000);
  Serial.print("MAC Address: ");
  Serial.println(WiFi.macAddress());
}

void loop() {
  unsigned long currentMillis = millis();
  bool updateNeeded = false;

  for (int i = 0; i < NUM_LEDS; i++) {
    if (currentMillis - lastUpdate[i] > TIMEOUT_INTERVAL) {
      leds[i] = CRGB::Red;
      leds[i].nscale8(IDLE_BRIGHTNESS);  // Set to dim white if no recent update
      lastUpdate[i] = currentMillis;  // Reset the last update time to avoid continuous resets
      updateNeeded = true;
    }
  }

  if (updateNeeded) {
    FastLED.show();
  }

  delay(50);  // Lower the delay to improve responsiveness
}

void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
  memcpy(&receivedData, incomingData, sizeof(dataStruct));

  if (receivedData.id > 0 && receivedData.id <= NUM_LEDS) {
    int ledIndex = receivedData.id - 1;  // Convert 1-indexed ID to 0-indexed array position
    lastUpdate[ledIndex] = millis();  // Update the last received time

    if (receivedData.powerStatus) {
      switch(receivedData.id) {
        case 1:
          leds[ledIndex] = CRGB::Green;
          break;
        case 2:
          leds[ledIndex] = CRGB::Green;
          break;
        case 3:
          leds[ledIndex] = CRGB::Green;
          break;
        case 4:
          leds[ledIndex] = CRGB::Green;
          break;
        case 5:
          leds[ledIndex] = CRGB::Green;
          break;
      }
    }

    FastLED.show();
  }
}
Author
HackMakeMod
Views
358
First release
Last update

Ratings

More projects from HackMakeMod

Back
Top