AndroidInfraRed
Open source project for transmitting signals via IR-blasters on Android devices
Install / Use
/learn @OneButtonDeveloper/AndroidInfraRedREADME
Android Infra Red
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
Menu
- Basis
- How to use
- 0. Include the InfraRed library to your project
- 1. Add the following permissions to your AndroidManifest.xml
- 2. Initialize logging
- 3. Initialize the InfraRed class
- 4. Initialize the transmitter
- 5. Initialize the raw patterns
- 6. Adapt the patterns for the device that is used to transmit the patterns
- 7. Implement the start and stop methods
- 8. Transmit the adapted patterns via IR
- In addition
- What's in the box?
Basis
Basic theory
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.
Sequence types
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).

Converting the patterns
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
How to use
0. Include the InfraRed library to your project
- Download the AndroidInfraRed project
- Run the project on a device or an emulator
- Find the infrared-release.aar file in the project folder (infrared/build/outputs/aar/infrared-release.aar)
- Import this file into your own project in Android Studio (File > New > New Module... > Import .JAR/.AAR package)
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.
1. Add the following permissions to your AndroidManifest.xml
<uses-permission android:name="android.permission.TRANSMIT_IR" android:required="false"/>
<uses-feature android:name="android.hardware.consumerir" android:required="false"/>
2. Initialize logging
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
3. Initialize the InfraRed class
Create a new InfraRed object with the parameters Context and Logger
infraRed = new InfraRed(this, log);
4. Initialize the transmitter
TransmitterType transmitterType = infraRed.detect();
// initialize transmitter by type
infraRed.createTransmitter(transmitterType);
The "detect()" method returns the TransmitterType. Possible values:
- Actual - The signals will be transmitted by the ConsumerIrManager
- Obsolete - The signals will be transmitted by a Samsung IR service
- HTC - The signals will be transmitted by the HTC IR SDK
- LG, LG_WithOutDevice - The signals will be transmitted by the QRemote SDK
- Undefined - the "empty" implementation will be used to transmitt the signals
5. Initialize the raw patterns
// 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)
6. Adapt the patterns for the device that is used to transmit the patterns
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.
7. Implement the start and stop methods
@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.
8. Transmit the adapted patterns via IR
private int currentPattern = 0;
@Override
public void onClick(View v) {
TransmitInfo transmitInfo = patterns[currentPattern++];
if (currentPattern >= patterns.length) curr
Related Skills
node-connect
339.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.9kCommit, push, and open a PR
