ESPHome Remote Receiver Test: Simplistic Shooting Game

I salvaged an infrared remote control receiver from a Roku Premier 4620X (“Cooper”) and dumped out some codes using an ESP32 microcontroller running ESPHome software’s Remote Receiver component. This is great, but before I moved on, I ran a simple introduction to actually using it. The “Hello World” of ESPHome remote receiver, so to speak.

The idea is a very simple shooting game. I will add an LED to the breadboard connected to GPIO 18. I will count to five seconds in an on_loop lambda and illuminate the LED using ESPHome GPIO output component. Once illuminated, it will wait for the signal sent by a Roku RC108 remote when the “OK” button is pressed. Once received, I will darken the LED for five seconds before turning it back on. With this very simple game I pretend to “shoot out” the light with my remote.

It was silly and trivially easy as far as shooting games go. Infrared remote controls are designed so the couch potato doesn’t have to aim very accurately for them to work. The emitter sends out the signal in a very wide cone, and the receiver is also happy to receive that signal from within a wide cone. If I am to evolve this into an actually challenging target practice contraption, I would have to figure out how to narrow the cone of effectiveness on the emitter, or the receiver, or both!

But that was not the objective today. Today it was all about dipping my toes in that world before I continued with my Roku teardown. I wanted to keep the hardware trivial and the code simple, so here is the ESPHome code excerpt for this super easy shooting game:

esphome:
  on_loop:
    then:
      - lambda: |-
          if (id(ulNextOn) < millis())
          {
            id(led_01).turn_on();
          }

status_led:
  pin:
    number: 2

output:
  - platform: gpio
    pin:
      number: 18
      inverted: true
    id: led_01

globals:
  - id: ulNextOn
    type: unsigned long
    restore_value: no
    initial_value: '0'

remote_receiver:
  pin:
    number: GPIO36
    inverted: true  
  dump: nec
  tolerance: 10
  on_nec:
    then:
      - lambda: |-
          unsigned long ulTurnOff;
          
          if (0x55AA == x.command)
          {
            id(led_01).turn_off();
            id(ulNextOn) = millis() + 5000;
          }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s