IR receiver decoding

I have a SEN-10266 IR Receiver Diode - TSOP38238 from Sparkfun. I am trying to capture IR codes from my remote using an Arduino UNO R3. I have the ground and power from the IR receiver connected to the Arduino and the "out" from the receiver going to a PWM pin. I cannot see any codes coming across the serial monitor after I upload Ken Sherriff's IR sketch. Is it possible I am using the wrong receiver? I looked at the data sheet for the receiver and believe I have it hooked up correctly. Please advise. Thank you very much!
Shawn.

Have you read this..

http://allaboutee.com/2011/07/10/arduino-infrared-sensor-code/
The connection

int irPin=2;
 
void setup()
{
 pinMode(irPin,INPUT);
 Serial.begin(9600);
}
 
void loop()
{
 
  if(pulseIn(irPin,LOW))
  {
     //button pressed 
     delay(100);
     Serial.println("You pressed a button");
  }
  
}

I believe you want the pinMode to be INPUT_PULLUP to keep it from floating.

Yes but I want to decode the buttons that are pressed so that I can use them in a remote control car sketch (to turn servos).

You probably want to just light an LED when the IR receiver pin goes LOW right now to confirm it is working as intended. Then worry about decoding once that is confirmed.

Tylernt: I'm not sure what you mean by INPUT_PULLUP. Is that instead of just INPUT for the PinMode? At this point I think I have the hardware configured correctly it's just the minimum amount of code I need to either decode the pulses or get an led to blink indicating it has received the code. Could you direct me to a link that explains this concept at a very simple level :slight_smile:
Thanks!

Pins that are floating INPUTs can receive random RFI from electromagnetic waves flying about from the Sun, cell phones, etc. Using INPUT_PULLUP will help keep this noise from causing false triggers.

I use something like for troubleshooting purposes

const byte ir_rx = 12;
const byte indicator = 13;

void setup()
{
pinMode(ir_rx, INPUT_PULLUP);
pinMode(indicator, OUTPUT);
}

void loop()
{
if(digitalRead(ir_rx) == LOW)
  {
  digitalWrite(indicator, HIGH);
  }
else
  {
  digitalWrite(indicator, LOW);
  }
}

Thank you for the suggestion. Unfortunately I am still unable to receive any ir codes from multiple remotes. Could you think of anything else I may be doing wrong? Thanks for your help.

Please clarify:

  1. You are unable to get the LED to light at all using the troubleshooting sketch posted
  2. The troubleshooting sketch does indeed light the LED when buttons are pressed on the remote, but you are having trouble decoding the pulses into a readable code.

tylernt: I uploaded the troubleshooting code you provided but receive an error. Looks like a syntax error just not sure how to fix it. The error is "expected unqualified id before '{' token". The curly bracket under the void loop is highlighted. I was just trying to, as you suggested, light an led with an ir remote control. Again thanks for your help.

The error is "expected unqualified id before '{' token".

This line:

void loop();

.... should not have a ; on the end. Should be:

void loop()

Thanks JimboZA, post edited.

Ok guys... I used the troubleshooting code and was unsuccessful at getting the led to light up. I used several different remotes. I'm thinking either the pin or the ir receiver is bad. Do you know of anyway that I can test the ir receiver to see if it's bad?

The troubleshooting sketch is the best one I know of to test with. Assuming you have the leftmost (looking at the rounded side) pin 1 of the receiver connected to Arduino pin 12, the middle receiver pin 2 connected to ground, and the right receiver pin 3 connected to +5VDC, then... yeah, I'd say it's toast.

Thanks!!!! After all that it was toast :wink: I was able to take an ir receiver out of a broken tv and it worked like a charm. I plan on using a sketch I found to use the ir codes to start and stop motors (remote care). In your opinion what is the best and safest way to hook up a servo to an arduino uno? I was planning on just plugging in the signal wire to one of the PWM pins and the ground and power to an external power source. If I do it that way do I need to use a relay or a transistor? Do I need to connect the ground from the arduino to the ground of the external power source? I feel like you guys have answered this before but I get so confused?? Thanks for hanging in there with me.

Servos require PWM of a very specific frequency and duty cycle. You want to use the Servo library, not analogWrite().

You can directly connect the Arduino Servo output pin to the servo's input signal wire. Although, connecting through a 220ohm resistor as insurance against oopsies shouldn't hurt.

Yes, the servo's and the Arduino's grounds do need to be connected to each other.

Thank you! What is really confusing me is that on the arduino.cc website http://arduino.cc/en/Tutorial/Sweep it shows a servo's power being connected directly to an arduino?? I thought that the arduino should not "power" any component other than signal wires and maybe led's?? I also noticed the frtizing examples have servo power directly connected to the arduino?? Could you please provide me with a link to a schemtic of how exactly I should connect my servos/dc motors to my arduino? Thanks again.

Yeah we should actively campaign for that tutorial showing the servo on the Arduino 5V, to be ditched. You can probably get away with it for one servo, unloaded, but a servo under load can get up to an amp or so....

So JimboZA could you suggest an accurate schematic of how to hook up multiple servos to an Arduino UNO?

welchsc:
So JimboZA could you suggest an accurate schematic of how to hook up multiple servos to an Arduino UNO?

Indeed.....

servo power.png