Experiment #1: Infra-red remote controller

Introduction

Since the diorama’s electronics are to be operated by means of an infra-red remote, it makes sense to test that component first.

A kit was purchased that included a remote control handset and an infra-red sensor. The handset was quite basic, but sufficient for the task in hand:

Remote control handset

The test was performed using an Elegoo Uno R3 using the Arduino-IRremote library.

Circuit

A test circuit was built on a breadboard using the infra-red sensor and a LED that was set to flash whenever a signal was received from the remote. This LED very nearly duplicates duplicates the sensor's built in LED, but has been included because it is unlikely the built in LED will be visible when the sensor is incorporated into the diorama. Furthermore, the final circuit design will most likely only flash the LED when a valid signal is received: it will filter out spurious signals.

The breadboard circuit schematic is shown below:

Test circuit breadboard schematic.

And here's a photo of the cicuit as built:

Photo of test circuit.

Code

The code is available on GitHub in the cahamo/diorama repository.

Two different programs that were used:

  1. ir-sensor-analyser.cpp – Sends full details of the received code to the serial monitor. This code was used to determine the handset type and to work out which codes are emitted by each button.
  2. handset-test.cpp – Using information gleaned from ir-sensor-analyser.cpp this script reports which button is being pressed on the remote control handset. It detects whether the key is being repeated and also reports any spurious readings as “Unknown”. Reports are sent to the serial monitor.

Methodology

The circuit was built as described above.

ir-sensor-analyser.cpp code was compiled and uploaded to the Uno. The handset's buttons were pressed in order from left to right, top to bottom and the serial output that was generated was captured to a text file using CoolTerm. The information gathered was used in the creation of handset-test.cpp.

Next handset-test.cpp was compiled and uploaded to the Uno. Once again the handset's buttons were pressed in the same order as before and the serial output was captured to a second text file.

Results

The text file created when ir-sensor-analyser was run was examined to find which type of unit the remote handset emulates. This was reported as a NEC type. Here's an extract from the text file ir-remote-raw-readings.txt that makes this clear:

⋮
Protocol=NEC Address=0x0 Command=0x45 Raw-Data=0xBA45FF00 32 bits LSB first
Protocol=NEC Address=0x0 Command=0x45 Repeat gap=39600us
⋮

Examination of the text file shows that some buttons repeated while others did not. The above extract demonstrates the output generated when a button was first pressed and when it repeats.

Because the order in which the buttons were pressed was known it became a simple matter to analyse the text file to find the codes of each button: each time the value of the Command entry changes we have a new key being pressed. A copy of the text file named ir-remote-annotated-readings.txt was annotated to make this clearer. Here are extracts from that file for number 1 and OK keys:

⋮
# Number key 1
Protocol=NEC Address=0x0 Command=0x45 Raw-Data=0xBA45FF00 32 bits LSB first
Protocol=NEC Address=0x0 Command=0x45 Repeat gap=39600us
Protocol=NEC Address=0x0 Command=0x45 Repeat gap=95300us
⋮
# OK key
Protocol=NEC Address=0x0 Command=0x1C Raw-Data=0xE31CFF00 32 bits LSB first
Protocol=NEC Address=0x0 Command=0x1C Repeat gap=39600us
⋮

The values gleaned from this file are summarised below. They were used to create a C header file that provides a #define statement for each key, providing a descriptive name for each kay value:

// Number keys
#define REMOTE_KEY_0      0x19
#define REMOTE_KEY_1      0x45
#define REMOTE_KEY_2      0x46
#define REMOTE_KEY_3      0x47
#define REMOTE_KEY_4      0x44
#define REMOTE_KEY_5      0x40
#define REMOTE_KEY_6      0x43
#define REMOTE_KEY_7      0x07
#define REMOTE_KEY_8      0x15
#define REMOTE_KEY_9      0x09

// Hash and star keys
#define REMOTE_KEY_STAR   0x16
#define REMOTE_KEY_HASH   0x0D

// Arrow / cursor keys
#define REMOTE_KEY_UP     0x18
#define REMOTE_KEY_DOWN   0x52
#define REMOTE_KEY_LEFT   0x08
#define REMOTE_KEY_RIGHT  0x5A

// OK key
#define REMOTE_KEY_OK     0x1C

handset-test.cpp includes this header file. It can be found in the cahamo/diorama repository as handset-test.h.

The test file handset-test.txt, produced by running handset-test, confirmed that the key mapping was correct. Here's a copy of the significant part of the file:

⋮
Key pressed: 1
Key pressed: 2
Key pressed: 2 - repeat
Key pressed: 3
Key pressed: 3 - repeat
Key pressed: 4
Key pressed: 4 - repeat
Key pressed: 5
Key pressed: 6
Key pressed: 6 - repeat
Key pressed: 7
Key pressed: 8
Key pressed: 9
Key pressed: *
Key pressed: * - repeat
Key pressed: 0
Key pressed: #
Key pressed: Up-Arrow
Key pressed: Up-Arrow - repeat
Key pressed: Left-Arrow
Key pressed: OK
Key pressed: Right-Arrow
Key pressed: Right-Arrow - repeat
Key pressed: Down-Arrow

The text files referred to above have been zipped up and can be downloaded here.

Conclusion

The tests have proved that the handset works and the output can be interpreted.

The next step is to determine what key sequences will be used to control the various LEDs, motors and sequences and to write code to trigger such events.

Back to main project page