IR obstacles detection with 08m2 using pwmout pulsed led and 38KHz IR receiver module

taux3

Member
Dear all,

Could I use a 08M2 to PWM an IR led at 38KHz 50% duty cycle using the pwmout command at pin c.2 and an IR remote control receiver at 38KHz at c.3 to detect an objects presence by IR reflection? would the code below work?

[start:
high c.0 'green led on
low c.1 'red led off
pwmout 2, 25, 51 '38KHz pwm 50% duty cycle for IR led
if pinc.3 = 0 then goback 'pinc.3 connected to 38KHz IR receiver for remote controls
goto start
goback:
high c.1 'red led on
low c.0 'green led off
pause 500
goto start]

thanks,
Antony
 

erco

Senior Member
I can't test your code right now, but it's definitely possible. A BS2 regularly accomplishes the same thing by sending out a very short burst of 38 kHz through an IR LED, then immediately looking for its reflection in a 38 kHz receiver module. It works because there is a slight delay in the receiver module's output after receiving a pulse. Very convenient.

There is a lot of processor overhead required if you are monitoring several of these sensors. An alternative is to get one or more of these cheap premade 38 kHz modules which do all the work for you: http://www.ebay.com/itm/IR-Infrared-Obstacle-Avoidance-Sensors-Module-for-Arduino-Smart-Car-Robot-HM-/400662837159

Several other useful sensors on that page as well, worth a look.
 

hippy

Technical Support
Staff member
IR receiver chips often do not always like continuous 38kHz IR. That may be more relevant to a static IR break beam system rather than an obstacle detector where IR is only present when it is reflected but it's easy enough to cater for, something like, in pseudo code ...

Code:
Do
  PwmOut 38kHz
  Pause
  If pinC.3 = 0 Then GoBack
  PwmOut OFF
  Pause
Loop
 
Top