Hardware:
Arduino UNO
Electronicspices IR proximity sensor (bought from amazon)
Problem:
The sensor detects the object in front of it perfectly (the light on it glows when it encounters another object and vice versa), however the output that i recieve is the very opposite. So when an object is placed in front (both lights glow), it returns false and when no object is in front(only 1 light glows), it returns true, hence i keep getting the opposite results if i ever connect it to the breadboard. Any suggestions of how do i fix this?
Connections:
ground of sensor to ground of arduino
vcc to 5v/Vin
out to digital3
i'm not sure if it helps but here is the small code:
int led = 13;
int ir = 3;
void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(ir, INPUT);
}
void loop()
{
if(digitalRead(ir)==HIGH) //Check the sensor output
{
digitalWrite(led, HIGH); // set the LED on
}
else
{
digitalWrite(led, LOW); // set the LED off
}
Serial.println(digitalRead(ir));
delay(1000);
}