obniz Parts Library

IRSensor

GitHub
IRSensor

IRSensor

Detecting Infrared signal like a remote controller's signal.

wired(obniz, {output [vcc, gnd]})

Connect vcc and gnd and output. vcc and gnd is optional.

Various parts can be used. Belows are example.

  1. OSRB38C9AA
  2. TFMS5380 etc,,,

These parts has vcc/gnd/output
For examle,

On program use it like

// Javascript Example
var sensor = obniz.wired('IRSensor', {vcc:0, gnd:1, output: 2});

start(callback(array))

start monitoring. and set detect callback.

// Javascript Example
var sensor = obniz.wired('IRSensor', {vcc:0, gnd:1, output: 2});
sensor.start(function (arr) {
  console.log('detected!!')
  console.log(JSON.stringify(arr));
})

arr is same as obniz.LogicAnalyzer's result.
So, It's like below.

[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0]

monitor options and these default value
See more details on logicanalyzer document

property type default description
dataSymbolLength number 0.07 (msec) sampling interval of logicanalyzer
duration number 500 (msec) data length
dataInverted number true 0,1 of data should be inverted
cutTail number false cutting of tail 0. It may affect communication.
output_pullup number true pullup to 5v or not of sensor output.

You can chenge these before start.

// Javascript Example
var sensor = obniz.wired('IRSensor', {vcc:0, gnd:1, output: 2});
sensor.duration = 150;
sensor.dataInverted = false;
sensor.start(function (arr) {
  console.log('detected!!')
  console.log(JSON.stringify(arr));
})

ondetect = function(array)

set callback after started

// Javascript Example
var sensor = obniz.wired('IRSensor', {vcc:0, gnd:1, output: 2});
sensor.start()

sensor.ondetect = function(arr) {
  console.log('detected!!')
  console.log(JSON.stringify(arr));
}

Supported from: obniz.js 3.5.0