Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Learning Javascript Robotics

You're reading from   Learning Javascript Robotics Design, build, and program your own remarkable robots with JavaScript and open source hardware

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781785883347
Length 160 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Kassandra Perch Kassandra Perch
Author Profile Icon Kassandra Perch
Kassandra Perch
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Learning JavaScript Robotics
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started with JS Robotics FREE CHAPTER 2. Working with Johnny-Five 3. Using Digital and PWM Output Pins 4. Using Specialized Output Devices 5. Using Input Devices and Sensors 6. Moving Your Bot 7. Advanced Movement with the Animation Library 8. Advanced Components – SPI, I2C, and Other Devices 9. Connecting NodeBots to the World, and Where to Go Next Index

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

Tip

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.

barcli

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

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images