Sensors

A sensor is a device that turns (technical term “transduces”) some kind of analog environmental information (motion, temperature, proximity, etc.) into an electrical signal that can be interpreted by a microcontroller. Sensors can be as simple as a switch for “on” or “off”, or as complex as a GPS receiver that outputs the latitude and longitude of the current location.

  • How Sensors Work: For a more detailed explanation of how sensors function, see the How Sensors Work section below.
  • Two wire sensors: For an important note about making sensors with only two wires, see the two wire sensor section below.

Kinds of Sensors

Sensors are either analog or digital:

  • Analog Sensors (continuous): These sensors produce an analog (continuous) voltage that varies (typically) from 0 to 5 volts. They require an analog input in the microcontroller, and have three wires – ground, power, and signal (typically red, black, and white, respectively). Examples include proximity, light, turn, etc.A list of some analog sensors typically used in tangible interaction systems, and descriptions of how they work, can be found on the Analog Sensors page of this site.
  • Digital Sensors (on-off): These sensors can only indicate two states, typically on and off. They can be used in either the analog or digital ports on most microcontrollers. Examples are switches and motion detectors.A list of some digital sensors typically used in tangible interaction systems, and descriptions of how they work, can be found on the Digital Sensors page of this site.
Also, set this very good reference for sensors: www.sensorwiki.org

How Sensors Work

Sensors are devices that take readings from the environment. That’s it. They are very dumb. These vary from sensing temperature, to rotation, to acceleration, to proximity.

Typically the sensor turns its reading into a voltage that corresponds to the reading. For example, a knob typically produces 0 voltage when turned all the way to the left, 2.5 volts in its middle position, and 5 volts at its rightmost position (assuming an input voltage of 5v). Other sensors behave in a similar way. A switch usually produces 0 volts in the “off” position, and 5 volts in the “on” position. A proximity detector may generate almost zero volts when nothing is detected in its range, and produce higher and higher voltages as an object gets closer and closer.

Note that some sensors (like the knob) produce a continuously varying voltage signal. Other sensors (like the switch) produce only discrete voltages. Special interface sensors usually produce a digital signal that contains information about the environmental state. These require a special digital input on the microcontroller. An example is a compass sensor (which detects the compass direction the sensor is pointed in) that requires an I2C interface on the microcontroller.

The voltage produced by the sensors is an “analog” signal, in that it can vary continuously from 0 to 5 volts (typically). In order for a computer or microcontroller to interpret this information, this analog voltage must be converted to a “digital” signal, in the same way that music must be converted to digital before it can be put on a CD.

This conversion from analog to digital (A to D) is usually handled by the microcontroller. The analog voltage is converted into a digital number with a specific range, depending on the capabilities of the A to D converter and the microcontroller. For example, the Make Controller microcontroller converts its analog inputs into a number from 0 to 1023 (geek note: this is a 10bit number). In this case, a knob connected to the Make Controller would generate a digital 0 when it was turned all the way to the left, and 1023 when turned all the way to the right.

Typically, the voltage coming from the sensor is read continuously, and this generates a stream of numbers for that sensor which varies over time. This provides a real time indication of the environmental factor the sensor is picking up (e.g. position of the knob, the temperature, etc.).

An important job of the software is to interpret/transform the sensor data as it comes in. Often the first thing that’s done is to scale the data to more closely match the content being manipulated. Some examples:

  • Scale the raw knob data ranging from 0 to 1023 to range from 0 to 480, and use it to position a graphic vertically on a screen that’s 480 pixels high. When the sensor data equals zero, the graphic will be positioned at the top of the screen, when the data is 480, the graphic will be positioned at the bottom of the screen.
  • Scale proximity detector data from 1 to 16, and display one of 16 different words, depending on how close an object is to the detector.
  • Combine the above, so the the words move smoothly up and down on the screen (data scaled from 0-480), but change at each of 16 different positions (data scaled from 1-16)

Wiring Two Wire Sensors with a Voltage Divider

Some sensors only have two wires, but the microcontroller needs three – ground, power, signal. For example, normal switches, some pressure sensors, and light sensors have only two connections. To remedy this sitation, you need to add a resistor (sometimes called a pull-up resistor) to create what’s called a voltage divider. This creates a three wire hookup out of the sensor’s two wires, that then works with the microcontroller.

For more info on this, go to this page.


Last modified September 30th, 2012