DIYables IR Controller - DIYables_IRcontroller_17.getKey()

Description

Check if there is a key pressed on 17-key IR remote controller and received by IR receiver.

Syntax

Key17 getKey();

Parameters

None

Return

  • Key17::NONE: if there is no key presed on IR controller and received by IR receiver.
  • One of the following values corresponding with the key on the IR remote controller:
    • Key17::KEY_1
    • Key17::KEY_2
    • Key17::KEY_3
    • Key17::KEY_4
    • Key17::KEY_5
    • Key17::KEY_6
    • Key17::KEY_7
    • Key17::KEY_8
    • Key17::KEY_9
    • Key17::KEY_STAR
    • Key17::KEY_0
    • Key17::KEY_SHARP
    • Key17::KEY_UP
    • Key17::KEY_LEFT
    • Key17::KEY_OK
    • Key17::KEY_RIGHT
    • Key17::KEY_DOWN
  • Key17::UNKNOWN: if it received a key that is not from the 17-key IR remote controller

Example

Hardware Required

1×Arduino UNO or Genuino UNO
1×USB 2.0 cable type A/B
1×IR Kit (Remote Controller and Receiver)
1×CR2025 Battery
1×Jumper Wires
1×(Recommended) Screw Terminal Block Shield for Arduino Uno
1×(Recommended) Breadboard Shield For Arduino Uno
1×(Recommended) Enclosure For Arduino Uno
Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.

Wiring Diagram

Arduino IR Remote Control Wiring Diagram

This image is created using Fritzing. Click to enlarge image

Arduino Code

/* Created by DIYables This example code is in the public domain Product page: https://diyables.io/products/infrared-ir-remote-control-kit-with-17-key-controller-and-receiver */ #include <DIYables_IRcontroller.h> // DIYables_IRcontroller library #define IR_RECEIVER_PIN 7 // The Arduino pin connected to IR controller DIYables_IRcontroller_17 irController(IR_RECEIVER_PIN, 200); // debounce time is 200ms void setup() { Serial.begin(9600); irController.begin(); } void loop() { Key17 command = irController.getKey(); if (command != Key17::NONE) { switch (command) { case Key17::KEY_1: Serial.println("1"); // TODO: YOUR CONTROL break; case Key17::KEY_2: Serial.println("2"); // TODO: YOUR CONTROL break; case Key17::KEY_3: Serial.println("3"); // TODO: YOUR CONTROL break; case Key17::KEY_4: Serial.println("4"); // TODO: YOUR CONTROL break; case Key17::KEY_5: Serial.println("5"); // TODO: YOUR CONTROL break; case Key17::KEY_6: Serial.println("6"); // TODO: YOUR CONTROL break; case Key17::KEY_7: Serial.println("7"); // TODO: YOUR CONTROL break; case Key17::KEY_8: Serial.println("8"); // TODO: YOUR CONTROL break; case Key17::KEY_9: Serial.println("9"); // TODO: YOUR CONTROL break; case Key17::KEY_STAR: Serial.println("*"); // TODO: YOUR CONTROL break; case Key17::KEY_0: Serial.println("0"); // TODO: YOUR CONTROL break; case Key17::KEY_SHARP: Serial.println("#"); // TODO: YOUR CONTROL break; case Key17::KEY_UP: Serial.println("UP"); // TODO: YOUR CONTROL break; case Key17::KEY_DOWN: Serial.println("DOWN"); // TODO: YOUR CONTROL break; case Key17::KEY_LEFT: Serial.println("LEFT"); // TODO: YOUR CONTROL break; case Key17::KEY_RIGHT: Serial.println("RIGHT"); // TODO: YOUR CONTROL break; case Key17::KEY_OK : Serial.println("OK"); // TODO: YOUR CONTROL break; default: Serial.println("WARNING: undefined command:"); break; } } }

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit

※ OUR MESSAGES