i.ve been googling and searching around for ages now but cant find why my sharp ir sensor gives a standerd return of 300 in the display of serial monitor..
when i put my hand in front it wil display a number based on the distance of my hand between an int of 200 to 600 and sometimes a little more..
do u guys know how this can be happening. because my arduino now thinks he's seeing an object and returns 300 while in real life my arduino is facing notin but air..
see what happens when you return the values of the other analog pins with nothing in them? Calculon has noticed that the analog pins are sort of linked and influence each other. maybe 300 is the average between the max and 0? Is the input tied to low?
@Geir Andersen: my ir sensor is wired as following:
pin 1 = 5V
pin 2 = GND
pin 3 = A1 (analog pin 1)
then next to this i have a ledpin powerd from arduino digital pin 12. and pin 11 and 10 are wired to the base of a transistor to control the motors with (not to forget the resistantce of 1k ohm also on the wire to the (transistors-)base from digital pins) the motors are powerd external with 9V and the arduino is also powered by a 9V battery trough barral jack thingy
then my code:
int dist; //represent the distance input of the IR-sensor
void setup()
{
//ledpin goes on when power is connected
pinMode(12, OUTPUT);
digitalWrite(12, HIGH);
//configere the motor-pin to outputs
pinMode(11, OUTPUT); //rechts (WIEL)
pinMode(10, OUTPUT); //links (WIEL)
Serial.begin(9600);
}
void loop()
{
//var dist contains distance
dist = analogRead(1);
Serial.println(dist);
//let motors work when distance is not too far away…
if(dist > 400)
{
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
}else{
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
}
}
and im goin to test the empty analog pins right now just wait to a reply to Calculon320…
see my post above for the wiring-up-story-based-pic …
i’ve done some tests and it seems that al the analog pins go up when an object gets closer to ir-sensor. i’ve wired my pulls-wire of my ir-sharp-sensor to analog pin 5 just to see what happens but nottin realy changed. i have a printscreen of my results.
every 3 lines is a new mesure. the first line of the three is pin A5 or Analog 5 where the wire is put on. than the second line is A2 and third line is A0. when u look from down to up its A0 followed by A2 and finaly A5. so…
the last 6 lines are mesures when i put my hand in front of the sensor. al the other crap is AIR or NOTTIN… >.<
I see nothing wrong here. This is the normal behaviour of this sensors. The output signal of the Sharp sensors is very noisy. I have written a tip&walkthrough about it and how to get a better signal.
Here is a picture from the datasheet, showing the output voltage of the sensor in dependency from the distance.
The analogRead() function returns the sensor voltage (5V = 1024, 2.5V = 512, 0.5V=102). If you hold your hand too close to the sensor (<10cm) you will get no useful readings.
Set the internal pull-up resistors for all your unused analog ports. Here’s a code snippet showing how to set analog pins 1 through 5, leaving analog0 available for use.
for (int pinindex = 15; pinindex < 20; pinindex++) { // pinindex 15 is analog0 digitalWrite(pinindex, HIGH); // set all the internal pullups for unused analog pins }
These Sharps are very (electrically) noisy devices. They are not really famous for having the most solid of outputs either. I would have to agree that the behavour you describe is probably normal.
thnxx all, i fixed it by addin a 10k resistor. my default return of the mesurement of air is now rated at ~90 now i am able to use distances between 300 and 100 agian =D got my robot workin and will place him as soon as possible at this website, only problem is that batterys are empty of the motor, soo it just worked well and then my battery is empty. anyway thnx alot u wil be able to see my first sucsesful avoidin robot sooon