Let's Make Robots!

Sharp IR sensor Broken?

For some time now ive been trying to get m sharp ir sensor to work with my arduino.
its all plugged in and fine but no matter what is infront of it the data will keep bouncing around 1000.

................................................................................................

#define BAUDRATE 9600
#define IRPIN 0 //analog pin for reading the IR sensor
#define WAIT 300 //milliseconds to delay

int val = 0;       // variable to store the value coming from the sensor

void setup() {
  Serial.begin(BAUDRATE);
}

void loop() {
  val = analogRead(IRPIN);    // read the value from the sensor
  Serial.println(val);        // print the raw analog value to serial port
  delay(WAIT); // stop the program for some time
}

................................................................................................................

all i get is:

977
1023
1011
859
861
890
1023
1023
956
866
872
904
923

I dont know whats wrong, Someone please help me.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Did you mount the sensor on a metal frame? The sensor housing can conduct electric current, and didn't work when mounted on a metall frame.

Just to be sure, try setting all of your unused analog inputs high with the digitalWrite command.

Another idea is to verify that your Sharp IR is at least putting out IR. If you have a digital camera, Look at your sensor through the camera with the lights off. You should be able to see some light from the IR emitter. That doesn't validate that the unit is completely working, but it at least shows that the emitter portion is still putting out IR.

If  you have an osciloscope you can verify the output, but I suspect you do not have one. (I wish I did.)

You might try a small cap

http://letsmakerobots.com/node/22781

How about measuring the voltage from the sensors output pin using a multi meter. Isolate every other variable. Tape down the sensor on a box. Put it on the table. Put a stable, flat, opaque object in front of. Now measure the voltage coming out while varying the distance between the two.

That's what a scientist would do. That's how I learned how to use a Sharp.

This experiment has a twin: remove the sensor an study the micro controller. I recommend a potmeter.