Introduction: How to Smarten a Plugboard With ESP32

About: Empowering Creation for Future Innovators; Our mission is to form a community with easy access to whether hardware, software and ideas that allow makers and younger generation to achieve their goals and realiz…

Yes! What you have seen is a smart plugboard that converted by ESP32 master board and controlled by BLE of ESP32. As a fan of Arduino, I am worried about that ESP32 has been supporting Wi-Fi and Bluetooth but without libraries files for Arduino. However, the smart plugboard can control many slave equipment at the same time. Trust me, I have made two and tested them.

Am I the first one to DIY with BLE of ESP32?

please check the video

Hardware in need:

1. USB Power Supply Wall Adapter 5V@2.5A (EU Standard)

2. FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)

3. FireBeetle Covers-Gravity I/O Expansion Shield

4. FireBeetle Covers-Proto Board

5. Gravity: Digital 5A Relay Module

6. Beetle BLE (smallest Arduino bluetooth 4.0)

7. Button

8. Crust printed by 3D printer

*Click here to download the program and the source code for 3D printing.

Step 1: Take a Power Adaptor and Used Plugboard Apart

You would better use tweezers or nippers to break the power adaptor. Mine power adaptor used glues not screws to compound and it is very hard to take it apart.

Talking about how to take the used plugboard apart, you can refer to the video. Anyway, different factories produce different plugboards.

Step 2: Make Power Cables

You need to find a length of household wire, no requirement of types and demolish the outer enameled wires that are about 10cm.

Step 3: Solder the AC Power Line Wire.

Solder one segment wire to the entry of AC.

Caution: To avoid leaking, no too many solders.

Step 4: Use a Diagonal Nipper to Remove the USB Power-supply Interface

Step 5: Solder a Power Cable to Supply the Esp32 FireBeetle Board

Step 6: Connect the Board

The Circuit Diagram is as below:

D2 controls a relay, D3 controls RGB.

In this step, you should fix the relay, Beetle BLE board, plugboard.

You can refer to the radio for details.

Step 7: Download

Beetle BLE Source code:

<p>#include 
<br>#include 
 
#define RELAY_PIN 3
#define RGB_PIN 4
 
enum{
  STOP,
  RUN,
  DEFAULTSTOP
};
 
enum{
  DEFAULTCOLOR,
  RED,
  GREEN,
  BLUE
};
 
PlainProtocol mySerial(Serial,115200);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, RGB_PIN, NEO_GRB + NEO_KHZ800);
 
boolean rgbBlink = false;
char currentState = DEFAULTSTOP;
unsigned long current_millis = 0;
 
/*
 * 1->Red 2->Green 3->Blue default->close
 */
void setRGBColor(int value){
  switch(value){
    case 1:
       strip.setPixelColor(0, strip.Color(255, 0, 0));
       break;
    case 2:
       strip.setPixelColor(0, strip.Color(0, 255, 0));
       break;
    case 3:
       strip.setPixelColor(0, strip.Color(0, 0, 255));
       break;
    default:
       strip.setPixelColor(0, strip.Color(0, 0, 0));
       break; 
  }
  strip.show();
}
void setRelayState(char value){
  if(value == RUN){
    currentState = RUN;
    digitalWrite(RELAY_PIN,HIGH);
    setRGBColor(GREEN);
  }else{
    currentState = STOP;
    digitalWrite(RELAY_PIN,LOW);
    setRGBColor(RED);
  }
}
 
void updateState(void){
  mySerial.write("STATE",currentState);
}
 
void blinkLoop(void){
  static int iRGB = 0;
  static int times = 0;
  if(rgbBlink){
    if(iRGB){
     setRGBColor(DEFAULTCOLOR);
    }else{
      if(currentState==DEFAULTSTOP){
        setRGBColor(BLUE);
      }else if(currentState==RUN){
        setRGBColor(GREEN);
      }else if(currentState==STOP){
        setRGBColor(RED);
      }
      if(times > 50){
        rgbBlink = false;
      }
    }
    times++;
  }else{
    setRelayState(currentState);
    times = 0;
  }
  iRGB=~iRGB;
}
 
void timerRun(void){
  if((millis()- current_millis)>200){
    current_millis = millis();
    blinkLoop();
    updateState();
  }
}
 
void setup() {
  Serial.begin(115200);
  current_millis = millis();
  strip.begin();
  strip.show(); 
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN,LOW);
  setRGBColor(BLUE);
}
 
void loop() {
  if(mySerial.available()){
    if(mySerial.equals("RELAYSTATE")){
      int value = mySerial.read();
      setRelayState(value);
    }else if(mySerial.equals("SCAN")){
      int value = mySerial.read();
      if(value==1)
       rgbBlink = true;
      else
       rgbBlink = false;
    }
  }
  timerRun();
}</p>

<br>

FireBeetle Board-ESP32 microcontroller code:

<p>#include "DFRobot_ESP32_BLE.h"<br>DFRobot_ESP32_BLE ble;
char dataName[15] = {'\0'};
 
boolean relay1 = false;
boolean relay2 = false;
boolean scan = false;
 
void scanKeys(void){
  if(digitalRead(D2) == LOW){
    delay(5);
    while(digitalRead(D2) == LOW);
    String sendStr = "";
    if(relay1 == false){
      sendStr = sendStr+"1;";
      relay1 = true;
    }else{
      sendStr = sendStr+"0;";
      relay1 = false;
    }
    ble.writedata("Chocho1", sendStr);
  }
   
  if(digitalRead(D5) == LOW){
    delay(5);
    while(digitalRead(D5) == LOW);
    String sendStr = "";
    if(relay2 == false){
      sendStr = sendStr+"1;";
      relay2 = true;
    }else{
      sendStr = sendStr+"0;";
      relay2 = false;
    }
    ble.writedata("Chocho2", sendStr);
  }
 
  if(digitalRead(D9) == LOW){
    delay(5);
    while(digitalRead(D9) == LOW);
    String sendStr = "";
    if(scan == false){
      sendStr = sendStr+"1;";
      scan = true;
    }else{
      sendStr = sendStr+"0;";
      scan = false;
    }
    ble.writedata("Chocho1", sendStr);
    delay(10);
    ble.writedata("Chocho2", sendStr);
  }
  delay(20);
}
 
void setup() {
  //Serial.begin(115200);
  pinMode(D2,INPUT);
  pinMode(D5,INPUT);
  pinMode(D9,INPUT);
  ble.setService(0xdfb0);
  ble.setCharacteristic(0xdfb1);
  ble.setconnummax(2);
  ble.setconnectname0("Chocho1");
  ble.setconnectname1("Chocho2");
  ble.init();
  delay(100);
  ble.begin();
}
 
void loop() {
  String bledata = ble.readdata(dataName);
  if (bledata.length() > 0) {
    if (strncmp(dataName, "Chocho1", strlen("Chocho1")) == 0) {
      //Serial.print("Chocho1:");
      //Serial.println(bledata);
    } else if (strncmp(dataName, "Chocho2", strlen("Chocho2")) == 0) {
      //Serial.print("Chocho2:");
      //Serial.println(bledata);
    }
  }
  scanKeys();
}</p>


<br>

Step 8: Complete Machine Assembly

Fix the plug with solders and put it into the crust.