EFA:Sensors:Reading Analog Sensors

Variable Resistors

Many sensors are just variable resistors that change their resistance value based on some external input (light, temperature, force etc.). The Arduino is not able to read the change in resistance directly, but we can convert that resistance change into a change in voltage using a voltage divider.

Voltage Divider

If you connect two resistors in series as in the image below, the voltage read from Vout depends on the ratio of the two resistors. Read the Wikipedia article or check this tutorial from Sparkfun, if you want to learn how to calculate the values.

Light Dependant Resistor (LDR, photocell, light sensor)

This can be used to read the values from various sensors, such as the light sensor we are using.



// Read and display the value from the light sensor.

int lightSensor = 0;

void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:
  lightSensor = analogRead(A0);
  Serial.print("light: ");


Potentiometers are essentially voltage dividers built inside a handy interface. They come in different shapes and sizes, but all of them work roughly the same way.

Most potentiometers have three pins, I’m calling them A, W and B

  • A would be connected to the negative side of your power supply. GND on the Arduino Uno.
  • W is the pin that outputs a varying voltage (essentially, it’s the Vout on the voltage divider circuit above). The W is connected to a moving wiper that changes the balance of the “two resistors” inside the potentiometer.
  • B would be connected to the positive side of your power supply. 5V on the Arduino Uno.

Sensors with Analog Voltage Output

Many sensors will just give you an analog voltage. These are getting more rare these days as more and more sensors are moving to being completely digital. Here is a list of a couple of commonly found sensors with analog output:

  • ADXL335 Accelerometer
  • Sharp Infrared Distance Sensors
  • Ultrasonic Range Sensor (Distance Sensor)

Make Your Own Sensors

Many materials around you can be used to create your own sensors. There are two common ways to convert things around you to sensors.

Resistive Materials + Voltage Dividers

Some materials that can be used to create DIY sensors:

  • Pencils (Graphite) – The softer the pencil the better. You can draw shapes on a piece of paper and the longer the distance between the two points the more resistance there is.
  • Magnetic tapes (VHS works well) – Most magnetic tapes can be used to create DIY linear potentiometers. Note that not all tapes work.
  • Velostat – This is a material that is used in antistatic packaging. Can be used to make DIY pressure and flex sensors.
  • Conductive textiles and yarns – Can be used to make DIY pressure and flex sensors. Kobakant is a great resource for making your own textile-based sensors.

Capacitive Sensing

Capacitive sensing is based on the fact that your body is able to store an electric charge. You can use almost any conductive object as a sensor with just one wire connecting the object to the microcontroller/sensor.

  • CapasitiveSensor Library – Works with most microcontrollers. Requires a couple of extra components.
  • Teensy Touch Pins – The Teensy microcontrollers have built in functionality for capacitive sensing. Use touchRead() on a pin that has the hardware capability for touch sensing.
  • MPR121 – A commonly used capacitive sensor. You can connect 12 individual conductive objects as sensors to it.
  • Trill touch sensors – High quality capacitive sensors that come in different forms. The Trill Craft can be used to connect up to 30 sensors to one board.