Curriculum
Course: Ir Sensor with LED
Login
Text lesson

mBlock Logic

Components

  • IR Sensor 1 → D2
  • IR Sensor 2 → D3
  • Servo Motor → D9

 

mBlock Logic

 
When Arduino Starts

Set Servo (D9) angle to 180

Forever

If (Digital Read D2 = 0) OR (Digital Read D3 = 0)

Set Servo (D9) angle to 90
Wait 5 seconds
Set Servo (D9) angle to 180

End If

End Forever
 

Block Structure

 
[When Arduino Starts]

[Set Servo D9 Angle 180]

[Forever]

< (Read Digital Pin D2 = 0)
OR
(Read Digital Pin D3 = 0) >

[Set Servo D9 Angle 90]
[Wait 5 Seconds]
[Set Servo D9 Angle 180]
 

Better Parking Gate Logic

If the car stays in front of the sensor for more than 5 seconds, the gate may close on the car.

Use:

 
Forever

If (D2=0) OR (D3=0)
Set Servo D9 to 90
Else
Set Servo D9 to 180
End If

End Forever
 

This means:

  • Car detected by either sensor → Gate opens.
  • No car detected → Gate closes.
×
×

Cart