Hello, I am trying to make, from what it looks like an IR obstacle detection sensor to work with an Arduino. I have no information about the sensor, apart of that it was fitted on the bottom of a car door mirror on a motorized door opening retrofit kit. Where this sensor would detect an obstacle ( another car or human, or tree , etc...) when the door swings open and will stop it if any obstacle is detected. There is a small circuit board after the sensor that is cast in resin so I can't see what components it is built of. The sensor does looks like infrared sensor, as it has that dark red tinted glass (like the remote controls) and as far as I can see there are two LED's behind it.
Below is a generic code to interface and IR sensor but I got nothing with it. I mean I get "object detect d" constantly even though nothing is in front of the sensor ( this is when I have the "state== LOW"). And if I change the code to "state==HIGH" I've got "Clear" on the serial monitor.
It is connected to Arduino Uno R3, black to ground, red to 5v and the yellow to digital pin 4. I guess that the color logic is this.
const int IRsensor = 4;
const int led = 13;
void setup() {
Serial.begin(115200);
pinMode (IRsensor, INPUT);
pinMode (led, INPUT);
}
void loop() {
int state = digitalRead(IRsensor);
Serial.println(state);
if(state == HIGH){
Serial.println("Object detected");
digitalWrite(led, HIGH);
}
else{
Serial.println("Clear");
digitalWrite(led, LOW);
}
}




