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 }
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.)
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.