Some questions about reading IR signals from remote

I have this remote:

[[[

And some Arduino code has these vars:

int irPin = 2; //Sensor pin 1 wired to Arduino’s pin 2

int statLED = 13; //Toggle the status LED every time Power is pressed

int start_bit = 2200; //Start bit threshold (Microseconds)

int bin_1 = 2250; //Binary 1 threshold (Microseconds)

int bin_0 = 1120; //Binary 0 threshold (Microseconds)

From that pattern image I understand that bin_1 should be 2250 and bin_2 1120 but I don’t know what start_bit should be set to. What is that?

Thanks.](Image 30913)](Image 30910)](Image 30911)

And where did this code come from? Without the reference its is completely out of context.

I seen these 3 variables in most IR codes so I thought it is a common thing.

Here is the full code:

http://www.sparkfun.com/datasheets/Comp … ontrol.pde

/*

SparkFun Electronics 2010

Playing with IR remote control

IR Receiver TSOP382: Supply voltage of 2.5V to 5.5V

With the curved front facing you, pin 1 is on the left.

Attach

Pin 1: To pin 2 on Arduino

Pin 2: GND

Pin 3: 5V

This is based on pmalmsten’s code found on the Arduino forum from 2007:

http://www.arduino.cc/cgi-bin/yabb2/YaB … 76098434/0

This code works with super cheapo remotes. If you want to look at the individual timing

of the bits, use this code:

http://www.arduino.cc/playground/Code/InfraredReceivers

This code clips a lot of the incoming IR blips, but what is left is identifiable as key codes.

*/

int irPin = 2; //Sensor pin 1 wired to Arduino’s pin 2

int statLED = 13; //Toggle the status LED every time Power is pressed

int start_bit = 2200; //Start bit threshold (Microseconds)

int bin_1 = 1000; //Binary 1 threshold (Microseconds)

int bin_0 = 400; //Binary 0 threshold (Microseconds)

void setup() {

pinMode(statLED, OUTPUT);

digitalWrite(statLED, LOW);

pinMode(irPin, INPUT);

Serial.begin(9600);

Serial.println("Waiting: ");

}

void loop() {

int key = getIRKey(); //Fetch the key

if(key != 0) //Ignore keys that are zero

{

Serial.print("Key Recieved: ");

switch(key)

{

case 144: Serial.print(“CH Up”); break;

case 145: Serial.print(“CH Down”); break;

case 146: Serial.print(“VOL Right”); break;

case 147: Serial.print(“VOL Left”); break;

case 148: Serial.print(“Mute”); break;

case 165: Serial.print(“AV/TV”); break;

case 149:

Serial.print(“Power”);

if(digitalRead(statLED) != 1) //This toggles the statLED every time power button is hit

digitalWrite(statLED, HIGH);

else

digitalWrite(statLED, LOW);

break;

default: Serial.print(key);

}

Serial.println();

}

}

int getIRKey() {

int data[12];

int i;

while(pulseIn(irPin, LOW) < start_bit); //Wait for a start bit

for(i = 0 ; i < 11 ; i++)

data = pulseIn(irPin, LOW); //Start measuring bits, I only want low pulses

for(i = 0 ; i < 11 ; i++) //Parse them
{ *
if(data > bin_1) //is it a 1?
data = 1;
else if(data > bin_0) //is it a 0?
data = 0;
else
return -1; //Flag the data as invalid; I don’t know what it is! Return -1 on invalid data
_}
int result = 0;
for(i = 0 ; i < 11 ; i++) //Convert data bits to integer
if(data == 1) result |= (1<<i);
return result; //Return key number
}

[/quote]*_

From a quick look…

start_bit = 4500; Time of the long low that marks the start of the byte

bin_1 = 2250-560; Time between pulses that denote a 1

bin_0 = 1120-560; Time between pulses that denote a 0

Likely adjust these number so they are not on the raw edge.

With these values it just prints same values:

Key Recieved: -1

Key Recieved: 2047

Key Recieved: -1

Key Recieved: 2047

Key Recieved: -1

Key Recieved: -1

Actually with most codes I tried it just printed same values for any key I press.

With a programmable remote I did get to a point where most buttons returned different values, but I didn’t like that because I was unsure of the current protocol.

Do you understand what the code is doing?

Do you understand how the IR sensor is connected to the Arduino?

Are you confident that the sensor is working?

Do you have a scope?

Do you have a logic analyzer?

What have you done to try to solve this problem?

I think only the code (the 3 settings) needs changing. Because …

With another remote, a programmable one has a function that sends different encodings one after another until your device (TV, VCR, ~arduino) reacts, then you click stop on remote and you save the settings. I did that with this remote and I got to an encoding where each button on remote prints a different code on the serial output. So I just know that these remote settings work but I have no idea what encoding this is (so not best way to continue). And I expected the small remote to work too, it says it uses NEC protocol.

That answers the above questions?

adrianTNT:
That answers the above questions?

Not really.

Is your second paragraph your own writting, or was it a quote from someplace? I was not sure.

