Chapter 4. Sensors and input
This chapter covers
- The role sensors play in projects as transducers, converting physical phenomena to electrical signals
- How microcontrollers use analog-to-digital conversion (ADC) to interpret incoming analog signals
- Building voltage divider circuits to read resistive sensors like photoresistors
- Using Johnny-Five’s generic Sensor class to read sensor data and listen for data and changes
- Taking advantage of Johnny-Five’s component-specific Thermometer and Button classes
- Managing default digital logic levels using pull-down resistors
To build nifty gadgets, whether they’re temperature-controlled automatic fans or more interesting inventions, you’ve got to be able to gather information and input from the real, physical world.
For this chapter, you’ll need the following:
- 1 Arduino Uno and USB cable
- 1 photoresistor
- 1 4.7 kV resistor
- 1 TMP36 analog temperature sensor
- 1 push button
- 1 10 kV resistor
- Black, red, and green jumper wires
- 1 half-size breadboard

Analog and digital sensors pay attention to a particular phenomenon in the physical environment—temperature, brightness, dampness, pressure, vibration—and they output information about changes in the intensity of that phenomenon as a signal. In the automatic fan example in chapter 1, a temperature sensor translated temperature changes into an electrical signal that the microcontroller’s firmware could read and process (figure 4.1).