Infra Red Vest Code




Introduction: Infra Red Vest Code

About: Happiness is invisible? Then you cannot sell it? You cannot copy it nor like it:-) You have to arrive there yourself??? But i am just a consumer! See Baudrillard, La societe de consommation, p60....
This instructable is about the code and the devices used for the infra red vest. The sewing you have to invent yourself!

This vest shows the infrared codes which are bombarding us all the time in rooms. Infrared is used for the remote controls of television sets, computers, video/dvd players, lamps, robots, and so on. The codes are sent at a frequency of 38 kHz.

The signal itself is sent within the light spectrum range of infra red which is invisible for the human eye, but visible when you point your digital camera on the led. Cameras but also insects (for instance) do have infra red vision.

Some remote controls are sending several codes, or are in regular contact with the device they are supposed to control.
The codes are just a sequence of 1's and 0's. All the codes are different, some have an elaborate signature at the beginning and the different buttons on the remote control make different endings.

When a infra red code is detected by the vest the led's light up. One shoulder is showing the reception, the other shoulder is showing the code.

The vest provide enough space for a large collection of remote controls as a belt and in the pocket at the right hand side, where also the chips and the batteries are hidden.

Step 1: Test Arduino Code

The challenge is to get all the necessary code on a stand alone atmega328 chip using AVR Gcc.
The problem is, we have the code for the flexible LED strip in C ...

see my instructable:

... but we have the infra red library in Arduino code! Do you think these two bits of code can be merged like that? Wrong!

So first get our infra red sketch working on the Arduino.

In the store you can buy a infra red plug and in the library Ports of there are examples getting the infra red signal.
These is all very convenient, and it works, have not learnt too much! Certainly not how to port it, merge it with other code.

Infra red devices:
You can also, and rather easily, make the receiver and sender yourself. The special IR diode with frequency controller (only receiving the 38 kHz) is about 1.60 euro at and works right away.
The sender needs a 555 timer to send at 38kHz, and you can find the schematics everywhere, at, but also here:

Porting the code
If you start exploring the infra red part of Ports the first thing you notice is the difference in digitalWrite and digiWrite of Jeelabs. Since my goal is AVR C code in a AVR project I have to rewrite the digiWrites in digitalWrites (and then to C in the next step). This is not too difficult, because you can find an easy conversion table at the Jeelabs site:

Functions left
Ports is in C++ and we go to Arduino C, so the c++ objects have to be rewritten. This is also easy, no real object structure is used. So we get a Arduino script with the functions from the library, not using the library Ports anymore.

These are the functions left for infrared use:

configure(uint8_t slot4, uint8_t gap256);

and we need some globals:
uint8_t slot, gap, buf [40];
char fill;
uint32_t prev;

Now this char fill variable works in Arduino code, but not in AVR Gcc! It has to be changed in an int, since it uses negative values...

If you have the infra red diode you can test with the following sketch:

where PC3, or analog 3, or digital 17 is the input pin for the infra red diode device (used here as a digital PIN).
I have used pin 6 and 7 to power my liquid display for testing.

You can see I included libraries used by the functions from the Ports lib:

Otherwise you get errors on ATOMIC STATE etc.

(In this sketch the fill is still a char.)

Checking the infra red code working from the Arduino is easy: just use the serial window.

Checking from avr gcc is not so straightforward, so already in the Arduino Code phase I added a Liquid Crystal to check if the Serial output was also appearing on the small Liquid Crustal screen. (This Liquid Crystal is attached to a Attiny2313.)

Hidden Arduino files
Arduino code is convenient if you compare it to AVR C. This making it easy is the big success of the Arduino! But going one small step further like me, and you have to understand a bit how this success was made possible.
So behind the ARduino srcipt is lain C.
Ports uses also the special Arduino files (hidden in the arduino folders and linked with an invisible makefile).
For instance:
In AVR Gcc i cannot use digitalWrite etc unless either I make my own function or use the Arduino files. Likewise for the function micro's.

Step 2: Re-using Arduino Files for Micro and the Timer

You can get the Arduino functions in AVR gcc if you want to, just copying the parts you need from the Arduino lib inside the Arduino folder. For some reason I keep using the Arduino 018 versions so in the folder, but that does not matter too much.

You can find the files needed in the Arduino folder:

hardware/arduino/cores/arduino (yes two times arduino)
there you find the arduino files, which saves a lot of people learning the C of AVR :-), but at a cost of speed and size.

I needed the micro functions and the interrupt, which I found in wiring.c
I copied: (also copying the variables and defines I needed from wiring.h)

unsigned long millis()
unsigned long micros()

but very important, to get the timer/interrupt started is the:
void init()
There is a lot of code you can skip if you know you use a atmega328.

Then we get this code in two nice files, a source and a header:
(This is a total AVR project you can use for further fun.)

