IR Sensor Interface With STM32

IR sensor with stm32

Circuit Diagram:

Ir with stm32

Code:

 int  obstaclePin = PB1;        // This is our input pin
void setup() 
{
  pinMode(obstaclePin, INPUT);
   pinMode(PB10, OUTPUT);
  Serial.begin(115200);  
}
void loop() 
{
  int hasObstacle = digitalRead(obstaclePin);

  if (hasObstacle == LOW)

  {
        digitalWrite(PB10, HIGH);   // turn the LED on (HIGH is the voltage level)
  }
  else
  {   
    digitalWrite(PB10, LOW);   // turn the LED on (HIGH is the voltage level)
  }
  delay(500);
}