Unfortunely I've made a mistake on ordering sensor ![]()
I have bought this one GP2D15
http://www.acroname.com/robotics/parts/R49-IR15.html
that is digital one type.
no pain
but I tried to make it working but i have a problem, as when i test the digital response from the sensor, the reply is not accurate.
this is the code:
/*
digital sensor reading SHARP GP2D15
code by A.Richetta
V. 0.1 26 APRIL 2009
version: NOT WORKING
*/int POS = 3; // initializing sensor
int LED_ROSSO = 6; // initializing RED LED
int LED_VERDE = 4; // initializing GREEN LEDvoid setup()
{
Serial.begin(9600); //SPEAKING WITH SERIAL
pinMode(POS, INPUT); // SENSOR IS AN INPUT TYPE
pinMode(LED_ROSSO, OUTPUT); // LED IS OUT
pinMode(LED_VERDE, OUTPUT); //LED IS OUT}
void loop()
{
if (digitalRead(POS) == 1) // READING SENSOR, IF 1 IS BACK THERE IS AN OBJECT
{
digitalWrite(LED_ROSSO,HIGH); // TURN RED LED ON
digitalWrite(LED_VERDE,LOW); // TUNR GREEN OFF
Serial.println("ostacolo"); // PRINT ON SERIAL OBJECT!!
delay(1000);
}
else
{
digitalWrite(LED_VERDE,HIGH); // TURN GREEN LED ON
digitalWrite(LED_ROSSO,LOW); //TURN RED LED OFF
Serial.println("nessun ostacolo"); // SERIAL PRINT NO OBJECT IN FRONT OF ME
delay(1000); // WAIT SOME TIME
}
}
Problem is, when no obstacle is in front of the sensor it's ok, green led is correctly on.
when i put my hand in front of the sensor, it starts to turn on red and off, turn green onn and off and so on.
i made mistakes in code?
thank you for any reply