Join Rae Hoyt for an in-depth discussion in this video Introducing various analog inputs, part of Arduino: Pulse Width Modulation.
- There are hundreds of different analog inputs but at their core, they all do the same thing. They may monitor the temperature in a room, humidity in the air, or the acidity of soil. But when you boil it down, each of these electrical components is simply a variable resistor. The Arduino will listen for a five volt signal on the Arduino analog pin. By adjusting resistance, more or less of the five volt signal passes through. The Arduino interprets this voltage and assigns a value from zero to 1023.
How has that value changed? Well, it depends on the component. There are many types of sensors, so your options are nearly limitless. Let's look at four components that are used frequently with the Arduino. Your components may have a different schematic, so always be sure to check the data sheet before plugging anything in. A potentiometer is a simple knob that provides variable resistance. As you turn the knob left and right, the resistance changes, which in turn changes the input value.
A dimmer switch on a light is a potentiometer. There are three pins on this component. The legs on either side are the two ends of a resistor and should be connected to power and ground. As the knob is moved left and right, the path of least resistance is changed. The center pin gets connected to the analog input. Potentiometers come in many different shapes. Some are knobs that rotate, others look like dimmer switches. You may even see some that look like buttons.
A flex sensor, also called a bend sensor, is normally long and thin. As you bend the sensor, the resistance changes. If you took apart a joystick, you might find a flex sensor. For the Arduino, I use a conductive ink-based bend sensor. In this component, a thin strip of conductive ink is placed between two strips of copper. As the component is bent, the ink is displaced, reducing the resistance to jump through the ink. A photoelectric sensor senses light.
As the amount of light is changed, the resistance changes. If your laptop automatically dims the screen when you turn the lights off, your laptop is using a photosensor. This one works through a stunning scientific process. The surface of the component is made out of a photon reactive material. When photons, or light particles, hit the surface, electrons are disrupted. The more electrons disrupted, the lower the resistance. As the light gets dimmer, the electrons come back to rest and the resistance goes up.
To hook this up to your Aduino, you also need a resistor in parallel to the photosensor in the circuit. The resistor will pull the value of the circuit back down to zero, stabilizing the signal and reducing noise. A piezoelectric sensor, or piezo buzzer, detects changes in pressure, strain, or force. The prefix "piezo" is Greek for "press" or "squeeze." Piezo sensors are incredibly common, from audio pickups to thousands of automotive applications.
How does it work? The secret is crystals. A diaphragm absorbs energy and squeezes a crystal. When the crystal is stressed, a charge is generated. Piezos, like LEDs, have polarity so they only work in one direction. Just as with the photosensor, you will also need to attach a resistor in parallel to the piezo. Piezos are unique, as they can also be used as outputs. If you send a signal through a piezo buzzer, you can create sound.
With analog inputs, projects can now read and react to the environment dramatically.
- Using basic PWM output
- Adjusting the brightness of LEDs
- Color mixing with RGB LEDs
- Using analog inputs to drive output
- Testing components with a multimeter
- Using the map function
- Debugging code efficiently with the serial monitor
- Controlling servos and motors