IR Detector - not working with Mega2560

by iisfaq on Sat Jun 16, 2012 2:21 pm

Hi all

Just getting started and I am having problems with getting the IR Detector project from http://www.ladyada.net/learn/sensors/ir.html working.

I have a Deumilanoye and it works in that but i nthe Mega 2560 it does not.

I tested the pin using a simple LED and can get it to flash so I assume that the direct pin connection may be a problem.

// We need to use the 'raw' pin reading methods
// because timing is very important here and the digitalRead()
// procedure is slower!
//uint8_t IRpin = 2;
// Digital pin #2 is the same as Pin D2 see
// http://arduino.cc/en/Hacking/PinMapping168 for the 'raw' pin mapping
#define IRpin_PIN PIND
#define IRpin 2


I have looked at the pin image for the 2560 but not sure what I am looking at - it looks like it could be pin 4 instead of 2? but I do not know :-(

Image

Any help appreciated

cheers

chris
iisfaq
 
Posts: 1
Joined: Sat Jun 16, 2012 2:16 pm

Re: IR Detector - not working with Mega2560

by Keith777 on Sat Jul 21, 2012 9:49 pm

I had the same problem and trying to find the correct pin on the mapping diagram didn't help anything.
I found the pin that works by just trying others. PIN 19 (rx1) is the one and I don't even see it on the mapping diagram.

-Keith
Keith777
 
Posts: 1
Joined: Sat Jul 21, 2012 9:44 pm

Re: IR Detector - not working with Mega2560

by TaylorHolmes on Tue Nov 27, 2012 3:32 pm

Has anyone figured out a working solution to this that they've tried? I'm having the same problem as iisfaq
(OP). I'm using the IR sensor - TSOP38238 (https://www.adafruit.com/products/157) with an Arduino Mega 2560 R3. I've tried everything in this thread, including the code that the last poster (aldan4uk) suggested, with no luck so far. At this point I'm just using trial and error, but it might take a while.

I was hoping that since this IR sensor is sold by adafruit, perhaps a bit of support is what we need.
always check the math.
User avatar
TaylorHolmes
 
Posts: 6
Joined: Sun Apr 10, 2011 10:20 pm
Location: Baton Rouge, Louisiana

Re: IR Detector - not working with Mega2560

by adafruit on Fri Nov 30, 2012 9:13 am

use pin PINE and 4 not PINE and 2 - not sure why he said E2
User avatar
adafruit
 
Posts: 11647
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: IR Detector - not working with Mega2560

by adafruit_support_rick on Fri Nov 30, 2012 12:31 pm

It works for me.
I'm using the sketch downloaded from github.
I made the following mod for use with the Mega 2560
Code: Select all | TOGGLE FULL SIZE
//#define IRpin_PIN      PIND
//#define IRpin          2
// for MEGA use these!
#define IRpin_PIN PINE
#define IRpin 4


I have the following connections:
Code: Select all | TOGGLE FULL SIZE
Sensor  Mega
------  ----
  1     digital 2
  2     GND
  3     5V


Make sure you have correctly identified pin 1 on the sensor, Looking at the domed side, pin 1 is the leftmost pin.

Make sure you're connecting to digital 2 on the mega (not digital 4).
User avatar
adafruit_support_rick
 
Posts: 10974
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY