Post comments on this article and find any associated files and/or downloads at
resistance so that INA[x] is solidly 1 or 0 as needed.
Figure 2 shows the schematic for this approach using a
photocell as the sensor, and Figure 3 shows the
corresponding breadboard setup for your Amigo.
If you have a photocell and potentiometer handy,
install the circuit in Figure 3 on your breadboard, then
load and run the code shown next in your Amigo. You
should see the value of INA[ 8] (either 1 or 0) displayed in
the center of the screen, and be able to adjust the
threshold between 1 and 0 for various light levels using
the potentiometer. The 10K potentiometer worked fine
with my photocell, but you may need to try a different
value to get things to work smoothly.
10 CLS 20 PRINT ““““Connect Threshold Detect circuit to ““““I/O Pin 8” 30 LOCATE 20,18 40 PRINT “INA = “; INA 50 GOTO 30
FIGURE 2: Using INA[x] to detect a specific threshold in the resistance of a sensor. Adjusting the pot changes the detect threshold.
This threshold detect circuit utilizing INA[x] can be
used with a wide range of resistive sensors, including
many you can build yourself. (If you’re not a big fan of
Forrest Mims, you should be. A quick Internet search of
“Forrest Mims sensors” will net you a goldmine of
potential Amigo sensor projects.) The threshold detect
circuit is still limited to “on or off” conditions, however —
either a sensor has tripped some preset threshold or it
hasn’t. Suppose we want Color BASIC to report the
resistance of the photocell at varying light levels?
Since Color BASIC doesn’t have a
native ADC (analog-to-digital converter)
command, it cannot directly convert the
voltage across a sensor resistance to a
number in your program. So, how do we
get this important capability?
Enter the time-honored RC decay
algorithm. From basic physics, we know
that the charge on a capacitor will
discharge through a resistance at a
predictable rate. Said differently, the time
for the voltage across the capacitor to
decay from its initial value to any lower
reference level will vary precisely with the
value of the shunting resistor. If we can
somehow measure that decay time in Color
BASIC, we’ll have a number we can use in
our programs to represent resistance.
Figures 4 and 5 help to explain this.
FIGURE 3: The light level detect circuit on the Amigo breadboard.
Figure 4 shows the basic RC decay circuit
in the charging configuration, with the
switch connecting voltage source V0 across
the parallel combination of capacitor C and
resistance R. In this configuration, the
42 January 2018