servo c.4,150 ‘ initialize servo on pin c.4
do ‘ start loop
readadc c.2,b0 ‘ read pot value on pin c.2,
‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘ save as b0
sertxd (#b0,13,10) ‘ display values on screen
servopos c.4,b0 ‘ move servo on pin c.4 to
position b0
loop ‘ end loop
#picaxe 08m2
#no_data
pause 100
Figure 5.
A quick word about resistance values
and electrical current here: 10K is a typical
pot and sensor resistance value — ideal for
low current applications. Five volts can only
push half a milliamp through 10K ohms.
That’s very low current — perfect for
microprocessors, but certainly not for motors
or other high current devices which could
damage a micro.
Keep in mind that there are three related but very
different numbers changing together: resistance, voltage,
and the READADC value. Besides being a manually
adjustable knob, a potentiometer can be a rotary position
sensor. Analog servos measure their angle of rotation with
an internal potentiometer.
Use caution when connecting voltage
dividers to your PICAXE — especially pots —
You might measure the angle of a robot arm joint with
a potentiometer, or create a pantograph-style digitizer with
a few pots on the linkage joints. Per Figure 5, our PICAXE
makes quick work of using a pot to control a servo, as
shown at www.youtube.com/watch?v=JY-9ytll2EE:
Photocells (a.k.a., photoresistors or Light Dependant
Resistors, LDRs) are light sensors and very inexpensive: 50
pcs GL5528 for $2 — so stock up! Typical resistance varies
from 1K (bright flashlight beam nearby) to over 200K in
darkness. Typical room values are 2-10K.
Thermistors are resistive temperature sensors — also
cheap at 5 pcs for $1! My “10K NTC 3435” thermistors
measure 10K at room temperature; 28K in an ice bath; and
700 ohms in boiling water. Both photocells and thermistors
will need a fixed series resistor to make a voltage divider.
A 10K fixed resistor is a good starting point, but the
best fixed resistor value is generally the same as the value
of the sensor at the center of the anticipated range.
Note that a fixed series resistor will limit the voltage
range and reduce the range READADC values. It’s helpful
to note that photocells, thermistors, pots, and resistors have
no polarity, and can be hooked up in either direction.
Recall from previous issues that each of these program
listings should be preceded by:
Figures 4C and 4D show two opposite ways to make a
voltage divider using a photocell (or thermistor). Method C
will increase voltage and ADC values with increasing light
(or temperature); method D will decrease values with
increasing light (or temperature).
Photocells are fairly directional as they
catch the most light and have the lowest
resistance when they point directly at the
light source. We can make a directional
light sensor by using two photocells in
series, aimed 80 degrees apart as shown in
Figures 6A and 6B. This differential light
sensor does an analog comparison of two
different light levels.
Figure 6A.
When both photocells face a light
source equally, their center voltage is half
of the battery voltage, but the voltage will
move toward zero or full battery voltage as
the light moves to favor one of the
70 SERVO 11.2015