Hi!
I need help with Sharp GP2Y0D02 (Digital output) sensor.
I've already used the analog sensor with success but for a particular project I need the digital version that outputs an HIGH voltage if an obstacle stays in the range of 80cm in front of the sensor.
I thought it was easy reading this sensor but I can't.
Maybe I need help with connection because I wired directly the sensor output to a digital pin as the 5V and ground. The datasheet speaks about a by-pass capacitor of 10μF and I see in the circuit a resistance of 12KΩ between Vo and Vcc...
I'm sorry but I'm not able to undestand what should I do..
Can you explain me better or post a tutorial where I can see what I have to do?
Thank you
PS
this is the simple code I used:
const int sensor = 2;
const int led = 13;
void setup() {
pinMode(sensor, INPUT);
pinMode (led, OUTPUT);
Serial.begin(9600);
}
void loop() {
int val = digitalRead(sensor);
if(val == HIGH){
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
Serial.println(val);
delay(500);
}