The fact that you were able to see some encodings in a “seek” mode, does not mean anything. Eventually any demodulator will be tricked by random data. When it did see a code, did it see the code that was sent?

All this indicates is that perhaps you have the IR sensor connected properly. But it would be helpfull to know what that sensor is and how you connected it.

It would seem that you do not understand the code you are modifying or the basics behind it. There are many ways that data can be encoded with light. IR remotes tend to modulate a carrier frequency at something like 40kHz (if memory serves me). The transmitter either send the carrier or it does not. In this case the off time between fixed width pulses is what carries the information. A ‘1’ has a long duration, and a ‘0’ is a short duration.

The next important aspect is a way for the reciever to sync of the data sequence. For that the Tx sends out a long burst (9ms) and then a long gap (4.5ms) followed by a bunch of 0s and 1s. These make up two address and two command bytes.

I do not see anything that sophisticated in the code you posted.

It was not a quote, I was explaining how the remote does that sending, it was a “seek” mode as you said.

Well, what I am trying to do is make it print a different code in serial monitor on each button press, so that I can then make it do anything, but most of the times it just prints same code, eider 0, -1 or same number e.g 2044 on any button press.

Sensor is connected like this: power to +5V on “power” area of Arduino pins, ground right next to it, and the signal is at pin 2 on “Digital” area.

I thought that I just adjust the 3 values and the code can then understand the pattern sent to it.

Maybe anyone has a code that works directly with NEC protocol? I found a NEC protocol but it is not compatible with latest Arduino version, errors on compile.

I think I found the problem.

The sensor that came with the remote is the one in that first post, the receiver/led has 3 pins itself, but I was testing with this, thinking it is the same:

http://www.robofun.ro/image/cache/data/ … 00x500.jpg

But this second one only as 2 pins led, are these^ “analogic” and work different than the one in the first image?

Just counting pins will not tell you much. The fact the first sensor has three leads may not mean they are all used but it might.

An IR sensor is often a phototransistor sensitive to IR light. The more light that hits the sensor the more current can flow through the EC path. The “base” of the transistor is the sensor, but in some cases their may be an electrical connection (3 leads) to allow for various biasings.

If the sensor is not an IR transistor ir will be a PIN diode. In this case it will only have two leads.

What you have is not know by looking at a simple picture. I would GUESS that both are transistors with the second having a built in pull up resistor. I would guess the second would want power, ground, and would generate a sense line. The sense line would not necessarily be a digital line. Its voltage would vary based on the light received. The voltage swing MIGHT be enough to trick the Arduino into thinking it was digital, but it might not. Normaly a conditionlng circuit is needed such as a comparator with a small amount of hysteresis.

Do you have a scope?

Do you understand how these sensors work?

Do you have part numbers and the datasheets for your sensors?

Do you understand how sensor work?

I am trying to.

  • What kind of scope?

  • I don’t have datashets, for the second sensor seller says it prints a values from 0 to 1024 (and it does) based on the amount of IR light and the very short sample code they provide reads by analogRead(0);

For the first sensor (the one in top) that is form eBay and say it works with Arduino, they do provide some docs but most of them are for more advanced projects. One doc is: http://adriantnt.com/temp/Arduino-DVD-kit-Manual.pdf

I am attaching a doc because you asked, I don’t expect someone else to read the docs for me :mrgreen:

The first sensor (IRM 3638) is not a simple photo transistor, but rather a complete receiver. I was not able to quickly find a datasheet, but I would assume the part has AGC and the appropriate detectors for the 38kHz carrier. The output appears to be an open collector digital output. Connecting as per the diagram on page 42 of your pdf would give you a digital signal.

I have no clue about the second sensor. I would suspect that this is just a photo transistor and not a receiver module. You would likely need more circuitry to get this as a true digital signal.

Scope = oscilloscope. A device for visualizing electronic signals.

Having a scope to look at the wave form from the sensor directly can isolate your problem to the sensor or to the software.

I don’t have one of those devices to visualize electrical current. Just that common device to measure voltage and other things.

Before trying again, can you tell me if that component (10KR) that is linked to signal pin of the IR receiver has polarization? Or can it go in any direction? I think I fried the IR receiver that came with the remote, because it made a “puff” :expressionless: so I bought new ones, hopefully they are the same.

Resistors are not polarized. Diodes (and other devices) are.

A “Puff” is a bad thing. Hopefuly you ordered replacement IR receivers and not just photo transistors. That will make your job much easier.

A volt meter can work do some degree. Once you wire up your sensor, monitor the voltage when the sensor is placed inside a box. Then measure when you blast it at clode range with a remote. If you do not see any voltage change from ground to the sensor line, you LIKELY have a problem with the hardware.

Thanks for your time fll-freak, I managed to get it to work.

My initial problem was that I assumed the two sensors/receivers were the same but they were not. Code I was trying was built for the sensor in the very first image but I was trying with the second one (the one that has 2 pin led) that only reads 0-1024 values.

Then of course I puffed the good one, with the new IR receiver it worked from first try and it decodes data properly with IR sample from arduino program. It says “Decoded NEC: FFA25D”, “Decoded NEC: FF18E7”, etc :o