JavaScript: Laser Intrusion Detection with Johnny-Five on Node.js

The Johnny-Five Tutorial Series is geared towards Arduino programming on Node.js, using the Johnny-Five framework. Get caught up here.

A fairly common security mechanism, the laser intrusion detection system (or laser trip wire), is actually the composition of two devices:

The laser emits a beam of light directly at the photocell; the photocell’s resistance can be read to determine the light exposure. The resistance will decrease as the amount of light intensifies. For the laser trip wire, a low resistance level will indicate an “unbroken” beam.


Connect the following:

  • Laser
    • Ground to GND
    • Signal to D9
    • Power to 5V
  • Photocell
    • Power to 5V (via 200Ω resistor)
    • Ground to GND
    • Signal to 200Ω

Save the following as laser-trip-wire.js:

var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  var laser = new five.Led(9);
  var detection = new five.Sensor("A0");
  var isSecure = false;


  detection.scale(0, 1).on("change", function() {
    var reading = !(this.value | 0);

    if (isSecure !== reading) {
      isSecure = reading;

      if (!isSecure) {

Run node laser-trip-wire.js to see the program in action! To trigger the intrusion message, break the laser’s beam with your hand or any solid object.


Based on the program above, how might it be extended to trigger some kind of audible or actuated reaction to the intrusion?

* The laser and photocell used in this tutorial are included in the Sun Founder 37-in-1 Sensor Kit. Other lasers, other photocells


We moved off of Disqus for data privacy and consent concerns, and are currently searching for a new commenting tool.

Contact Us

We'd love to hear from you. Get in touch!


P.O. Box 961436
Boston, MA 02196