About data transfer through an audio jack

Original author: Liang Lee
  • Transfer
  • Tutorial
One of the important interfaces on mobile devices and tablet computers is the headphone / microphone jack. However, you should not think that it is intended only for speaker-headphone-microphone speakers - it can also be used for data transfer. We’ll talk about this today. Alternative ways to use the audio jack to connect third-party devices are constantly updated. Peripheral devices, for example, the iHealth Lab glucometer (which detects blood sugar), Irdroid - an IR remote control for remote control of the TV, set-top boxes and sound components and Flojack

- NFC reader (organizing radio communications between nearby mobile devices) - all this has become possible thanks to the presence of an audio connector.

Since the market for mobile and peripheral devices has a large number of potential customers, I believe that the headphone jack will be the main port for transmitting information in the near future. In this article I will talk more about this feature.


The audio jack interface has two standards: OMTP and CTIA . OMTP is an international standard; ATIS is the American standard used in devices such as the Apple iPhone and iPad. They differ in V-microphone, as well as the location of the ground; differences are shown below:


How data is transmitted

When we send 0x00FF data, the first step is to convert the digital data into analog. Therefore, you need to modulate the value of the data. As a rule, a sine wave carrier for an analog signal is used for this.

FSK modulation of the signal The

second step in Android devices is to call the audioTrack API , the function used to play. The following code sends data to the buffer using the audioTrack function for this.

public void send(byte[] bytes_pkg) {
        int bufsize = AudioTrack.getMinBufferSize(8000,
        AudioTrack trackplayer = new AudioTrack(AudioManager.STREAM_MUSIC,
                8000, AudioFormat.CHANNEL_OUT_MONO,
                AudioFormat.ENCODING_PCM_16BIT, bufsize, 
        trackplayer.write(bytes_pkg, 0, bytes_pkg.length);

Data retrieval

In the receiver, it is necessary to translate the analog signal into a data value, demodulate the signal to remove the incoming signal, and decode the data in accordance with the protocol. The protocol may be in the form of public data or private.

Signal demodulation

On Android systems, we use the audioRecord API function for recording sound:

public void receive(){
		int minBufferSize = AudioRecord.getMinBufferSize(AUDIO_SAMPLE_FREQ, 2,
		AudioRecord ar = new AudioRecord(MediaRecorder.AudioSource.MIC,
				AudioFormat.ENCODING_PCM_16BIT, minBufferSize);

How to extract the energy of sound signals

Obviously, to accumulate on the power circuit for peripheral devices, a certain power is required. For example, an L channel transmits data. The R channel sends a stable square or sine signal. These signals can be converted by the MCU (Micro Controller Unit) and several sensors.

Success Story: IR Peripherals

Androlirc is a project based on Github. Its functions can be used to send the infrared interface of the audio connector to the application. You can study this project to understand the process of exchanging data through the audio jack. Androlirc uses LIRC-Library to create entries in the data buffer. This library is an infrared library for Linux that supports several types of interfaces, for example, USB, audio jack, etc. Androlirc allows you to use the LIRC library to accumulate data. You can find many infrared coding types on the market, such as the RC-5 and RC-6 protocols. In the above example, we use the RC-5 protocol to control the TV. First, we must modulate the value of the data using a 38k sine wave to generate buffer data. Then we use the Android audio API to play sound from the data buffer. At the same time, we use one of two channels to reproduce a sine or square power signal on the equipment of peripheral devices.

Success Story: Audio Connector for Developers

A new solution from NXP Semiconductors, Quick-Jack is a prototype-based device called Hijack. Hijack is a project by students from the University of Michigan. The Hijack platform allows you to create a new class of compact, cheap, phone-oriented peripheral sensors with support for plug-and-play operations. You can use the NXP Quick-Jack boards to create a prototype.

Below is a smartphone that displays indoor temperature using a temperature sensor based on an audio jack. Through it, the LED indicator of peripheral devices is controlled using an application based on the Android OS.

Temperature value obtained using Quick-Jack; through it, the LED indicator is controlled

Free information

Wearable devices with the ability to connect peripherals are increasingly appearing in the consumer market. The audio connector as a function for data transfer is used by ODM manufacturers more and more actively. Perhaps in the future, the function of transmitting data through this connector will be supported by mobile OS by default.

about the author

Liang Li received a master's degree in signal study and data processing from Changchun University of Technology. He joined Intel in 2013 as an Android engineer in the Chinese division. Now he is creating functions that would allow Android to get competitive advantages (for example, displaying multiple application windows at the same time, etc.).

Related Links

Also popular now: