Go Down

Topic: Forming strings from digitalRead input and comparing them (Read 2878 times) previous topic - next topic


New member signing in! Hopefully this is the correct section to post and this hadn't bee discussed too many times earlier.

I have an Arduino Duo. My project is to make a small stand-alone ir-remote converter. I have a Bang & Olufsen audio system. I would like the converter to listen to the IR data, note when there is a command sent, capture a pre-set length of bytes and compare this to preset strings (=to identify certain commands). Then the program should react in a certain way (as a result, to send out another IR command to control another devices).

I have an external IR receiver from a B&O link room system that has a receiver and processor. It works on 5v DC that I supply from the Arduino. Data output is connected to a digital pin 2. When I send an IR command and keep reading the digital pin 2 I got a series of 0s and 1s depending on a command.

Fe. running this:
Code: [Select]
void setup() {
  pinMode(2, INPUT);

void loop() {
  int data = digitalRead(2);
  Serial.println(data, DEC);

I got stuff like this: 01111111101110110110110110110110111101100110110110110110 (with infinite number of 1s (it might be good idea to invert the read as 1 seems to indicate low now) before and after.)

How can I capture a string of the input? The commands are quite different and I wouldn't need many so comparing only the beginning of a command string (like 5-10 characters) should be enough. Or should I approach this in some other way? I will get on to the IR sending (fe. Apple Remote commands to control my MacBook) later when I get the receiving part working.


Typically you can use Shirriff's IRremove library to decode incoming IR signals. The IR is encoded in particular ways. You can directly read the encoded 0 and 1 but you can also get the decoded result easily from his library:

Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter


Hi. Thanks.
I did try the IRremove earilier but couldn't get it working for some (IDE) reason. The version you linked works. However the B&O remote codes are longer than what many other remotes use. When I run the IRrecord and capture a signal, I receive it in two separate parts as the code cuts it too early.

For example; I press CD on remote and serial monitor shows:

Received unknown code, saving as raw
m1450 s1650 m1450 s1600 m1450
Received unknown code, saving as raw
m1450 s1600 m1450 s4700 m1450

When I try to send it out, it doesn't work(=control the music system) as the software sends only the last half of the original code. I will try flipping thrue the IRremote.h to see if there some useful variables.


Jan 06, 2013, 12:53 am Last Edit: Jan 06, 2013, 12:57 am by christianlykke Reason: 1

The Bang & Olufsen infrared receiver is very sensitive, meaning that it picks up a lot of noise. That is why it looks like the code cannot be in one buffer in the IRremote Library. Also the B&O infrared command uses biphase mark code, which is why the commands all look the same in the library.

However, a infrared command from the B&O remote only consists of 17 bits (1 bit for link, 8 bits for address and 8 bits for the command)

The data from the infrared receiver must be filtered in order to decode the actual command.

You can find my program for decoding the data from the infrared receiver on my Github account:

I am planning on implementing support for receiver's 4-key "keyboard" and 2 LEDs in a future version.

The decoder has been implementing using Timer1 so it should be possible to run the IRremote library "Beomote" library simultaneously.

If you have any questions, feel free to contact me at christian.lykke@gmail.com

There is no processor in the infrared receiver  ;)


Why in the world would you ever turn that into a string?

It's all ones and zeros.  Store it in a binary int type long enough to hold it.  Probably a long.  Then work with it as numbers.  That would be so much easier.  You could use hex in the code to make it easier to read for you, but the computer wouldn't care.  Or better yet, you could make an enum type to hold all the values and give them names that you could use in your code like UNIT_ON or UNIT_OFF.

|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Go Up