NC
, NO
, and COM
. It can help us control the ON/OFF of AC-220V@3A
/ DC-30V@3A
circuits. To use it, simply configure the IO pin to HIGH/LOW to control the switch. When the control pin outputs LOW, NO and COM are disconnected, and NC and COM are connected. When the control pin outputs HIGH, NO and COM are connected, and NC and COM are disconnected.#include <M5Unified.h>
#define RELAY_PIN 9
bool relay_no_status = false;
void setup()
{
M5.begin();
M5.Display.setFont(&fonts::FreeMonoBold12pt7b);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);
M5.Display.setCursor(10, 40);
M5.Display.println("Relay NO & COM Open");
}
void loop(void)
{
M5.update();
auto t = M5.Touch.getDetail();
if (t.wasClicked() || M5.BtnA.wasClicked()) {
relay_no_status = !relay_no_status;
if (relay_no_status) {
M5.Display.clear();
M5.Display.setCursor(10, 40);
M5.Display.println("Relay NO & COM Closed");
digitalWrite(RELAY_PIN, HIGH);
} else {
M5.Display.clear();
M5.Display.setCursor(10, 40);
M5.Display.println("Relay NO & COM Open");
digitalWrite(RELAY_PIN, LOW);
}
}
}
For CoreS3, press and hold the reset button (for about 2 seconds) until the internal green LED lights up, and then release it. This indicates the device is in download mode and ready for programming.
The Unit Relay switch can be controlled through the touchscreen, enabling load power control.