Sensors allow the robot to understand its environment so it can interact with it successfully. For example, a robotic arm controller needs to know when it has reached the limit of its movement; otherwise, if it keeps supplying power, it will burn out the motor or damage the arm. Examples of commonly used sensors are: === Limit Switches === Mechanical or optical switches can be used to determine when a mechanism has reached its limit of movement. * Mechanical switches work like light switches on a wall; [[Image(http://hobbydistrict.com/wp-content/uploads/2015/02/Roller-Limit-Switch-Default.jpg,15%,right,margin=10)]] two or more brass electrical contacts can be connected and disconnected by an internal brass bar. A cut-away view shows a limit switch whose top electrical contact will connect to either the bottom right or top right contact depending on whether the switch is pressed or not. [[Image(https://i.ytimg.com/vi/q6nP1FjxAMU/maxresdefault.jpg,15%,left,margin=10)]]. '''Exercise''': Use a multimeter to test the continuity (conductivity) between the contacts on a mechanical limit switch. Press the switch and observe how the continuity changes. Note: Using mechanical switches can be complex. When a switch contact closes or springs open, it actually bounces several times before making a secure connection. Although this happens fast, usually 10-50ms, that's a long time for a computer and the computer will see the switch close-open-close-open-close-open... Software needs to take special measures to ''debounce'' mechanical switches. * Optical switches work like the safety on your garage door: a beam of light (often invisible), is emitted from a source and a light detector conducts or doesn't conduct based on whether it sees the beam of light. [[Image(https://cdn-shop.adafruit.com/970x728/2168-03.jpg,15%,right,margin=10)]] Some optical switches (like your garage sensor) operate on the principle of something breaking the beam and are called ''opto-interrupters'' or just ''beam-break'' sensors. Other optical switches look for a beam of light bouncing off a nearby object; these are called ''opto-reflectors'' or ''proximity'' sensors. [[Image(http://rohmfs.rohm.com/en/products/images/faq/opto/optical_sensor/common/faq_01.gif,left,15%,margin=10)]] An obvious advantage of optical sensors is that no contact is required. An arm slamming into a mechanical switch can easily break it, but if the arm passes through and blocks a beam of light, there is no risk of mechanical damage. {{{ #!html
}}} === [http://engineering.nyu.edu/mechatronics/Control_Lab/Criag/Craig_RPI/SenActinMecha/S&A_Optical_Encoders.pdf Rotary Encoders] === Opto-interrupters are commonly used to track the rotation of a shaft to monitor and report (encode) its position or count its rotations. [[Image(http://cdn3.volusion.com/vyfsn.knvgw/v/vspfiles/photos/am-3132-2.jpg?1442240393,15%,right,margin=10)]] In an optical encoder uses a disk attached to the rotating shaft with slots cut out. The disk rotates between the light emitter and detector of an opto-interrupter, alternately passing the light beam through the slot and then blocking the beam between slots. [[Image(https://ni.i.lithium.com/t5/image/serverpage/image-id/172208iF93365BB55D1262F?v=1.0,15%,left,margin=10)]] A tiny optical encoder can have 360 or more slots cut in the rotating disk allowing a beam-break to occur for every 1-degree of rotation of the shaft. Attaching a rotary encoder to a wheel's axle allows the robot controller to determine whether the wheel is turning or slipping, how fast the wheel is turning, and with a clever encoder arrangement called quadrature, even determine which direction the wheel is turning. Similarly, an encoder at the joint of an arm allows the controller to precisely determine the angle of the arm which is critical to controlling it. Techniques other than optical interruption are also used for encoders including magnets and capacitance sensors, but optical encoders are most common. Exercise: Ask a mentor to help you take apart an old-style mouse (the kind that had a heavy metal ball instead of bright lights underneath). In these mice, the ball turned two shafts (X and Y directions) that each had an optical rotary encoder attached. The mouse movement was detected by counting the interruptions of the light beam in each axis.