The example below is only one way how to set up the Relay Module.
In this examples we have connected a ESP32 to the BEVRLink Manager ESP32 V2 with BEVRLink 8 Channel Relay V1 12V. 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
- Download latest Arduino IDE
- Tools->Board->Board Manager
- Search for ESP32
- Press install
- Tools->Board->ESP32 Arduino and select the board you are using
Code
#include <Wire.h>
void setup() {
// put your setup code here, to run once:
Wire.begin(21, 22);
// Set all on address 0x20 as output, copy this to add another relay
Wire.beginTransmission(0x20);
Wire.write(0x00); // Register
Wire.write(0x00); // GPIO
Wire.endTransmission();
}
int relay = 1;
void loop() {
// put your main code here, to run repeatedly:
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++;
delay(500);
}
- Connect your board to the USB port of your PC
- Press Upload to compile and upload you code