[SOLVED]IR sensor module OUTPUT doesn't seem to be recognise by wemos D1 R?

Hi everyone,

int LED = 13; 
int isObstaclePin =2;  
int isObstacle = HIGH;  // HIGH MEANS NO OBSTACLE

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(isObstaclePin, INPUT);
  Serial.begin(9600);
  
}

void loop() {
  isObstacle = digitalRead(isObstaclePin);
  if (isObstacle == LOW)
  {
    Serial.println("OBSTACLE!!, OBSTACLE!!");
    digitalWrite(LED, HIGH);
  }
  else
  {
    Serial.println("clear");
    digitalWrite(LED, LOW);
  }
  delay(200);
}

As you can see:

this type of IR sensor come with three pins, I connected
VCC-> 5V
GND->GND
OUT_>D2

The IR sensor has indicators which are
Power LED->Illuminates when power is applied
Obstacle LED-> Illuminates when an obstacle is detected

There is suppose no error in code, nor the connection, as I followed the instruction in the link above. The IR sensor Obstacle LED on the module does detect when an object is approaching.
My problem is the serial monitor doesn't show Serial.println("OBSTACLE!!, OBSTACLE!!") even when the sensor detect object? I am using a Wemos D1 R1 board for my project by the way. Thank you!

According to this pic (which I don't vouch for, I just happened to find it....) pin D2 is actually pin 16 not pin 2, if you don't call it D2.

terW3_:

int isObstaclePin =2;

OUT_>D2

1 Like

I changed the code at

int isObstaclePin =16;

and its works. Thank you!!! :slight_smile:

Cool...

I use a nodemcu, which has a similar confusion of pin numbers, and I stuck a pic of the "D" numbers and "Arduino" numbers on the back...