Open source project for transmitting signals via IR-blasters on Android devices
Created in Android Studio
Supports Samsung, HTC, some LG devices with IR
Contains: - SampleApplication - InfraRed library
Email: one.button.developer@gmail.com
In order to remotely control a device via IR, you require a transmitter (mobile phone with IR blaster) and a control signal sequence that you want to send. This sequence is the key to the function that the device is supposed to perform (e.g. the function of a TV to turns itself on). The built-in IR receiver of the controlled device analyzes all incoming signals. When they match a pattern of a particular function, the devices calls that function.
The control signal sequence consists of two parameters: The frequency (in Hertz) and the pattern, which is a time sequence of ON/OFF signals on the specified carrier frequency. Such patterns can be found on the Internet.
The pattern is pictured by a sequence of numbers either of the hexadecimal (HEX) or the decimal (DEC) numeral system.
Here's an example:
Frequency:
33000 Hertz (33KHz)
Patterns:
0) 0x01f4 0x1c84 0x01f4 0x00c8 or (01f4 1c84 01f4 00c8)
1) 500 7300 500 200
2) 17 241 17 7
The main difference between the patterns in this example is their notation. Each number in the pattern describes the duration of a single ON/OFF signal, only that patterns 0 and 1 describe it in microseconds, while patterns 2 describes it in cycles.
One cycle always consists of an an ON and an OFF signal (the image below shows cycles with a frequency of 40000 Hz).

The length of a single period T in microseconds equals 1 000 000 (1 second in microseconds) divided by the frequency f (in Hertz)
T = 1 000 000 ms / f
For example
T = 1 000 000 ms/ 33000 Hz ≈ 30.3 ms
To covert a microsecond pattern to a cycle pattern, divide each value by T
To convert a cycle pattern to a microsecond pattern, simply multiply each value by T
Tip! Your can download the infrared-release.aar file from releases
Known issue! One of the project files contains broken characters. Just rename it again.
<uses-permission android:name="android.permission.TRANSMIT_IR" android:required="false"/>
<uses-feature android:name="android.hardware.consumerir" android:required="false"/>
You can choose between printing your logs to an EditText view (LogToEditText), the LogCat console (LogToConsole) and not logging at all (LogToAir)
// print log messages to EditText
EditText console = (EditText) this.findViewById(R.id.console);
log = new LogToEditText(console, TAG);
// print Log messages with Log.d(), Log.w(), Log.e() (LogCat)
// LogToConsole log = new LogToConsole(TAG);
// Turn off logs
// LogToAir log = new LogToAir(TAG);
LogToEditText is the default option
Create a new InfraRed object with the parameters Context and Logger
infraRed = new InfraRed(this, log);
TransmitterType transmitterType = infraRed.detect();
// initialize transmitter by type
infraRed.createTransmitter(transmitterType);
The "detect()" method returns the TransmitterType. Possible values:
// initialize raw patterns
List<PatternConverter> rawPatterns = new ArrayList<>();
// Canon
// rawPatterns.add(new PatternConverter(PatternType.Intervals, 33000, 500, 7300, 500, 200));
// Nikon D7100 v.1
rawPatterns.add(new PatternConverter(PatternType.Cycles, 38400, 1, 105, 5, 1, 75, 1095, 20, 60, 20, 140, 15, 2500, 80, 1));
// Nikon D7100 v.2
rawPatterns.add(new PatternConverter(PatternType.Cycles, 38400, 77, 1069, 16, 61, 16, 137, 16, 2427, 77, 1069, 16, 61, 16, 137, 16));
// Nikon D7100 v.3
rawPatterns.add(new PatternConverter(PatternType.Intervals, 38000, 2000, 27800, 400, 1600, 400, 3600, 400, 200));
// Nikon D7100 v.3 fromString
rawPatterns.add(PatternConverterUtils.fromString(PatternType.Intervals, 38000, "2000, 27800, 400, 1600, 400, 3600, 400, 200"));
// Nikon D7100 v.3 fromHexString
rawPatterns.add(PatternConverterUtils.fromHexString(PatternType.Intervals, 38000, "0x7d0 0x6c98 0x190 0x640 0x190 0xe10 0x190 0xc8"));
// Nikon D7100 v.3 fromHexString without 0x
rawPatterns.add(PatternConverterUtils.fromHexString(PatternType.Intervals, 38000, "7d0 6c98 190 640 190 e10 190 c8"));
The PatternConverter can be used to easily define and convert IR patterns between the different patterns types (Cycles and Intervals in ms)
PatternAdapter patternAdapter = new PatternAdapter(log);
// initialize TransmitInfoArray
TransmitInfo[] transmitInfoArray = new TransmitInfo[rawPatterns.size()];
for (int i = 0; i < transmitInfoArray.length; i++) {
transmitInfoArray[i] = patternAdapter.createTransmitInfo(rawPatterns.get(i));
}
this.patterns = transmitInfoArray;
PatternAdapter automatically detects the device's manufacturer (LG/HTC/Samsung) and uses that information to determine how the raw patterns have to be converted in order to be compatible with the transmitter of the used device.
@Override
protected void onResume() {
super.onResume();
infraRed.start();
}
@Override
protected void onDestroy() {
super.onDestroy();
infraRed.stop();
if (log != null) {
log.destroy();
}
}
Always call the start() method before transmit IR signals and call the stop() method when you are done.
It is a good idea to call them in the onCreate/onDestroy or onResume/onPause methods.
private int currentPattern = 0;
@Override
public void onClick(View v) {
TransmitInfo transmitInfo = patterns[currentPattern++];
if (currentPattern >= patterns.length) currentPattern = 0;
infraRed.transmit(transmitInfo);
}
Now we can send IR signals (TransmitInfo) to the device we want to control
Examples for the individual steps can be found in this project
The sample project gives you an idea how the infrared library is supposed to be used. The project contains an activity (MainActivity.java) with a predefined layout (activity_main.xml). The layout contains a console (EditText) and a IR button.
The onCreate() method contains the full initialization of the InfraRed library
When you run the application, the console will show you what is happening inside the library. When you click on the button, the IR blaster on your device will send a IR signal, of course only if your device is supported by the library.
Please note that you wont get any runtime exceptions because your device is not supported.
Logging to a EditText can be quite useful when you want to understand what's happening on your customer's devices. I often send special .apk files to users in order to obtain a log from their devices.
This library allows you to easily create raw IR signals in code, to detect device types and adapt raw signals for specific devices, to detect the devices' IR transmitters and to use them to send the adapted IR signals to a devices with a IR receiver.
The Library consists of several packages that are explained below.
Provides different ways to log data. All classes in this package inherit from the Logger class.
LogToConsole is useful when your can debug the application on a device that is connected to an IDE with LogCat.
LogToEditText can be used to to display the log messages on the user's screen.
LogToAir won't log anything (you can apply this in your application's release version)
Enum PatternType tetermines the type of the IR signals in an integer array (a single value in the array is either the number of cycles or
$ claude mcp add AndroidInfraRed \
-- python -m otcore.mcp_server <graph>