Sharp IR Proximity Sensor
Infrared proximity sensor made by Sharp. Part # GP2Y0A21YK has an analog output that varies from 3.1V at 10cm to 0.4V at 80cm. The sensor has a Japanese Solderless Terminal (JST) Connector.
For more information click here.
How To Connect
Cylon.robot({ connections: { arduino: { adaptor: 'firmata', port: '/dev/ttyACM0' } }, devices: { sensor: { driver: 'ir-range-sensor', pin: 0, model: 'gp2y0a41sk0f' } } });
How To Use
var Cylon = require('cylon'); Cylon.robot({ connections: { arduino: { adaptor: 'firmata', port: '/dev/ttyACM0' } }, devices: { sensor: { driver: 'ir-range-sensor', pin: 0, model: 'gp2y0a41sk0f' } } work: function(my) { every((1).seconds(), function(){ var range = my.sensor.range(); console.log('Range ===>', range); }); } }).start();
Commands
analogRead
Returns the current analog value from the pin
Params
-
[callback] (
Function
) invoked witherr, value
as args
Returns
- (
Number
) current analog value, or 0 if it's not been read yet
rangeCm
Returns the current range, in centimeters
Params
-
[callback] (
Function
) invoked witherr, value
as args
Returns
- (
Number
) current detected range in centimeters
range
Returns the current range, in inches
Params
-
[callback] (
Function
) invoked witherr, value
as args
Returns
- (
Number
) current detected range in inches
Events
range
Emitted when the IR Range Sensor has detected the current range
Values
- distance the current distance in inches
rangeCm
Emitted when the IR Range Sensor has detected the current range
Values
- distance the current distance in centimeters