PIC Inputs
Many input devices work by some physical change altering the resistance of a component. For example,
| ¡ | the resistance of an LDR decreases when the intensity of incident light on it increases |
| ¡ | the resistance of a negative temperature coefficient thermistor decreases as temperature increases |
| ¡ | the resistance of a positive temperature coefficient thermistor increases as temperature increases |
| ¡ | the resistance across the contacts of a normally open push button changes from very high to very low when the button is pressed |
| ¡ | the resistance across the contacts of a normally open switch changes from very high to very low when the switch his closed |
| ¡ | the resistance of a pressure mat changes from very high to very low when someone steps onto it |
| ¡ | the resistance across the contacts of a tilt switch changes from very high to very low when the switch is tilted |
| ¡ | the resistance of a shock sensor momentarily changes form very high to very low when receiving a sudden mechanical shock |
| ¡ | the resistance of a moisture sensor decreases with increasing moisture |
Resistive sensors can be used as inputs to digital systems e.g.PICs by incorporating them into a potential divider.
Switch type sensors
The following devices are all basically switches (they are on or off). Their resistance changes from very low (a few ohms) to very high (a few mega ohms).
Tilt switch
|
Slide switch
|
Reed switch
|
Slide switch
|
Microswitch
|
Push button
|
Shock sensor
|
Toggle switch
|
Pressure mat
|
Float switch
|
|
|
Replacing the top resistor in a potential divider with a switch produces a digital signal that represents the state of the switch. When the switch is closed, the output goes high. In binary terms, the output state is 0 when the switch is open and 1 when closed. The value of R1 is not critical. It should be greater than 1K (to avoid wasting battery power when the switch is closed) and less than 100K to avoid problems with stray pick-up (noise).

If the potential divider output is connected to pin 3 on the PIC, the flowchart element that 'reads' the state of the switch is . .

. . . if the switch is not pressed, the state of pin 3 will be low. Control exits via N and loops round and round until the switch is pressed. When the switch is pressed control takes the Y exit.
(Note: This type of flowchart box is called a decision box. Decision boxes should have an expression in them that reads like a question. There should only be two possible answers yes or no)
Non-switch type sensors
The following devices have a continuously variable resistance that depend on physical conditions. Their resistance change is not as great or well defined as a switch, so care is needed when combining them with a pull down resistor to create a sensor to output a signal dependant on some physical property such as light or heat.
Thermistor
|
Moisture sensor
|
LDR
|
Light dependant resistor

It is straight forward to create a light sensor from an LDR. The resistance change from dark to light can be in the range of 1M - 2K. For Rapid part no. 58-0134, a 10K pull down resistor will cater for most occasions.
Moisture sensor
The value of pull-down resistor depends on the degree of wet or dry you are trying to sense and the length and separation of conductors you plan to use. It is best to use a multimeter to measure the resistance between the probes of the wettest condition you want to sense. Make the pull-down resistance 10x that value.
Thermistor
A digital temperature sensor using a thermistor is potentially quite tricky to design because of the bewildering choice of available devices. Some thermistors have quite a low resistance and they may not give a large enough change in resistance of the desired temperature range. Devices with a low resistance require a low value of pull-down resistor resulting in quite a high potential divider current which can lead to significant drain on the battery. Suitable thermistors are available from Rapid; they are part nos. 61-0415 and 61-0420. To use a thermistor as a digital temperature sensor, it may be useful to use a variable resistor to provide adjustment.

Analogue sensing
Achieving a reliable digital sensor using a resistive sensor such as a thermistor can be difficult. The temperature range you want to sense may not give a large enough change in output voltage from the potential divider. A simple solution is to use one of the PIC's analogue inputs. An analogue input measures the input voltage and converts the value into an integer number in the range 0 to 255. This conversion occurs over the PIC's power supply voltage range. If the PIC is operating from a 6V supply, then it can sense changes of input voltage as small as 24mV (6V/256).
The flowchart element that reads the analogue in input voltage is:

In the above example, the voltage input at pin 1 is stored in variable b0. (You need to refer to the PICAXE data sheets to determine which which pins have analogue inputs)
To branch to different sections of programme according to the analogue input voltage you now need to add the following element.

The voltage value at the analogue input (which was stored in b0) is compared with a chosen number in the range 0-255 (109 in the example).