Introduction: Understanding Electronic Sensors
Intended to explain the operation of common industrial and household sensors, this "Instructable" teaches you how to use commercially available sensors in a real world deployment using hands-on exercises and experiments.
This lesson will briefly cover circuits which can sense the following:
- Changes in Temperature
- Being Touched (Capacitive skin contact)
- Being Touched (Switches and buttons)
- Changes in Light
- Changes in Sound
- Changes in Acceleration (Movement and gravity)
Also covered is hardware and software needed, where to buy / download the items, how to set up the circuits for numerical output, how to read the numerical output, and a background on how each sensor works.
Let's get started!
Step 1: Thoroughly Tested - Purchasing and Downloading the Environment
You'll see throughout the Instructable that the details of this lesson were thoroughly tested by teenagers visiting a local University as part of their interest in Mechatronics (robotics and manufacturing).
Oreo cookies are helpful, but not required.
The Adafruit people manufactured the board we will use today, called the "Circuit Playground - Classic" and they have thoroughly tested a large number of ways to use the device. You can see some of these in their "Learn" page here, wich pretty much roughly track this Instructable laboratory experiment and sub-steps - courtesy of this Adafruit "Learn" page, https://learn.adafruit.com/circuit-playground-and-bluetooth-low-energy
The parts you need are simple, inexpensive, and easy to use for experimenters from a wide range of age groups, even as young as Middle School (12 years old, perhaps?)
- First, purchase one or more of the devices here : https://www.adafruit.com/product/3000 and also a USB to Micro-B USB adapter to connect to your PC here https://www.adafruit.com/product/898. The total cost is under $40 with shipping, but you may find it cheaper.
- Once you purchase and receive your inexpensive Circuit Playground and USB cable, you'll need to connect it to a Personal Computer (PC) that has an Integrated Development Environment (IDE) for Arduino type devices.
- In this example we are using the IDE arduino-1.8.4-windows, but others will work as well. Be sure to install all drivers (in this case, adafruit_drivers_126.96.36.199
- Once you've installed the IDE, you can open IDE called "Arduino"
- Under File -> Preferences insert the following "Additional Board Manager URL" https://adafruit.github.io/arduino-board-index/pac... , then say OK and then close and re-open the IDE
- Now connect the Circuit Playground device with the Micro USB. See that it powers up and runs the default program "Circuit Playground Firmata" by displaying a rainbow sequence of lights. You can test that the switch near the battery power jack reverses order and one of the buttons plays a note for every color.
- You'll need to get the Circuit Playground Library and then unzip the Circuit PLayground Library into the Documents -> Arduino -> libraries folder “Adafruit_CircuitPlayground-master.” Once unzipped, remove the suffix "-master" from the folder name. Stop and restart the IDE, and load the Circuit Playground Board Type under Tools -> Boards -> Board Manager and then search for type "Contributed" and keywords "Adafruit AVR". This will let you install the "Adafruit AVR Boards" (latest version) after which you should stop and restart the IDE
- Now you are ready to test the Circuit Playground with a demo program. Connect to the Circuit Playground connected via USB. Go to Tools -> Boards and make sure that you select Circuit Playground. Go to Tools -> Ports and make sure you select the appropriate COM port (the one connected to the USB Blaster). Download a demo program as follows: Select: Files -> Examples -> Adafruit Circuit PLayground -> demo and then compile and upload (can use the "right pointing arrow" button to do all)
- Test the demo program by following these steps: See that the Circuit Playground is blinking in rainbow sequence. Turn the slider switch and see that it causes notes to be played (please turn it back off, otherwise it will surely annoy everyone around you). See that the red download LED blinks the timing rate.
- Now you can communicate with the Circuit Playground via Text Interface. Click on the "Serial Monitor" button in the IDE. It looks sort of like a magnifying glass in the upper right of the demo program window. You may wish to turn off auto scroll to get a better look.
You are ready to experiment and connect to all the different sensors!
Step 2: Sensing Temperature
Take a look at the “temperature” value on your serial monitor text output. It will have a room temperature value somewhere in the 30's. I measured 39.43 degrees Celsius.
The thermistor being used to measure temperature is shown in the photo. It is sensor A0 and has a graphic of a thermometer next to it.
Gently put your thumb over the temperature sensor and record how many seconds it takes to reach a top temperature. Make a note of this, as well as the following:
To reach maximum finger temperature it took __________ seconds.
What is the highest temperature it eventually reached? __________ C
What is this value in Fahrenheit? __________ F. HINT: F = (C * 1.8) + 32
Is this warmer or cooler than normal body temperature? __________
Would using this thermometer with someone’s thumb be a good fever indicator to tell if they are sick?
A Thermistor is a special kind of resistor that changes resistance according to the temperature. One of the pictures in this step shows a typical Thermistor circuit diagram. ·
In the circuit shown, what would be the reading on the Volt Meter? __________ HINT: Use the voltage divider rule Vout = (5V * R1 Ohms) / (R1 Ohms + Thermistor Ohms)
If the thermistor has a rating of “1.5% Resistance change per degree C” – what will be the resistance of the thermistor if the temperature goes up to 30 degrees C? _______________________ HINT: since it is a 5 degree change, and each degree changes the resistance by 1.5%, we get Thermistor Ohms = (5 * 0.015) + 10,000 Ohms
At 32 degrees C, what would be the reading on the Volt Meter? __________ HINT: Now the change is 7 degrees.
Where might temperature sensors be used in the types of manufacturing?
Step 3: Capacitive Touch Sensor
The photo shows which of the connectors (or “pads”) can also be used to detect touch. They are called capacitive touch sensors because they use the human body as an electronic component called a capacitor.
For safety, we want any electric current to be very low. For this reason, all external connections to the pads pass through a 1 Mega Ohm resistor to a common area (pin #30 of the chip) so the total resistance between any two pads is 2 Mega Ohms.
- If the peak voltage between any two pads is 5 Volts, and the resistance is 2 Mega Ohms, what would be the current that passes between any two pads if they are short circuited? __________ (DO NOT short circuit them)
- "Capsense" are the numbers that are displayed by the text interface. In which case are the numbers larger, when the sensors are being touched, or when they are not being touched? _________
- Record some examples of numbers when the sensors are NOT being touched: ____________________
- Record some examples of numbers when the sensors ARE being touched: ____________________
- What difference do you observe when multiple sensors are touched simultaneously? _____________________
- What happens if you hold something metallic, and touch the sensor with that? _____________________
- What happens if you hold something non-metallic, and touch the sensor with that? _____________________
- Because capacitive touch sensors have no moving parts, they are very resistant to vibrations. Also, they can be covered with a waterproof protective coating. Why might these two aspects be useful in a manufacturing environment? ______________________________________________________________________
Step 4: Traditional Buttons and Slider Switches
Push buttons and switches seem so simple and “everyday” that we take them for granted when it comes to their use as sensors. The keyboard is a great example. When we want to type quickly, have few “false” keystrokes, and have a long life of many years of use – mechanical switches (one under every key on the keyboard) are the way to go.
The circuit we are using today has three push-button “intermittent” switches. That means that one you let go of the button, they pop back to their original position (thanks to a spring loaded mechanism). The circuit also has a sensor dedicated to a two-position slide switch. It may take some effort to slide it, but don’t break the board trying to do that – slide sideways more firmly than you press down. This type of sensor is very stable. Stable means that once you slide it to one position or the other, you can fully expect to be able to walk away and come back a long time later and expect it to still be in the same position, even if it is on a vibrating surface, etc.
Where have you seen such a slide switch in manufacturing, or even your house?
Look at the text output and find the sensor information. In this case, the sensor may not output a number but rather something else.
"Slide" switch should indicate its position. What values does the “slide” sensor take in the two positions?
Something else happens in one of the two slide positions. What is that?
P.S. As a courtesy to everyone else, please slide the switch to the “less annoying” position as soon as you are finished with this section.
Step 5: Light Sensors
Like the temperature sensor, the Light Sensor circuit on the “Circuit Playground” board uses a voltage divider circuit – where the 5 Volts driving the device is chopped into two parts, by the sensor and by a fixed value resistor. Instead of a “thermistor” the light sensor uses a “photo-transistor” which changes resistance based on the amount of light striking it. You can see the photo-transistor “A5” right next to the graphic of the eye on the circuit board.
If the light sensor is pointed towards the ceiling of the room (towards the lights) the value of “Light Sensor” should be in the hundreds.
What value of "Light Sensor" do you observe when the “eye” is pointed towards the ceiling of the room?
What about if you point the “eye” towards the floor – what number do you observe? _______________
What about if you point the “eye” in different angles between the ceiling and the floor? – Describe what you observed, including the values of the numbers you observed, and what you did to get those numbers. ________________________________________________________________
What about if you point the sensor to a close (but not touching) piece of dark cloth – what number do you observe? ____________________
Covering it up (sensor near the "eye") with your finger should bring the number down. Does it? ___________
Note, your finger is semi-transparent, so the bright lights of the glowing LED can glow it up through your finger. What else could you use to cover up the sensor to get a lower number? _____________________________
Light sensors can be somewhat finicky – not always giving the exact reading you’d expect, and greatly depending on the reflectivity, transparency, angle of lighting, and brightness of lighting. Manufacturing vision systems seek to get past these limitations by tightly controlling these variables. For example, a bar code scanner may use a bright focused single-color laser stripe to minimize the impact of room lighting. In another example, a milk carton conveyor belt uses a “garage door” style light sensor, counting milk cartons by counting the number of times light is allowed to pass between them.
Give a different example from manufacturing, home, or business where some of these light variables are controlled to get a better light sensor result (besides the examples I already mentioned here):
Step 6: Sound Sensor
The sound sensor on the “Circuit Playground” is actually a rather sophisticated Micro Electro-Mechanical System (MEMS) which can not only be used to detect audio levels, but can also perform basic frequency analysis. You may have seen a spectrum analyzer display in a music studio or music player app – which looks like a bar graph with the low notes to the left and the higher notes to the right (just like a graphic equalizer displays).
The value that displays on the text readout is in fact the raw audio waveform. We would have to add the values over time to find the total power of the audio (the sound pressure level).
Nevertheless, this MEMS device can be used to trigger actions by a robot or other device when sounds are present, or when a specific sequence of sounds is heard. In addition, MEMS are extremely small (it’s the device underneath that small hole on the metal box, right next to the “ear” graphic on the board) and low power. This combination makes MEMS devices extremely useful for acoustic, biomedical, micro-fluid detection, microsurgical tools, gas and chemical flow sensors, and more.
Because the output is the audio waveform (and not the power level) you will see less range in the values when things are quiet (~330 is the middle for a perfectly silent room) and wider swings for loud noises (0 to 800 or so).
Record the “Sound Sensor” values when only the background noise of the room is present. What value to you observe? From __________ To ___________
What value do you observe if you speak in a normal tone of voice – about 2 feet or so away from the sensor? From __________ To ___________
Do you get a higher range of values by speaking or by snapping your fingers (or clapping) repeatedly?
Yes or no: _______________ Rage for clapping/snapping goes From __________ To ___________
Why do you think that is? ___________________________________________________________
Try other kinds of noise and record what you observe – but please don’t tap on the board: _________________________________________________________________________________
P.S. MEMS work in both directions, and it is possible to use electricity to move the micro mechanical parts. A company called “Audio Pixels” is working on grouping these devices together to make a perfectly flat tiny speaker that can point the sound in any direction.
Step 7: Accelerometers
An accelerometer isalso a type of MEMS, and one of these devices is provided on the “Circuit Playground” board. The LIS3DH chip, near the center of the board next to the XYZ Graphic, gives the ability to measure acceleration in any direction as the vector sum of acceleration in the X, Y, and Z direction.
Since the force of gravity is identical to force felt by accelerating (Einstein’s theory of relativity), even when standing still here on earth, the device measures an acceleration of 9.8 meters per second per second (9.8 m/s2).
You can rotate the device to get that entire force in the “X” direction.
Try to tilt the device so that all of the acceleration is in the X direction (please be gentle with the short USB cable when twisting things around). What values did you observe? X: __________ Y: __________ Z: __________
Now tilt the device to get almost all of the force of gravity (acceleration) in the Y direction. What values did you observe? X: __________ Y: __________ Z: __________
Finally, position the device so that the acceleration from gravity is split between the X and Y directions, and is nearly 0 in the Z direction (somewhere in between the prior two positions). What values did you observe? X: __________ Y: __________ Z: __________
Use the Pythagorean Theorem to add the X and Y vectors of acceleration from the previous measurement. You can ignore negative signs, it means the device is just upside down in that direction. What is the total acceleration? ______________ Recall that the total acceleration = √(X2 + Y2).
ATTEMPT THE NEXT EXPERIMENT ONLY IF YOU ARE THREE-DIMENSIONAL! Tilt the device so that the acceleration from gravity is split between the X, Y, and Z directions. What values did you observe?
X: __________ Y: __________ Z: __________ Total Acceleration = ___________
As you can see, the accelerometer (thanks to the force of gravity) can also be used to measure tilt – or the position of the board. If you were building a robot arm with a gripper, where might you put the accelerometer sensor, and why? ________________________________________________________
Besides tilt and the direction of the center of the earth, accelerometers can naturally also measure acceleration. Gently move the board back and forth (please be gentle with the short USB cable when twisting things around). What values did you observe?
Direction moved: ___________________ X: __________ Y: __________ Z: __________
Direction moved: ___________________ X: __________ Y: __________ Z: __________
Step 8: You're Done!
Congratulations on completing all these steps and Understanding Electronic Sensors!
Leave a comment to send me feedback on things you think should be improved, and also let me know if you've come up with additional sensor uses of the Circuit Playground Classic!
Paul Nussbaum, PhD
We have a be nice policy.
Please be positive and constructive.