Memorial day is 05/25/2015 – Orders will ship out on May 26th. There will not be any deliveries or shipping on Monday. Any order placed after 11am ET on Friday May 22nd will not start to ship out until Tuesday May 26th.

IR Detector - not working with Mega2560
Moderators: adafruit_support_bill, adafruit

IR Detector - not working with Mega2560

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

Hi all

Just getting started and I am having problems with getting the IR Detector project from 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
// 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 :-(


Any help appreciated


Posts: 1
Joined: Sat Jun 16, 2012 3:16 pm

Re: IR Detector - not working with Mega2560

by Keith777 on Sat Jul 21, 2012 10: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.

Posts: 1
Joined: Sat Jul 21, 2012 10:44 pm

Re: IR Detector - not working with Mega2560

by TaylorHolmes on Tue Nov 27, 2012 4: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 ( 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
Posts: 6
Joined: Sun Apr 10, 2011 11:20 pm
Location: Baton Rouge, Louisiana

Re: IR Detector - not working with Mega2560

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

use pin PINE and 4 not PINE and 2 - not sure why he said E2

Posts: 11905
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: IR Detector - not working with Mega2560

by adafruit_support_rick on Fri Nov 30, 2012 1: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).

Posts: 18421
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY