This article covers the connection, code and use of relays with the ESP32. While some slight changes may be needed, the information provided here will generally work with other MCUs and SBCs, such as the ESP8266, most Arduino boards and even the Raspberry Pi.