13.07.2015 Views

Hacking Sensor Interfaces - MSc Sound Design

Hacking Sensor Interfaces - MSc Sound Design

Hacking Sensor Interfaces - MSc Sound Design

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Hacking</strong> <strong>Sensor</strong> <strong>Interfaces</strong>Chris Handwww.mungbean.netThe aim of this session is to introduce you to building and hacking your own sensors and actuators to usewith software such as Max/MSP, Pd or vvvv and sensor interfaces such as iCubeX, Phidgets or Teleo. Youdon’t need to have any experience in electronics at all. There’s a tiny amount of electronics theory includedhere, but it’s kept very simple – and you don’t even need to understand it to follow the instructions. Ifyou’re interested in taking these ideas further see the Further Reading section below. There’s also a list ofuseful websites and electronics suppliers.Safety - Mains Electricity and SolderingUnless you know what a relay or an opto-isolated triac are, don’t even think about how youmight control mains-powered devices. Getting it wrong can be extremely dangerous (i.e.fatal). I recommend you use battery power or devices that take their power from USB(although take care not to make a short circuit and blow up the USB port on your best laptop).Similarly, soldering irons get extremely hot and shouldn’t be used for anything other thansoldering. Never shake a hot soldering iron – flying molten metal isn’t good for eyeballs. Endof disclaimer.<strong>Hacking</strong>There are various meanings of “<strong>Hacking</strong>” in use, ranging from doing neat programming tricks to gainingcriminal access to a computer system. As used here, <strong>Hacking</strong> means appropriating or subverting thefunction of some technology for our own purposes. The classic input hack is to take a cheap qwertykeyboard and replace some of the keys with switches connected to things you want to sense.A major benefit of <strong>Hacking</strong> existing devices is the saving of cost and time – it’s almost always faster toprototype or “sketch” an idea in hardware if you can find a device that almost does what you need and thenmodify it. And if your idea doesn’t work out then you’ve saved money by using a low-cost device or a junktoy rather than building some custom electronics. <strong>Hacking</strong> should also be fun in and of itself – thesatisfaction of making technology do your bidding is often in stark contrast to our everyday frustrations withdevices and systems.One of the downsides of <strong>Hacking</strong> is that if something breaks then it’s sometimes difficult to fix, since youdidn’t design the circuitry and probably don’t even know exactly how the device works. For this reason ifyou decide to use a hack for a mission-critical piece of work, such as an installation in a high-profileexhibition, then you should seriously consider having some back-up hardware or spare parts on-hand incase the worst happens. Also take extra care when disassembling electronics as many connecting wiresare very fragile. It’s a good idea to cover delicate electronics with masking tape while soldering or desoldering,as a splash of solder in the wrong place can kill a perfectly good circuit.Culturally and politically, <strong>Hacking</strong> is associated with DIY Culture and the punk ethic, and encouragespeople to participate regardless of their apparent skills and in defiance of warnings and declarations ofpower from manufacturers and vendors of equipment. The MAKE blog urges readers to “Void yourwarranty, violate a user agreement, fry a circuit, blow a fuse, poke an eye out...”. Hacker communities areorganic, grass-roots organisations and until recently most of the activity worth following was online, or inface-to-face meetings such as Dorkbot. Books – which inevitably trail real life by a year or two – are harderto find, although Nicolas Collins and Reed Ghazala have both published practical guides to hacking andcircuit bending recently.Using a <strong>Sensor</strong> InterfaceComputers are digital machines (they speak binary, using only 0 and 1), while the real world is analogue.Phenomena such as light, pressure and temperature vary continuously and can be measured accurately butthese measurements need to be converted into a digital format that the computer can read. This is done byanalogue-to-digital converters (ADCs).The easiest way of connecting analogue sensors to the computer is using an off-the-shelf sensor interface.There are many of these available these days: iCubeX, Teleo, Phidgets, MIDItron and so on. These connectto the computer or other equipment via MIDI, USB or sometimes RS232 (serial) or Ethernet. Some MIDIChris Hand 28/1/10 1/10