Also included here are, a UART.c and UART.h, for communication with the liquid crystal.

You see I have made the fill an int variable.

Also the analog read is activated for an LDR, and one pin is used to make the other shoulder light up when a signal at 38kHz is received.

initTimers(); is used to start the interrupts, the init() function from wiring.c

In the header file you find the connections with the groups of LED's (flexible LED strips)
//connections to PIN's from the led circle
unsigned char  rows[8] = { 7, 6, 5, 4, 3 , 2, 1, 0 };
unsigned char  cols[8] = { 15, 14, 13, 12, 11, 10, 9, 8 };

The interrupt function is different from the flexible LED strips I used before:

In this function, besides the "Arduino code" I have added my own interruptFie();
This function takes care of the LED block MATRIX activities.

In the setIRPattern(uint8_t count) function you see the matrix for the LED's on the shoulder band.
The 3's indicate the missing LED's form the 64 (I didn't use the full 64 = 8 x 8 LED's in the vest.)

Step 3: One Last Small Challenge

The flexible LED's were functioning a the left shoulder showing the code.
The Atmega328 worked on 2 AAA batteries at 2.8 Volts and the LED's were used without resistors. (On the Arduino with 5V you have to use a resistor not to let your LED's explode.)

I wanted a quick solution at the other shoulder, which will be replaced of course!

So there was a cheap set of 20 LED's running on three AA batteries. Christmas LED's! For about 2 euro's:

Using this is simple, see this tiny instructable for that:

The trick was the voltage: these LED's run on 5V, but the LED's in the vest on 3V. So how do we solve that? The three batteries for the group of LED's can also be connected using only 2 batteries for the atmega328 and the blue LED's!

Batteries are always the hidden challenge of smart textile and other electronic projects.

Step 4: Finishing!

So we have a vest showing the codes of the remote controls trying to control our devices and who knows, trying to control us.

The main thing we learnt is getting functions from Arduino and other libraries to AVR Gcc code projects.

Shortly we will add a nice video!

Be the First to Share


    • Pocket-Sized Speed Challenge

      Pocket-Sized Speed Challenge
    • Audio Challenge 2020

      Audio Challenge 2020
    • Maps Challenge

      Maps Challenge

    9 Discussions

    Dr. dB
    Dr. dB

    8 years ago on Introduction

    What a cool project! (Or a warm one, depending on the garment you chose to use!) It certainly could make laser-tag a lot more WOW, visually speaking...

    However, as popular as 38kHz has become, many I/R remotes operate at other frequencies. Carriers of 32.7k, 35.5k, 37.5k, 39.2k, 56.0k (even as crazy-high as 455.0kHz!) have been, and sometimes still are being, observed.

    Is there a different LDD/pickup ass'y with the bandwidth to handle that kind of spread? With a "wide-open" input device like that, could the system then, somehow, auto-"seek the freq." before reading the code? (This is how the "OmniRemotePro" software works on my ancient Tungsten T PDA, admittedly a bit more machine than the Arduino, even given its silver-whiskered-antique status...)

    Also, waddaya bet you could add a mic, modulate voice into an I/R transmitter and make "two-way clothing" that allows you to talk to each other across line-of-sight ranges?


    8 years ago on Step 2

    Like the project and the links for Arduino / Jeelabs related info, thanks for posting. Can you explain how you get at the C equivalent of arduino code. I also thought this would be a good route on learning C but could not see how to get at the raw files? Thanks, Al


    Reply 8 years ago on Introduction

    C is best learnt in one of the many c tutorials on the internet.
    AVR C is of course dedicated for the avr chip, this is a link to basic C scripts for the atmega328 (or other):

    the scripts can be uploaded using a programmer.
    The dedicated part consists of the many registers and their names.
    If you understand this part, you can put this code also in the Arduino scripting window, it works! (Mind the setup and loop seperation.)
    The files of the Arduino "hiding" this same C code are in the Arduino folder, hardware, arduino....
    You could also write C in Eclipse, Google for links.


    8 years ago on Introduction

    ER,whaddoes it do? Have I missed something here.....................??


    Reply 8 years ago on Introduction

    the vest reacts to remote controls sending infrared code at 38 kHz. The Led's show this code....


    8 years ago on Introduction

    I like the old Apple remote you tested with- classic!


    8 years ago on Introduction

    I really hope you aren't one of those people who think thse signals are "dangerous" and made it to show people how many there are around.


    Reply 8 years ago on Introduction

    Not at all! I use also RF in clothing (sending poetry around, or recycling received messages and sending greens words from the reassembled letters back). The difference for me is that infra red "feels soft" because it is always contained in a room, the living space, while RF penetrates walls, buildings etc. The "softness" of infra red is (for me personally) related to the softness of fabric. That's why it suits me.


    8 years ago on Introduction

    It looks like something you would see in startrek