Practical library series : Infrared ray transmitter and receiver
Languages
日本語版はこちら : http://mbed.org/users/shintamainjp/notebook/remote_ir_ja/
Overview
The most easiest way to get a user input is using push button switches.
However, Many pins on mbed have a peripheral and we can't use their pin if we use the peripherals.
It's OK to add a few switches. But over 10 switches ... It's not good way to get a user inputs. It's not beautiful way for it.
So I created IR remote transmitter and receiver class library.
You can get a user inputs with only a pin if you use this class library.
Now we can control many machines that have a IR port.
Features
The following function is provied on this library.
- Support NEC, AEHA, SONY protocol.
- Support transmit and receive.
- Interrupt based transmitting and receiving.
- This library don't touch the data. So It can be support many protocols. Maybe I think. :)
Library
Structure of the class
The library consist are 2 classes.
You can transmit and receive IR signal if you known these 2 classes.
- TransmitterIR class is for transmitting.
- ReceiverIR class is for receiving.
Projects
The projects are RemoteIRandRemoteIR_TestProgram.
The library project is RemoteIR. This project have not mbed library for general library use.
You can check the functions with RemoteIR_TestProgram.
How to use the library
ReceiverIR class
Create ReceiverIR instance in your program. The instance need a pin name for IR receiver.
#include "ReceiverIR.h" ReceiverIR ir_rx(p15);
And check the state with getState(), if the state indicate ReceiverIR::Received than you can get a data.
RemoteIR::Format format; uint8_t buf[32]; int bitcount; if (ir_rx.getState() == ReceiverIR::Received) { bitcount = ir_rx.getData(&format, buf, sizeof(buf) * 8); }
'format' have a received format type. The last argument of getData is maximum bit length for the buffer.
'bitcount' is received bit count.
You know this library interfaces is very simple.
The example circuit
TransmitterIR class
Create TransmitterIR instance in your program. The instance need a pin name for IR transmitter.
#include "TransmitterIR.h" TransmitterIR ir_tx(p21);
And check the state with getState(), if the state indicate TransmitterIR::Idle than you can write a data for transmit.
RemoteIR::Format format = RemoteIR::SONY; uint8_t buf[] = { 0x80, 0x00 }; int bitcount = 12; if (ir_tx.getState() == TransmitterIR::Idle) { bitcount = ir_tx.setData(format, buf, bitcount); }
'format' is for a transmit protocol type. The last argument of setData is bit length of the data.
This is very simple way to transmit IR signal.
The example circuit
Others
There is a example application.
Research and verification
There are many protocols in IR remote world. In this section, check some protocols with theis signals.
The output signals polarity is negative. The data is LSB first.
NEC
- T=562u[sec]
- Leader: 16T+8T (With data), 16T+4T (Without data => Repeat)
- Data: 32bits fixed length (With data), None (Without data => Repeat)
- Stop bit: Yes
- Data bit: 1T+1T (bit0), 1T+3T (bit1)
The data is ...
Check my library output.
AEHA
- T=425u[sec]
- Leader: 8T+4T (With data), 8T+8T (Without data => Repeat)
- Data: Variable length (With data), None (Without data => Repeat)
- Stop bit: Yes
- Data bit: 1T+1T (bit0), 1T+3T (bit1)
The data is ...
Check my library output.
SONY
- T=600u[sec]
- Leader :4T
- Data: Variable length
- Stop bit: No
- Data bit: 1T+1T (bit0), 1T+2T (bit1)
12bits length
The data is ...
Check my library output.
15bits length
The data is ...
Check my library output.
References
- 赤外線リモコンの主要な通信フォーマット概要 (C)ChaN,2008 (Japanese only)
- SB-Projects: IR remote control: SIRC protocol (English only)
Update history
Version | Date | Description |
1.0.0 | 2010/08/21 | First version. |
1.0.1 | 2010/10/18 | Added schematics of the transmitter and the receiver circuits. |
- | - | - |
- | - |
- |
- | - | - |
- | - | - |
- | - | - |
- | - | - |
- | - |
- |
Special Thanks to...
Special Thanks to Mr.Johan Philippe-san.
5 comments
You need to log in to post a comment
thanks for such a great work! Library really works well.
I would like to ask something about hardware of transmitting IR signal. In the example cicuit, why did you use 5 IR Leds?
I guess it is just for increase the IR transmitting power. I would like to carry the IR signal with cable and there will be one IR LED at the end of the cable. I am going to use
5V circuit, same as your example. So, do you have any idea or suggestion about the long distance(about 30m) transmitting.
thanks in advance,