controllers like the Kenton Control Freak have inputs for external sensors. It’s possible to save money bybuying a kit and making an interface yourself. Using an Arduino microcontroller board is another costeffectiveroute, but outside the scope of this tutorial. There’s no “best” way – it simply depends on whatequipment you have access to, how much money you want to spend, and what kind of software you wantto use to access the sensors.The commercial interfaces all have a selection of sensors available, but with a little effort it’s quite easy tohack your own which is much cheaper and more fun. If you want to go all the way you can hack a gamecontroller to turn it into your own sensor interface. Both of these kinds of hacking are covered below.Connecting Variable ResistorsMost of the simple sensors we use are variable resistors. A resistor opposes the flow of electrical current ina circuit – the greater the resistance, the greater the opposition. A sensor converts (or “transduces”) aphysical phenomenon, such pressure or light level, into a resistance. This can then be measured by theinputs on the sensor interface box.The simplest kind of variable resistor is a potentiometer or “pot”. These are very common – the volumecontrol on your stereo, for example – and they’re cheap. The schematic diagram below shows a potconnected to a sensor interface. This is a good starting point for testing your set-up.Resistance is measured in Ohms, written as Ω (the Greek letter omega) or sometimes as “R”. It’s commonto leave out the “ohms” completely, e.g. “a 10k pot” is a potentiometer with a maximum resistance of 10kΩ(10 kilo-Ohms or 10,000 Ohms).red wire+5 volts(other wire)sensor voltageeggplantia5@flickrpotentiometerblack wireground (0 volts)sensor interface(a) typical potentiometer(variable resistor)(b) schematic showing potentiometer connected tosensor interfaceThe middle terminal on the pot is connected to the “wiper”, which moves from one end of the resistor to theother as you turn the knob, changing the resistance between the middle terminal and each end. This is akind of “voltage divider” circuit, as seen below (a). The voltage divider is an important circuit, and allsensors and switches connected to the sensor box will form some kind of voltage divider.R1R2+ve voltage, Voutput voltageground (0V)(a) Basic voltage divider circuitVoltage divider circuitOutput voltage dependson ratio of R1:R2R1 > R2: output lowerR1 < R2: output higherR1 = R2: output is V/2+ve voltage, VVR1output voltageR2ground (0V)(b) sensor as variable resistor in voltage dividerChris Hand 28/1/10 2/10


Connecting <strong>Sensor</strong>sMost sensors are variable resistors, but with two terminals not three. So to connect them to the sensorinterface we add another resistor to make a voltage divider as shown above (b), and in the photographbelow.When experimenting with sensors and switches it’s quick and easy to use terminal blocks instead ofsoldering. The photo below shows a light-dependent resistor (LDR) connected in a voltage divider circuitwith a resistor using a terminal block. A good rule of thumb is to choose a resistor with a roughly similarvalue to the sensor – in this case the LDR’s value varies between 36k and 88k, so we’ve used a 100kresistor (identified by brown-black-yellow stripes).LDR in a voltage divider circuitwith a 100k resistor. The middlewire is the variable output.SwitchesWe also connect switches using a circuit similar to a voltage divider, as shown here.+ve voltage, V+ve voltage, VR1switchto inputgroundswitchR2to inputground(a) switch with pull-up resistor(b) switch with pull-down resistorUsing a “pull-up” resistor as shown in (a) means that the output voltage will be high when the switch isopen, and low when the switch is closed. The set-up in (b) is reversed, i.e. when the switch is open theoutput will be low, going high when the switch is closed. You can use either of these circuits to connect aswitch or push-button to a sensor box. Typically we would use a 10k resistor in this pull-up or pull-downconfiguration.Chris Hand 28/1/10 3/10


