Sharp IR Problem with Pro Mini

I’m having a problem reading my Sharp IR range sensor with my Pro Mini 5v.

#define IR 2
#define sampleSize 10

long interval = 100;           // interval at which to blink (milliseconds)
long previousMillis = 0;        // will store last time light sensor was updated

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
 unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
    // save the last time you read the accelerometer! 
    previousMillis = currentMillis;

    // Main code here!
    
    int IRVal = sampleIRPin(IR);
    int IRValMap = map(constrain(IRVal,82,419), 82, 419, 0, 100);
    Serial.println(IRValMap);
   
  } 
  
}

int sampleIRPin(int IRPin)
{
  long reading = 0;
  analogRead(IRPin);
  //  Ignore first analog read
  delay(1);

  for (int i = 0; i < sampleSize; i++)
  {
    reading += analogRead(IRPin);
  }

  return reading/sampleSize;
}

My Pro Mini is on a breadboard with nothing else connected other than my 5v FTDI adapter. I’m also using a 10uF capacitor on the mains as the data sheet recommends. My readings are really unsteady and rarely rest at 0 which is what it should read when nothing is in sight. If I move the power for the sensor closer to the Pro Mini and not use the power rails of the breadboard, it gets slightly better but not a great deal. It seems the further away you move the positive and negative cables from the Pro Mini the worst things get e.g. reseting point being around the 20’s. I’ve also tried switching analog ins just in case I had a dry joint and tried another JST cable, etc.

The strange thing is that I’ve loaded the same sketch onto my Arduino Uno using a breadboard and its perfect.

Sounds like just simple interference. Have you tried another supply? I suspect the Uno has more decoupling than the Promini.

Suggest you try adding a lower value ceramic cap on the supply as well, 0.1uF - 1uF, along with the 10uF.

My GUESS is that your FTDI adapter can’t supply the peak current needed by the Arduino plus the sensor. IOW you’re having brown outs. If the sensor is like this ;

https://www.sparkfun.com/products/8958

… then the ave current is 33 to 50 mA. I don’t know the peak current but I’ll GUESS it’s something like 150 mA to get the range needed. Still not a lot but ???

What do you have for an FTDI adapter ?

I am using the official Arduino FTDI adapter and yes its exactly the same one as your link (20-150cm range).

I’ve just switched boards to my Arduino Nano 3.1v and I’m having the same problem.

The Sharp IR range finders do pull a lot of current when pulsing their IR LED. These typically require an additional 10uF (or greater), low ESR cap soldered right onto the Sharp’s connector pad. This ‘local’ cap supplies the current required to pulse the IR LED.

These typically require an additional 10uF (or greater), low ESR cap soldered right onto the Sharp’s connector pad

Sorry, whats a ESR and where is the Sharp’s connecter pad?

Thanks

http://en.wikipedia.org/wiki/Equivalent … resistance

Put the cap as close to the sensor’s Vin and GND pins as possible.

If have more than 10 uF handy, use them as well.

This indicates perhaps 330 mA is the peak current draw.

http://www.sharpsma.com/webfm_send/1490

That may be more than a typical USB port will provide w/o negotiation (? 200 mA ?) by the device, in your case that’s the FTDI adapter.

Add more capacitance btw Vcc and GND or try using another ~5v supply for (just) the sensor. Perhaps 4 AA batteries in series.

https://www.sparkfun.com/search/results … t=products

Will try tomorrow. I have got the pololu 5v step up/down converter I can try also. I will be using the sensor with an external 9v battery anyway, but wanted to see it working first within the serial monitor.

It’s just funny how the UNO works fine. I find most things seem to work better with the UNO but sadly there’s no room in my project box for one which is why I favour the pro mini or nano.