Get Started With BEVRLink 4 Relay + 4 Buttons with inbuilt ESP32 - Arduino

Get Started With BEVRLink 4 Relay + 4 Buttons with inbuilt ESP32 - Arduino

The example below is only one way how to set up the Relay Module giving examples for both with and without buttons.

The BEVRLink Relay 4 with inbuilt ESP32 12V use the ESP32-C6 module with WiFi, Bluetooth and Zigbee/Matter support. Here we will give examples how you can control the relays with code, this code can later be added to your wireless control. With this relay module board you need the BEVRLink Power Supply 12V 2A.

Optional for a safe setup we recommend to use case for both the manager and relay boards: BEVRLink Cases

Set up ESP32 support in Arduino

    1. Download latest Arduino IDE
    2. Add ESP32 3.0 to Arduino board manager database
      1. File->Preference
      2. To the textbox "Additional boards manager URLs" add:
https://espressif.github.io/arduino-esp32/package_esp32_index.json
  1. Press OK
  2. Tools->Board->Board Manager
  3. Search for ESP32, you might get many results, select the one from Espressif System and change the version 3.0.0-alpha3 or newer in the drop down menu. 3.0 adds support for the ESP32-C6 module.
  4. Press install
  5. Coffee break while it installs
  6. Tools->Board->esp32 and select the board you are using(ESP32C6 Dev Module)

Pinout

 

 

Code

#include <Wire.h>

//Testmode
#define RELAYONLY
//#define RELAYnBUTTONS
//#define ALL

//Connected BEVRLink boards address
#define BERVLink_8_add 0x20

//Define the used pins
#define SDA 6
#define SCL 7
#define R1 10
#define R2 11
#define R3 22
#define R4 23
#define B1 18
#define B2 19
#define B3 20
#define B4 21

void setup() {
  // put your setup code here, to run once:
#ifdef ALL
  //i2c init, if you have an expansion connected
  Wire.begin(SDA, SCL);
  // Set all relays on address BERVLink_8_add as output, copy this to add another relay
  Wire.beginTransmission(BERVLink_8_add);
  Wire.write(0x00); // Register
  Wire.write(0x00); // GPIO
  Wire.endTransmission();
#endif

  //Relay init if you only have relays
  pinMode(R1, OUTPUT);
  pinMode(R2, OUTPUT);
  pinMode(R3, OUTPUT);
  pinMode(R4, OUTPUT);

#if defined(RELAYnBUTTONS) || defined(ALL)
  //Button init, if you have the ESP32 4+4 board
  pinMode(B1, INPUT);
  pinMode(B2, INPUT);
  pinMode(B3, INPUT);
  pinMode(B4, INPUT);
#endif
}
int relay = 1;
int val = 0;
void loop() {
  // put your main code here, to run repeatedly:
#ifdef RELAYONLY
  //Toggle relays
  val = digitalRead(R1);   // read the relay state
  digitalWrite(R1, !val);  // sets the Relay to the opposite of previous value
  val = digitalRead(R2);   // read the relay state
  digitalWrite(R2, !val);  // sets the Relay to the opposite of previous value
  val = digitalRead(R3);   // read the relay state
  digitalWrite(R3, !val);  // sets the Relay to the opposite of previous value
  val = digitalRead(R4);   // read the relay state
  digitalWrite(R4, !val);  // sets the Relay to the opposite of previous value
#else
  //Read buttons
  val = digitalRead(B1);   // read the input pin
  digitalWrite(R1, val);  // sets the Relay to the button's value 
  val = digitalRead(B2);   // read the input pin
  digitalWrite(R2, val);  // sets the Relay to the button's value 
  val = digitalRead(B3);   // read the input pin
  digitalWrite(R3, val);  // sets the Relay to the button's value 
  val = digitalRead(B4);   // read the input pin
  digitalWrite(R4, val);  // sets the Relay to the button's value 
#endif
#ifdef ALL
  Wire.beginTransmission(0x20);
  Wire.write(0x0A); // Register
  Wire.write(relay); // GPIO
  Wire.endTransmission();

  #Cycle the relay on and off
  relay = (relay << 1) & 0xFF;
  if (relay == 0) relay++;
#endif
  delay(500);
}