Types of SwitchThe most common switches we encounter from day to day are push switches (push on – release off, or viceversa) and toggle switches (flick it over – it stays over, e.g. on/off switch). These are designed for control byhuman fingers and are not well-suited to sensing objects. The switches listed below are adapted for specialsensing applications and are much more useful for hacking purposes.Tilt SwitchMakes a connection when tilted beyond a certain angle. Easy to use, cheap and good for detecting generalmovement. Might be used on a motorcycle anti-theft alarm. Get more sensitivity by using several togethermounted at different angles.Reed SwitchConnection is made or broken by moving a magnet close to – or away from – the switch, whose contactsare extremely light and hence moved by the magnetic field. Typically used in burglar alarm systems todetect opening of windows and doors.Pressure Mat/Dance MatA pressure mat is a large flat switch that makes a connection when you step on it. Used in burglar alarmsby hiding them under door-mats and stair carpets where intruders won’t see them. A simple way ofdetecting someone entering your installation space. Dance Mats such as those used with game consoles(e.g. Dance Dance Revolution) are similar but feature multiple switches.MicroswitchSmall, sensitive switch capable of detecting small movements mechanically via a lever mechanism. Typicaluse is again on burglar alarms, to detect someone opening the case. Useful for detecting the opening of abox lid or the arrival of a sliding/moveable object.Types of <strong>Sensor</strong>There are many different kinds of sensor you can connect in the configurations shown above, and someonline lists are provided in the Further Reading section. O’Sullivan and Igoe’s book also has a very goodoverview.Light-Dependent Resistor (LDR)As the name suggests, this is a component whose resistance changes depending on the amount of lightfalling on it. These are cheap, reliable and very versatile. Put one in a cupboard and detect the opening ofthe door as light falls inside. Put one under an opaque object and you can detect when it’s lifted up. Canalso create a simple interface with existing equipment – stick one on an indicator LED or display to sensewhen something has happened (e.g. screen of mobile phone lighting up when someone calls).Infra-red DistanceSends out a beam of invisible infra-red light which bounces off a nearby object and provides a measure ofdistance from the sensor. This is typically short-range (less than a metre), but varies with different models.Output may be analogue or digital. Sharp have a good range of these, and GP2D12 has an analogueoutput. These are used in Roland musical instruments such as the MC-505 and known as the “D-beam”.Infra-red ProximitySimilar to Infra-red distance, but the aim is to detect the presence or absence or an object, over a largerdistance. The classic one is a Passive Infra-red <strong>Sensor</strong> (PIR) which is used in alarm systems high up in thecorner of a room, and to trigger automatic lights in driveways and gardens. Output is digital: on or off.Infra-red ReflectorAnother kind of infra-red sensor whose purpose is to detect linear or rotational movement. The object thatmoves typically has a wheel with slits in, or has black and white stripes, and the IR sensor detects blackareas or the slots, each of which will result in a digital pulse. Counting the pulses gives an measure ofposition, while counting the rate of pulses measures speed. Used in car rev-counters and the older ballbasedcomputer mice. Can be fiddly to set up right since not all blacks appear black to an IR photodiode,Chris Hand 28/1/10 4/10


especially marker pens – use paint or print the pattern on a laser printer. If the movement is large you canmake a crude but similar setup using an LDR and an LED.Ultrasonic distance/rangefinder.Similar to infra-red distance sensor but uses ultra-sonic pulses. Capable of measuring much largerdistances. Main drawbacks are that a faint clicking sound may be audible, and that indoors the pulses willreflect off hard and shiny surfaces and can cause false triggering. Usually digital output.Hall Effect <strong>Sensor</strong>Outputs a voltage that varies with the strength and direction of magnetic field hitting it, e.g. from a magnetmounted on an object you want to detect. Can be unreliable unless you can guarantee the absence ofinterfering magnetic fields such as those generated by nearby electric motors or TV sets.Electronic CompassGives a reading proportional to its orientation towards the Earth’s magnetic North. Usually digital output.Thermistor/ThermocoupleA thermistor changes resistance according to temperature, while a thermocouple outputs a voltage thatvaries with temperature. Thermocouples are used in electronic thermometers.Flex sensorA flexible sensor that changes resistance according to how much it is bent. Typically used on the fingers ofvirtual reality gloves. Fun to play with but not so cheap (around £5 each) and hard to find.Force-Sensing Resistor (FSR)Similar to flex sensor but detects how much force is applied, e.g. when you press it. Could be used todetect whether or not someone’s sitting on a chair, for instance. Also not that easy to find.AccelerometerMeasures acceleration in 2 or 3 axes. Famously used in the Nintendo Wii remote control, as well as indigital cameras to detect rotation of the camera and mark the photo accordingly. Also used in the AppleiPhone to auto-rotate the screen. Relatively expensive (£30 or more) – hence the popularity of Wii remotesas gestural controllers for music etc since they cost around the same and you get Bluetooth and somebuttons built-in.GPS receiver (Global Positioning System)Gives longitude, latitude and altitude readings as well as date and a very accurate measure of time. Somewill also output speed. As used in car satellite navigation systems. Not really a sensor as such – typicallyconnects to a computer by Bluetooth or a USB cable. Pretty cheap these days, and increasingly being builtinto mobile phones which makes them ripe for interesting software hacks and mash-ups with the likes ofGoogle maps. Downside is that the current generation of devices only works outside and needs to be ableto “see” a number of satellites in the sky to give a reading, so built-up urban areas can be a problem.Chris Hand 28/1/10 5/10


