[Add to or Correct This Page]
Transducers
The first thing you need to do is find converters between the actions in the physical world and the elecrical energy that the computer can deal with. For instance an ordinary wall switch is able to convert pressure from your finger into electrical energy. These converters are called transducers. Finding the right transducers for your situation or contriving your situation to fit your transducers will probably be the technical challenge that will require the most creativity. If you are lucky your transducer might be something like a microphone or video camera that plugs directly into the regular old computer that you already know how to use. Or there may be an off -the-shelf stand alone (if you can afford it) or at least ic modules that don't require you to do much building.. Otherwise you will be you will need to get down to actually hooking electronic components with a microcontroller.
We will describe transducers here that run the gamut from low to high level. At a low level will be simple inexpensive switches that require you do do some circuitry and programming. It will help focus your search if you have [categorized] your needs and if you are working at a low level have an idea of the class of transducer (eg switch,variable resistor,electronictally thrown switch) that will mostly likely fit your needs. At a medium level are "modules" like the ir distance sensors that surround the tranducer little surrounding circuitry to work more easiely with a microcontroller. At the high end are stand alone i/o devices like a magnetic postion tracker which come ready to send or recieve data from a serial port with requiring you to set up a microcontroller at all.
Sensing Movement
- Garden Variety Undisguised Switch When you want your switch to look like a switch you can simple go to a hardware store and buy a wall switch or doorbell push button. Radio Shack also has a wide variety of regular switches. You might look in catalogs for arcade games for switch with some fun built in.
- Make your own switch In many installations you will want the person to throw a switch without knowing it. This requires building the switch into some normal looking object. A switch is really just two pieces of metal or "contacts" that touch or don't touch. The current going through these contacts is so little that it is safe to have people touch it. If you can engineer a way for two contacts to touch or not touch depending on the user's actions, you have made a switch. For instance, if you take a thin slice of foam rubber with holes in it and sandwitch it between two metal plates and attach one lead from the switch in the digital in circut to each plate, then you have a switch. I someone steps on the metal plates, the foam rubber will compress and the plates will touch wher there are holes in the foam rubber.
- Foot Switch Foot switches are the most straightforward means of detecting a person’s presence, especially within a small area. The most common type is made of long strips of metal tape separated at intervals by foam tape. When someone steps on these sensors, the foam tape compresses and the metal strips touch each other like the contacts of any other switch. The biggest problem with these sensors is that they need to be robust enough to withstand the weight of people constantly stepping on them. For this reason, it’s probably better to use a commercial version, even though they seem very simple to make. There are some good ones available at http://www.tapeswitch.com. For a higher-end analog version, see the TapTiles made for Infusion Systems’ I-Cube (http:// www.infusionsystems.com) Floor pads tend to be ugly and should be concealed beneath some sort of carpet.
- Roller Switch This is a switch that you can get at Radio Shack that requires very light pressure to close it.
Burgular Alarm Switch
- Beam Switches In a photoelectric switch, a light beam hits a target sensor. When the beam is broken by a body passing between the sensor and the light source, the switch is activated. These are the “electric eye” switches that have been used for decades in such things as automatic door openers. They’re great for detecting passage through some threshold, such as a body through a doorway or a hand through a hole in a box. You always see these in movies about jewel theft, sending red beams of light across the room around the treasure. In reality, you seldom see the beam, and the jewel thief is never as attractive as the ones in the movies. Some photoelectric switches have an emitter on one side and a detector on the other. Others have the emitter and detector on one side and just a mirror on the other side. You can make your own with a cheap laser pointer on one side and a photocell or phototransistor on the other. Keep in mind that these sensors are digital, not analog, sensors. They won’t tell you how far the body is from the light, just that the body crossed the beam of the light. You can also buy photoelectric switches from any burglar alarm supply store. These burglar alarm sensors can be effective across very wide areas and don’t necessarily even need a microcontroller. They usually have two terminals, which get connected when the beam breaks. You can connect these as a switch into a digital input circuit or use it directly to turn on a relay or another low-amperage device. Quite often, they will delay their reset for some period of time after being tripped. There’s usually a potentiometer in the device for lowering the delay. You may not be able to lower it to zero, though, depending on the sensor you buy. Highly Electric (http://www.highly.com) carries photoelectric switches if you're looking online for a source.
- Magnetic Switches consist of a very thin pair of contacts in a protective housing. When exposed to a magnet, they’re drawn together, closing the switch. Sometimes you’ll see the switches themselves (without the magnets) sold as reed switches. The magnetic switch is a favorite for sensing the position of moving objects because the magnet doesn’t require any wires. Suppose you want an object to be able to move unencumbered by wires, but you want to know when it is placed on a pedestal. You might simply put a magnet in the bottom of the object and the magnetic switch on the top of the pedestal.
- Motion Detectors are those ubiquitous beige or black boxes with an LED that blinks when someone walks anywhere in the room. These sensors respond to changes in the infrared light in the space. They only react to change, so will not tell you if someone is in the room and standing still, only if they are moving. The ones used for burglar alarms usually come with terminals that will connect as a switch into a digital input circuit. They offer a distinct advantage over photoelectric switches in that they are extremely easy to install, usually have a much wider field of sensitivity that can be adjusted by changing the lenses that usually come with them. Like photoelectric switches, these sensors will delay their reset for some period of time after being tripped. There’s usually a potentiometer in the device for reducing the delay, but again, you may not be able to reduce it to zero, depending on your sensor. You can also hack into the motion sensors used for outdoor lights, which are cheaper and usually available in any hardware store. Though these sensors are usually designed to switch 120 volts AC, they usually operate well on as low as 5 to 12 volts DC, so they’ll work with your microcontroller.
Position
- IR SensorsYou really can’t beat the Sharp GP2D family of IR sensors (carried by http://www.acroname.com, http://www.digikey.com, and other retailers) for determining short distance. They are cheap, relatively accurate, and easy to use. These sensors send out an infrared beam and read the reflection of the beam off a target (see Figure 9.2). Different models work at different ranges. The longest range sensor in the family, the GP2Y0A02YK, can sense from 8 to 56 inches. The shortest range one, the GP2D120, can sense a range from about 1.5 to 12 inches. There are analog sensors in this family and digital sensors. The digital sensors trigger when a person or object moves within a given threshold distance of the sensor. The analog sensors output a variable voltage from 0 to 5 volts, which varies with the distance. We find the analog ones more useful because they can always be converted to digital use by measuring for a threshold. The standard[analog input circuit] will work for these if your microcontroller has A/D conversion built in. Figure 9.6 shows the schematic and the wiring. If your microcontroller has no A/D converters, you can use a variation on the R-C circuit used with the rctime command.
- Ultrasonic Sensors For longer ranges, ultrasonic ranging modules work well. Just like sonar devices, they send out a ping of ultrasonic sound, and then time how long it takes to bounce back. The longer it takes for the ping to return, the further away your target is. There are several different models. The SensComp/Polaroid sonar-ranging modules can read a range from 6 inches to 35 feet. They have an initiation pin and an echo pin. To use them, you set the initiation pin high, then use the rctime command on the echo pin to measure how long it takes to return a signal. These modules are useful but expensive, and they draw a significant current (up to two amps) when they send the ping.The Devantech SRF family of ultrasonic sensors are a cheaper alternative to the Polaroids. The cheapest one, the SRF04, works in the same way as the SensComp/Polaroid model: you set an initialization pin high, then wait for a return on an echo pin. To determine the distance, you divide the time taken by the speed of sound in your microcontroller’s software. More expensive models like the SRF08 allow you to just get the distance by communicating with the sensor using a protocol called [I2C]. If you’re using the Devantech SRF04 or the SenseComp/Polaroid module, you will need to do a little more programming. You can send out the ping with a simple pulsout command on the INIT pin of the module. You can time how long it takes the sound to bounce off the target and return using either a pulsin command or an rctime command. You will need a constant for the speed of sound to convert the microseconds returned by these commands into inches (73.746 microseconds per inch) or centimeters (29.033 microseconds per centimeter).
distance var word
conversionFactor con 137 '54 for centimeters
initPin con 11 'pin number for init pin
echoPin con 8 'pin number for echo pin
debug "start"
pause 500 ' start program with a half-second delay
main:
pulsout initPin,10 ' 10us init pulse
pulsIn echoPin,1, distance
distance = distance/conversionFactor
debug "Distance: = ", DEC distance, "inches",13
pause 100
goto main
- Flex Sensor For small distances these are very easy to use.
- Magnetic Sensors If you have very precise positioning requirements on the scale of the human body, consider magnetic motion trackers (http://www.polhemus.com or http://www.ascension-tech.com). These give you extremely fast and accurate readings for all six degrees of freedom via RS-232 serial communication. The object that you’re tracking has to be tethered to a small magnetic sensor. The range for the most accurate readings (less than 0.1") is about 1 yard radius, with a bigger range for less accurate readings. Large amounts of iron in the room will reduce the accuracy. These sensors are expensive. They cost thousands of dollars, but you can’t beat their accuracy with any homegrown solution. They’re great for applications where a person will stand still in one place and move parts of her body around or move objects around her body. Virtual reality designers love them. If you need precise positioning for these kinds of applications, the investment will save you hundreds of hours trying to get precise six-degree tracking on your own.
- Motions Capture Systems for Animation In the $10,000 range, you can find a variety of sensors in the entertainment industry for motion capture for special effects and animation. Every year at the Association for Computing Machines’ SIGGRAPH conference, you will see new schemes for doing this. Often these systems require installation into a special purpose room. For example, Vicon (http://www.vicon.com) makes a system for motion capture that uses an array of cameras spread around the perimeter of an empty room. Retroreflective tape or balls (like the paint used in highway lines, that reflects light very well) are attached to the body or object that you want to track. The cameras are designed to read only infrared light, which is reflected by the retroreflective tape. The data from all the cameras is combined to generate a three-dimensional track of the tape spots in space. To track a person, the spots are attached to all of the person’s joints and whatever other body parts you want to track. Though motion capture systems are very accurate, they are also very expensive and require considerable computer expertise and horsepower to set up and maintain.
Rotational Movement
- Potentiometer The simplest rotation sensor is the ordinary potentiometer. For example, if you want your user to turn a wheel to adjust the rotation of an image or the pitch of a sound, you could attach a potentiometer to the pivot point of the wheel. The circuitry and programming for a potentiometer are very simple and covered in the “Analog Input” section of Chapter 6. There are two challenges to using an ordinary potentiometer for sensing a full 360 degrees of rotation. First, most pots do not turn 360 degrees infinitely. Second, you have to find a way to attach them to the wheel that the user is supposed to rotate. Most potentiometers don’t turn a full 360 degrees. You can find multi-turn potentiometers, but eventually they have also a limit in both directions. You can pop the back off of a pot and eliminate the physical barrier to full rotation by cutting part of the metal casing off. However, a potentiometer’s resistive band has a gap in it, positioned where the metal stops and keeps you from turning it further. You will get very erratic readings as the potentiometer’s wiper moves over this gap. You might be able to live with this if the resolution that you need from the sensor is less than the error that the gap introduces. You can also buy dual potentiometers, or continuous rotation potentiometers, which contain two wipers, and rotate endlessly through 360 degrees. By reading the signal from both wipers, you get a continuously changing reading and can avoid the error caused by the gap. You do this by discarding the reading from whichever wiper is passing over the gap at any given moment. Attaching a potentiometer to a larger wheel is usually a highly idiosyncratic problem, but there are a few guidelines that are helpful to remember. Generally, pots are too lightweight mechanically to take the force that an axle for a large wheel must take. Use a strong axle for the wheel, and then attach the pot to one of the axle’s stationary supports. Next, couple the pot to the wheel itself to measure the rotation. Make sure there is a little give in the coupling so that the eccentricities of the wheel’s movement don’t produce wear on the pot. Figure 9.9 shows three different options for coupling a potentiometer to a wheel.
- Mercury Switch These open and close depending on how they are oriented. They work by having a drop of mercury in a glass tube with two contacts at the end. When the mercury rolls to one end of the tube, the mercury conducts current between the leads and the switch is closes. When the tube is tilted the other way, the contacts are not connected.
- Accelerometers measure the change in speed of movement, or acceleration. They typically have two (or sometimes three) axes of measurement. Accelerometers are commonly used in cars to measure acceleration and deceleration. If a car decelerates too fast, the accelerometer senses it and triggers the air bags to inflate. When the two axes are perfectly perpendicular to the earth, an accelerometer only measures changes from an outside force. For example, an accelerometer mounted on a toy car would measure the car’s acceleration due to a push from you. When you tilt an accelerometer, however, it measures acceleration due to gravity. As a result, accelerometers will give you a relatively good measurement of the tilt of a body or object. Because they use gravity as a reference, they only need to be attached to the object you are sensing, thus avoiding all the mechanical hassles described above that come with attaching potentiometers to moving parts. Accelerometers will typically give you close to 90 degrees of sensitivity when it comes to measuring tilt in this way. Unless you’re using a three-axis accelerometer, or two two-axis accelerometers mounted at 90 degrees relative to each other, you’ll only get two directions of movement.Analog Devices (http://www.analog.com) makes a number of good accelerometers, among them the ADXL202E. All of Analog’s accelerometers are tiny chips, which are very difficult to solder by hand for the inexperienced solderer. However, they make a demonstration board, the ADXL202EB, that’s very easy to integrate with a breadboard. The ADXL202E has two output pins, one for the X axis and one for the Y axis. Both pins output a digital pulse whose width varies with the acceleration on that axis. You can measure the pulse width using the rctime command or the pulsin command. Analog also makes a second demonstration board, the ADXL202-EB-232, that gives you the X and Y accelerations via RS232 serial communication. This board costs over $200, though, so we don’t recommend it. Figure 9.11 shows how to connect the ADXL202EB to a microcontroller.To read the ADXL202E from a microcontroller, you simply listen for pulses coming in on the X pin and the Y pin. For most human-scale applications, just reading the varying numbers will give you a good enough resolution to do what you need to do. If you actually need to calculate the acceleration in meters per second squared, consult the data sheet available for download from Analog Devices (http://www.analog.com). The example below returns the raw numbers only.
xTilt var word
yTilt var word
XPin con 6 'pin number for init pin
yPin con 7 'pin number for echo pin
debug "start"
pause 500 ' start program with a half-second delay
main:
pulsIn XPin,1, xTilt
pulsIn YPin,1, yTilt
debug "xTilt = ", DEC xTilt, " yTilt = ", DEC yTilt
pause 100
goto main
- Compass Accelerometers cannot read rotation around the vertical axis, or pan angle. For this you can use an electronic compass. Electronic compasses work just like conventional compasses, using the earth’s magnetic field to determine rotation. Readings from a compass are not perfectly accurate ( [+-]5 degrees) and they don’t react very quickly, but for rough readings, they’re relatively easy to use. Reasonably priced models like the Devantech CMPS03 (available from http://www.acroname.com and others) send their reading back to your microcontroller using [synchronous serial communication]
- Encoder Encoders combine a rotating wheel and a light sensor to sense rotation. The heart of a common encoder is a wheel with slits cut in it. A phototransistor and an LED are mounted on either side of the wheel, aimed at it. The LED’s light will pass through the slits and be received by the phototransistor, but it will be blocked by the spokes between the slits. Your microcontroller can then count pulses from the phototransistor to find out how many slits have passed and, therefore, how far the wheel has turned. This is a relative reading as opposed to the absolute reading that a pot gives you. If your microcontroller misses a pulse, your relative position shifts, and you have inaccurate information about the wheel’s position. There is another type of encoder called an absolute encoder that does the work of counting the pulses for you and delivers an absolute position. Absolute encoders sound great, but they typically have less resolution than potentiometers. Both types of encoders can continuously move 360 degrees around a circle.
Video Tracking
see
[VideoTracking]
Making Movement
- Servo Motors The easiest thing to work with are the little servo motors made for Radio Control Airplanes. They can be powered right off your microcontoller. The down side is that they only travel in a 180 degree arc. The great news is that they go to a given position for a give length of pulse out of your microcontroller. Any hobby store sell them starting around $17. America's Hobby Center 146 W 22nd 675-8922
- Regular DC Motors
- Solenoids
- Stepper Motors
- Muscle Wires These are wires that expand and contract depending on whether current is passed throught them. Mondo Tronics Inc. San Anselmo CA 1 800 374-5764
Sensing Light
- Photoresistor also called photocells. These resist current to differing degrees depending on how light or dark it is.(Radio Shack#...)
- Photodiode
- Phototransistor
- Position Sensing Diode
Making Light
- LED's
- AC dimmers
- LCD's displays
- Video display from a microcontroller
Touch
- Force Sensative Resistors</H3> These resist current to differing degrees depending on how hard they are being pressed.
- FSRs
- Home Grown FSR
- Qtouch
- Piezo
- FlexSensor
- Force Feedback
- Vibration
- Thermistor These resist current to differing degrees depending on how hot or cold it is. (Radio Shack#...)
Sensing Sound
- ROC The simplest way to get microphone input to a computer is to use a multimedia computer’s microphone or audio inputs. You don’t need to add any additional circuitry,; the multimedia computer can sample the sound wave very often, and there are many software tools available for analyzing the samples.
- Max/MSP is particularly strong in this area. For volume, you just use the MSP adc~ object and connect it to a float~ box, which will show you the incoming instantaneous amplitudes. The best tool for doing a more fuller analysis is Miller Puckette’s fiddle~ object at http://www-crca.ucsd.edu/~tapel/software.html. Fiddle~ will work with both Max/MSP and PD, which is a shareware mMax-like environment for Windows.
- The Director MX Xtra GetSoundLevel (http://www.physicalbits.com) is also easy to work with for getting sound amplitude. It gives you the general sound input level, or two separate left and right levels if you use a stereo microphone. If you spread two microphones out, this could give you rough position information of a object emitting a constant sound. There are also xXtras for sensing pitch, using FFT. One that we like is the asFFT xtraXtra, available from ASCI (http://www.as-ci.net/asFFTXtra/).
- Java can get sound input in several ways, but the most powerful way is to use the JSynsyn classes (http://www.softsynth.com/jsyn/). JsynJSyn includes tools for both analysis and synthesis of sound using Java. Amit Pitaru has extended Processing using JsynJSyn in a tool kit called Sonia (http://www.pitaru.com/sonia/). Live sound input and analysis is one of the many things you can do with Sonia.
- microphone
- speech
- telephone sounds
- pitch to midi
Making Sound
- your computer
- freqout
- telephone sounds
- sample sound playback
- single board computer
Identity
Tracking objects in a space becomes more complicated when you’re trying to track more than one. Not only do you need to know where each object is, but also which one is where. Many of the sensors covered here will not support multiple targets. For example, our beloved IR and Uultrasonic sensors will bounce off the closest target, not noticing any targets behind it. The main technique for establishing identity of multiple targets is to give each targets a distinct signature.
Three of the most common commercial identification technologies can interface relatively easily with a microcontroller or a multimedia computer: Bbarcode scanners, RFID tags, and magnetic swipe card readers. Radio Frequency Identification (RFID) tags are stickers or small tokens which that carry a unique ID number. When radio waves are bounced off an RFID tag, the tag reflects the radio wave back, but the reflection carries the ID number with it. Passive RFID tags get their energy from the radio wave itself, and require no battery or other form of power. Passive RFID tags only work over short distances. If you’ve ever bought a book or a CD and seen the sticker with a spiral metal pattern on it, you’ve seen a passive RFID tag. Active RFID tags have their own power source, and can work over longer distances. These are much more expensive than passive tags. They’re used in commuter toll booth passes like EZ-Pass. The receivers for RFID range in cost from $100 and up. SkyetTek (http://www.skyetek.com) sells a small receiver for avout about $100 that interfaces via RS-232 serial to a microcontroller, and can be embedded into many projects. Passive RFID tags cost less than a dollar apiece, generally. Barcode scanners use a laser to scan the pattern of light and dark bands on a UPC symbol, and convert it into a string of text. They’re ubiquitous in retail stores these days. You can find barcode scanners with RS-232 serial ports relatively easily. Symbol Technologies (http://www.symbol.com) is the biggest manufacturer of barcode scanners, and has a wide range available. Used barcode scanners are easy to find on eBay as well. They usually come with software for printing the out the barcode stickers. Magnetic swipe card readers ise use a magnetic tape recorder head to read the magnetic tape on a credit card or ID card and convert it to a string of text. They’re also easy to find on eBay and many of the electronics retailers mentioned in this book. Interfacing them to a microcontroller is a little trickier; it generally involves synchronous serial communication.
While commercial ID systems aren’t terribly difficult to use, they don’t work well at longer ranges (greater than a meter). In addition, the expense and overhead of learning the protocols may be more than you need. There are many more homegrown solutions for identifying objects as well. Generally, any property that you can be sense can be assigned to in varying degrees to use as a signature to distinguish each object that you want to track. Following are three approaches to one problem, the tracking of game pieces on a board (e.gfor example, chess, checkers, etcand so on).
- Color:. You could give an individual game piece a unique color, and place a camera above the board. Then you’re able to track all the game pieces using any of the video tracking techniques covered in this chapter. This relies on very controlled lighting, and on the players’ hands not obscuring the game board too much. You can also get the TCS230 color sensor (available from http://www.parallaxinc.com) that senses differences in color. It’s basically a very low- resolution camera that outputs the color differences only, with no information about the shape of what it sees.
- Flashing sequence:. You could give each piece its own microcontroller (consider the cheaper PICs here), and have each one emit a different serial string, which pulses an infrared LED. (text missing here??) \Use an infrared phototransistor attached to a serial input pin, and to read the serial data in through the phototransistor. The receiving microcontroller will know each different game piece by its serial signature. In order to do this, you need to be able to make an infrared LED visible on the top of each game piece. You should also make sure that each piece isn’t constantly sending its signal, so that there’s less chance that they’ll overlap. One method to control this overlap is to have the receiver work much like an orchestra conductor, constantly sending data to each piece, and waiting for a reply before it prompts the next piece for an update.
- Resistance:. You could make the board a tracking device. Put two electrical contacts in each square of the board. One connects to an analog input pin, and the other to 5 volts. Put a different value resistor in each game piece, and position the ends of the resistor so that it makes a connection between the contacts of a game square whenever it’s put down. When you read all the inputs on the game board, you’ll be able to sense which piece is where, because each will return a different analog value.
- Continuity Another common technique for establishing identity is watch things over time. To do this, you assign a unique id ID to each object when your sensors first find it. You then assume that objects don’t move drastically and that an object from each subsequent sensor reading will be the same one as the closest object in the previous reading.
[Add to or Correct This Page]|[Yes, this is a Wiki]