the old infrared chestnut!

I have read and read threads on IR receivers.. but am stuck!

i have been using code similar to on this thread: http://forum.arduino.cc/index.php?PHPSESSID=kkhq3lnr346iges3mafn6dr692&topic=17965.30

im using this code from the 1st post:

int pwr_high = 4;  //Sensor pin 1
int pwr_low = 3;    //Sensor pin 2
int ir_pin = 2;    //Sensor pin 3, the data pin
int data[12];
  
void setup() {
  pinMode(pwr_high, OUTPUT);    
  pinMode(pwr_low, OUTPUT);
  pinMode(ir_pin, INPUT);
  digitalWrite(pwr_high, HIGH);    //Sensor pin 1 always high
  digitalWrite(pwr_low, LOW);      //Sensor pin 2 always low
  Serial.begin(9600);
}

void loop() {
  data[0] = pulseIn(ir_pin, LOW);    //Start measuring bits --the sensor defaults high, goes low on infrared 
  data[1] = pulseIn(ir_pin, LOW);
  data[2] = pulseIn(ir_pin, LOW);
  data[3] = pulseIn(ir_pin, LOW);
  data[4] = pulseIn(ir_pin, LOW);
  data[5] = pulseIn(ir_pin, LOW);
  data[6] = pulseIn(ir_pin, LOW);
  data[7] = pulseIn(ir_pin, LOW);
  data[8] = pulseIn(ir_pin, LOW);
  data[9] = pulseIn(ir_pin, LOW);
  data[10] = pulseIn(ir_pin, LOW);
  data[11] = pulseIn(ir_pin, LOW);
  
  Serial.println("-----");    //Send them all
  Serial.println(data[0]);
  Serial.println(data[1]);
  Serial.println(data[2]);
  Serial.println(data[3]);
  Serial.println(data[4]);
  Serial.println(data[5]);
  Serial.println(data[6]);
  Serial.println(data[7]);
  Serial.println(data[8]);
  Serial.println(data[9]);
  Serial.println(data[10]);
  Serial.println(data[11]);
}

but am falling over as my serial monitor is throwing garbage at me :( this is what im getting back for a simple button press....

ÖÖçÿ?ÎÖK?ø?!!¨ûgëÄ:Hk:HkHÄ!?:hZe:hZeÄKj¤Hê:x[eJÄL?:xJ:xJ?LÄ??:H[e:H[e
ÄZk¤H
Ä¥)Ä¥Ä¥Ä­HÄ­HÄ­½Ä­½Ä¥?Ä¥?Ä­µÄ­µÄ­?Ä­?ĵ!ĵ!ĽĽĽĽĵ?ĵ?Ľ!Ľ!Ľ¥Ľ¥Ä¥?Ä¥?Ä­¥Ä­¥Ä­
Ä­
ÄJ)ÄJ)ÄJµÄJµÄJµÄJµÄJJÄJJÄZ)$ÄZ)ÄkJL?:hJ?:hJ?L?L?:h¥?:h¥?J?J?:xJ?:xJ???:xJK¤
?ÄJ
ÄJ
ÄJÄJÄJÄJÄÄÄïÄHÄJÄJÄJJÄJJÄ
JÄ
JÄ?JÄ?JÄL?ÄL?Ä
æ
Ä??Ä??ÄK)ÄK)Ä[[:hµ¥¬?
ÄK¥ÄKZ:hJ¥¬?J?Ä[!'ÄkJ:hKJ¬?ÄkÄ{J:h
?J?J?:h[¥¤??LÄ{
Ä{
ÄK¥ÄK¥Ä?!!¸­?þÎÖK?ø

could some one please bash some stupidity out of me and tell me what im doing wrong please!

First check that the baud rate in Serial.begin() is the same as in Serial monitor (bottom right of Serial monitor screen).

groundfungus:
First check that the baud rate in Serial.begin() is the same as in Serial monitor (bottom right of Serial monitor screen).

good call, i was one baud rate too high, but even with 9600 im getting :

Wþ|×µ ° ° ¸ ?¤$?ÊI ?	 ¢p?4Ä¢P?²P?¢X?$u?pX(pP<?¢T1f?P©¨?0¢x°9?ªP?4?0Ph1P(ÞÙ

which is still a load of smelly stuff

I have set my com port up at COM9, havent had an issue with this in the past, but this is my first go at IR

I use the IRremote (or the later IRlib) library with my remote projects. http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html The library has examples to help understand how the remotes encode data. I don't know what that code is trying to accomplish, but using the library you can get consistent usable data from the remote and if your goal is to control devices via IR from the Arduino the libraries will make it less difficult.

thanks, i was just looking at that…

In your code you state:

#include <IRremote.h>

int RECV_PIN = 11;
[b]IRrecv irrecv(RECV_PIN);[/b]
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}

Now this is for receive… but what does the IRrecv (highlighted in bold) . this is not valid is it ? or am i being blond ?

That creates an instance (variable) of the IRrecv class called irrecv. That is called a constructor. Male sure that the value of RECV_PIN is the number of the input pin connected to your decoder.

GroundFungus.

Thanks for your reply.

one this that is still stumping me is the fact that your arduino compiler wont compile that line : IRrecv irrecv(RECV_PIN); says "IRrecv does not name a type"

ok, maybe scrap my previous post...... its all compiled but i still get characters i do not understand....

for a simple 'power on' using a sony remote im getting this responce from the COM9 port:

Áû@??!Q8èßA"Pp?¢P??°µ    ²\$pT?4?eÐ  ÀÁ

Baud is right, pin input is right, no other software loaded on the arduino for it to mess up.

Post the code (in cod tags please). Are you running one of the examples?

im using this example from the IR library:
im using a mega 2560 if that makes any difference.

/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}

if i run that and press the power button i get the garbage from my previous post

Do you have any data on the IR decoder (receiver)? The ones that I have worked with invert the data before sending the data to the arduino and the library expects that. I have to wonder if yours doesn't invert so confuses the library. I am out of ideas otherwise.