<strong>Hacking</strong> a Game ControllerA typical game controller features two joysticks and lots of buttons (often 16 or more). The “HumanInterface Device” or USB-HID specification defines how software should read it, and so any software thatcan talk HID can read a game controller (and mouse, keyboard, trackpad and so on).To read a game controller in Max/MSP you use the hi object, while in Pd there’s an equivalent hid object.Analogue joysticks are built from two potentiometers mounted at right angles. If you take off the case youwill be able to see where the three pins of each pot are soldered into the circuit board. The simple trickinvolves removing the joystick (the hard bit) and replacing the pots with sensors in voltage divider circuits(or replacement 3-pin pots) as mentioned above.Depending on the design of the circuit board you might find it easier to cut the legs of the pots in thejoystick and then de-solder the remaining stumps with a de-solder pump. Watch that you don’t damagethe rest of the circuitry on the board while de-soldering.The photo below shows a Logitech Cordless Wingman controller with one joystick removed and twopotentiometers added in its place. The one on the right is a multi-turn pot, which has to turn 12 completecycles to change from minimum to maximum resistance.For detailed tutorials on game controller hacking, see Andrew Benson’s tutorial on the Cycling’74 website,or the chapter in Nicolas Collins’ book. (Details on both are below.)Chris Hand 28/1/10 6/10


OutputSome sensor interfaces, such as the larger iCubeX boxes, have outputs which can be used to turn externaldevices on and off. In the case of the iCubeX this works by switching on or off the +5V supply pin, so tocontrol a low-power 5V circuit simply connect it to the top (+5V) and bottom (ground) pins. However, theoutputs can only supply 30 milliamps (mA) of current each, which is very small. To control higher-powereddevices such as electric motors we can use a relay.Reed Relay CircuitA reed relay is a switch, very similar to a reed switch, but controlled by a low power electro-magnet. Whena voltage is present across the coil of the electro-magnet, the switch will change over. Because the relayuses magnetism to change the switch, it’s isolated from the coil’s circuit. There are reed relays that canwork on very low currents that we can drive them from an output on a sensor interface.The schematic below shows a relay connected to an output of a sensor interface. The switch contacts canbe connected to any low voltage circuit to turn it on and off. (The diode connected across the relay’s coil isthere to protect the interface from being damaged by backward-flowing current generated by the coil.)+5 volts(actuator output)red wire(not used)diodeground (0 volts)black wireThe photo below left shows a small circuit board with the reed relay and its protecting diode (connectionsare made on the underside of the board). The photo on the right shows the whole circuit connected to asmall electric motor with its own 3V power supply.Chris Hand 28/1/10 7/10


