E N D
Lecture 5: Sensors
A sensor is any element that provides information from the to the robot, either about the environment or about the robot itself. Sensing can include contact switches, pressure transducers, encoders and resolvers, position, motion and rate detectors, photo-detectors, temperature sensors, imagers, microphones, IR, ultrasonic range detectors and even monitors for internal circuit loads.
We will investigate a number of different categories of sensors that can be implemented with the BasicX-35 microcontroller. Generally we need a way to convert a voltage level into a digital value. The BX-35 has 8 inputs that accept analog inputs (voltage levels) and convert them to numeric values (digital samples). These A/D converters are connected to pins 33-40.
Contact Sensors Switches - The simplest type of contact sensor is the switch. A switch can be a toggle type that can be set to remain on or off (i.e. the electrical path through the switch is connected or unconnected). Switches can be momentary switch is spring loaded so that once the force used to trip the switch is removed it returns to its original condition. Momentary switches can be normally open (no connection) or normally closed. Switches can be combined with some type of mechanical bumper or wisker to produce a contact sensor. Microswitches are types of switches that require a very small pressure or contact force to make/break the connection. Typically a microswitch is a momentary type. In order to permit a microprocessor to read the condition of a switch we need to provide a mechanism in which the switch varies a voltage level being read by the processor. Simple on/off measurements can be read by either a digital input or an analog input. In addition to the 8 A/D inputs the BX-35 has 8 digital input/output pins that can be used to drive other circuits such as our robot servo drive motors.
BasicX-35 Example Programs - This example program assumes that you're using I/O pin 25 of a BX-35 and that you have a switch wired according to the diagram shown previously. The program reads the state of any switch connected to the pin and writes that value to a second pin (I/O pin 26, in this case). The logical state of the second I/O pin can then be verified with an oscilloscope or logic probe. An LED can also be used as shown: Sub Main() Dim State as Byte Do ' Read I/O pin 25. State = GetPin(25) ' Copy the state to pin 26. Call PutPin(26, State) Loop End Sub This program works well with any type of switch, but if you try this example using a momentary switch you will notice that pin 26 only stays in the active state as long as the button is pressed. This program would not work if you wanted to toggle the state of an I/O pin for some time after the sense switch is closed. This section taken from the Application Notes for the BasicX-24 by NetMedia. The program above is contained in a separate file called Buttons.bas provided on the BasicX-24 CD.
In order to make use of momentary buttons or switches a different approach is needed. This example program assumes that you are using pin 25 for the input and pin 26 for the output and have a momentary push button wired according to the diagram above. In this program we use the bitwise binary XOR operation to toggle the state of pin 26 each time the momentary button is pressed. Sub Main() ' This program reads the state of a switch and toggles the ' state of an output pin whenever the switch is pressed. Const InputPin As Byte = 25 Const OutputPin As Byte = 26 ' Configure pins. Call PutPin(InputPin, bxInputTristate) Call PutPin(OutputPin, bxOutputHigh) Dim State as Byte State = 0 Do ' Toggle State if switch is pressed. If GetPin(InputPin) = 0 Then State = State Xor 1 ' Pause a quarter-second for button de-bounce. Call Delay(0.25) End If ' Write State to output pin. Call PutPin(OutputPin, State) Loop End Sub
Pressure Transducers Transducers are made from a material that converts one form of energy into another. In this section we will study a type of transducer that converts pressure or vibration into electrical energy (and vice versa). Piezoelectric polymer sensors are one of the most versatile and economical forms of pressure transducers available. There have been significant developments in the technology of piezoelectrics since the discovery of the piezoelectric effect by the Curie brothers over 100 years ago. They found that a quartz crystal changed its size when subjected to an electrical field and that the crystal produced an electrical charge when it was mechanically deformed.