ir-tv.ino

M5StickC Plus2 (M5Stack) — ESP32-PICO-V3-02 "stick" wearable kit (SKU K016-P2) · File : ir-tv.ino · Language : Arduino · Use case : Éteindre un téléviseur avec la LED infrarouge

The stick's IR emitter LED (G19) replaces remote controls: after capturing your TV's NEC code, the stick fires POWER on every press. The swiss-army knife of non-connected home automation.

Hardware required

An M5StickC Plus2 (ESP32-PICO-V3-02, 135×240 display, A/B/C buttons, passive buzzer on G2, IR + red LED on G19, MPU6886 IMU, microphone, 200 mAh battery). None to transmit; an IR receiver (TSOP) on G35 to capture your own codes.

Wiring

Internal IR LED on G19, aim at the TV sensor (~5 m range). For capture: TSOP1838 on G35, internal pull-up.

How it works

IRremoteESP8266 modulates the NEC frame (9 ms + 562 µs bursts) in interrupt-driven bit-bang on the LED. sendNEC(code, 32) replays the exact captured code. In the Arduino IDE (esp32 package), board « M5StickCPlus2 »; « M5StickCPlus2 » or M5Unified library. On the PMIC-less v2, hold button C for >2 s to power on; HOLD (G4) latches the power.

Going further

A 6-macro menu (TV, set-top, hi-fi) browsed with button B, or automatic repeat in deep sleep.

ir-tv.ino

// LED IR (G19) — bibliotheque IRremoteESP8266 portee ESP32.
// Envoyer POWER NEC : capter d'abord sa telecommande avec le sketch
// IRrecvDumpV2 (recepteur sur G35 en entree) pour les codes reels.
#include <M5Unified.h>
#include <IRremoteESP8266.h>
#include <ir_Send.h>

IRsend irsend(19);            // G19 = LED IR du stick

void setup() {
  auto cfg = M5.config();
  M5.begin(cfg);
  irsend.begin();
  M5.Display.setRotation(1);
  M5.Display.drawString("A = POWER TV", 20, 50, 2);
}

void loop() {
  M5.update();
  if (M5.BtnA.wasPressed()) {
    // Exemple NEC : 0xFFE01F (POWER generique TV) — a remplacer par
    // le code capte sur VOTRE telecommande.
    uint32_t code = 0xFFE01F;
    irsend.sendNEC(code, 32);
    M5.Spk.tone(880, 60);
    M5.Display.fillScreen(TFT_BLACK);
    M5.Display.printf("NEC %06X envoye", (unsigned)code);
  }
  delay(30);
}

← Back to the board