Further ReadingMassimo Banzi. Getting Started with Arduino. O’Reilly, 2008 (ISBN 0-596-15551-4)Very accessible and non-technical introduction to Arduino, with backgroundon tinkering, hacking toys and keyboards etc. Probably the best place tostart if you think you might want to go down this road. (It's actually quitepainless!)Bert Bongers. “Physical Interaction in the Electronic Arts: Interaction Theory andInterfacing Techniques for Real-Time Performance”. in Wanderley &Batterley (eds) Trends in Gestural Control in Music. (CDROM), IRCAM:Paris, 2000. (ISBN 2-84426-039).Also available at http://www.xs4all.nl/~bertbon/downloads/IRCAM.pdfNicolas Collins, Handmade Electronic Music: The Art of Hardware <strong>Hacking</strong>.Routledge, 2006 (ISBN 0-415-97592-1)Great book with a wide range of material, from soldering to circuit bending,and featuring Nic’s famous recipes for CMOS logic based synthesisers. Alsoincludes a chapter on hacking joysticks. Recommended.Reed Ghazala, Circuit-Bending: Build Your Own Alien Instruments. John Wiley &Sons, 2005. (ISBN 0-764-58887-7)Usman Haque and Adam Somlai-Fischer. Low Tech <strong>Sensor</strong>s and Actuators forArtists and Architects. Self-published, 2005.http://lowtech.propositions.org.uk/Excellent free eBook focusing on hacking toys for building interactiveenvironments.Robin Hollands. The Virtual Reality Homebrewer’s Handbook. John Wiley & Sons,1996. (ISBN 0-471-95871-9)Lots of DIY projects to build things like 3D joysticks and video projectorsusing low-cost components. Likely to be hard to locate by now.Tom Igoe, Making Things Talk. O'Reilly, 2007. (ISBN: 0-596-51051-9)More advanced book than "Physical Computing", covering RFID, bluetooth,networking and connecting to the Internet, Processing, Arduino and more.Dan O'Sullivan and Tom Igoe. Physical Computing: Sensing and Controlling thePhysical World with Computers. Thomson, 2004. (ISBN 1-59200-346-X)Excellent book that's definitely worth buying if you're at all interested in thisarea. Very good basic introduction to electronics along with sensors andmicrocontrollers (although published before Arduino came out). Packed withexample circuits and code. Recommended.Eduardo Reck Miranda and Marcelo M. Wanderley New Digital MusicalInstruments: Control and Interaction Beyond the Keyboard. A-R Editions,Inc., 2006. (ISBN 0-89579-585-X)Includes chapters on gestural controllers, sensor interfaces and biosignals.Chris Hand 28/1/10 8/10


Websites and Blogshttp://www.tigoe.net/pcomp/index.shtmlTom Igoe teaches on the ITP course in New York and wrote the classicPhysical Computing book with colleague Dan O'Sullivan. His website has avast collection of tutorials, code snippets, sensor information and more.http://www.sensorwiki.org/Nice overview of kinds of sensors and where to get them, as well as listingsensor interfaces and kits. Part of a broader wiki project originated at McGillUniversity (Montreal)http://cnmat.berkeley.edu/resourcesLibrary of information on materials, sensors, interface devices, tools etc,produced by Centre for New Music & Audio Technologies (CNMAT) at UCBerkeley Music Department.http://www.kobakant.at/DIY/“How to get what you want” – tutorials and documentation on many kinds ofDIY sensor and interface techniques relating to “soft circuits”, smarttextiles/crafting and wearable technology. A project by Mika Satomi andHannah Perner-Wilson aka Kobakant.http://www.prc68.com/I/<strong>Sensor</strong>s.shtmlAnother list of sensors. Messy but incredibly exhaustive.http://www.cycling74.com/story/2007/3/12/113645/135Andrew Benson’s tutorial ‘Making Connections: Connecting a Joystick toMaxMSP/Jitter’ on the Cycling’74 website. Shows how to use the hi object,interpret the data it spits out, and how to hack the joystick.http://www.dorkbot.org/Dorkbot is a world-wide hacking movement bringing together “people doingstrange things with electricity”, generally artists, engineers, designers,musicians and computer nerds. Dorkbot Alba, the Scottish group, meetsregularly in the Forest Café in Edinburgh.http://www.epemag.wimborne.co.uk/solderfaq.htmBasic guide to solderinghttp://www.anti-theory.com/soundart/circuitbend/Reed Ghazala's website on circuit bendinghttp://blog.makezine.com/Online companion to O'Reilly's MAKE magazine. Lots of example hacks andprojects to build.http://delicious.com/pixelfrenzyChris’s bookmarks – search for tags like sensors, hacking, interaction,software etc.Chris Hand 28/1/10 9/10


Electronics SuppliersUnless specified otherwise these are UK suppliers. Ordering from the USA ismuch slower and can incur extra charges through excise duty, but issometimes the only way of getting hold of specialist parts.Maplin http://www.maplin.co.ukIncreasingly focused on consumer goods and toys these days, but still useful.The Edinburgh shop is in Dalry, next to Somerfield’s supermarket.Omni Electronics. 174 Dalkeith Road, Edinburgh EH16 5DX tel. 0131 667-2611Small specialist Edinburgh shop with knowledgeable staff.Farnell http://uk.farnell.comRS http://rswww.comRS and Farnell are the two main professional electronics suppliers in the UK.Not always the cheapest, but they carry a huge range of stuff and delivery isfast. Farnell has a minimum order of £20.Rapid Electronics http://www.rapidonline.com/Smaller range than RS and Farnell but often better prices. More educationoriented.Sparkfun http://www.sparkfun.com (USA)The hacker's favourite. Lots of very cool bits and pieces, including breakoutboards they make and produce themselves.Robot Electronics http://www.robot-electronics.co.uk/Operated by Devantech who make great ultrasonic distance sensors (most, ifnot all have digital not analogue outputs).Active Robots http://www.active-robots.comMuch the same range of sensors as Robot Electronics, plus Lego and othereducational stuff. Sharp range of IR sensors, Devantech ultrasonic sensors,uMP3 playback module. Also sell the Phidgets range.Digikey http://www.digikey.com (USA)Not cheap, and US-based so delivery is slow, but sometimes they have stuffyou can't find anywhere else.Images Scientific Instruments http://www.imagesco.com/ (USA)Flex sensors (hard to find) and Force-Sensing Resistors.Conrad http://www.conrad-direct.co.ukGermany's equivalent of Maplin’s. They have Force-Sensing Resistors(search for “FSR”)Gremlin Solutions http://www.gremlinsolutions.co.uk/UK supplier of arcade machine controls and parts. Good for large , robustbuttons.Coinop Express http://www.coinopexpress.com/Another supplier of arcade machine parts, including coin mechanisms. Basedin Hong Kong.Chris Hand 28/1/10 10/10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!