Book Image

Learning JavaScript Robotics

By : Kassandra Perch
Book Image

Learning JavaScript Robotics

By: Kassandra Perch

Overview of this book

Table of Contents (16 chapters)
Learning JavaScript Robotics
About the Author
About the Reviewers

Using sensors – Light and Temperature

Now, we'll build a couple of projects that demonstrate how to use more advanced sensors: a photocell and a temperature sensor. We'll learn how specialized Johnny-Five Sensor objects allow us to make these easier to use, and how to play with inputs in the REPL and show some input data in the console using a module called barcli.

Wiring up our photocell

First, we'll start with the photocell—see the following wiring diagram:

The wiring diagram for the photocell


Note that the resistor setup is how we wire up a sensor with only two leads and we need three—input, power, and ground.

Coding our photocell example

As we code our photocell example, we'll note that there is no photocell object, so we're going to use the generic Sensor object, as we did with the potentiometer.

As for outputting the data that we get from the sensor, we're going to use a handy utility called barcli to make our output much easier to read.


In the early days of Johnny-Five, one of the...