prototype, so expect
imperfections. The ‘belt’
should be a little wider
than a soup can and
long enough to hold six
cans (which is the
number I had in my
pantry), while the ‘base’
should be just slightly
wider than the belt so
you can slide the cans
past the QRD1114 as
shown in the pictures.
The IR detector should
almost touch the soup
cans as they pass by to
get a good reflection.
■ FIGURE 9. IR object
Tomato Soup Can Counter Software
You have no way to predict the ADC values for the
IR returned from a particular object other than it will be
between 0 and 1,023. I did preliminary tests using the
ReadPot TAW source code in the Arduino IDE (from
Smiley’s Workshop 12) and substituting the detector for
the potentiometer. The data shown in Figure 11 varied
from a low of 145 to a high of 799 for my finger (your
finger will probably be different).
When I set up the soup can conveyer and slowly
moved a can past the sensor while observing the results
from the ReadPot TAW software on the Arduino Serial
Monitor (slow since the code is only measuring once per
second), I saw a range of values above (>600) which I
could be certain that a can is present and another range
below which I could be sure there was no can present
(<300). There is also a sloppy mid range where I couldn’t
be sure (301 to 599). Remember your values won’t be the
same as mine. You must make your own measurements to
determine the certain ranges: YES_CAN and NO_CAN,
then use a true/false variable ‘yes’ to decide if a can
has passed the sensor. There really are many ways to do
this kind of thing, but I selected the easy (for me) to
understand logic of:
If the analogInput is greater than YES_CAN and
yes is equal to 0,
then set yes to 1.
Else if analogInput
is less than
yes is equal to 1,
then set yes
equal to 0 and
■ FIGURE 11. ADC readings
of finger movements.
this for a moment
SMILEY’S WORKSHOP ☺
■ FIGURE 8. IR object detector layout.
from the perspective of a can moving by the sensor.
Before the can gets there, ‘yes’ is equal to 0 for false and
the analogInput value is less than the YES_CAN constant
we have predetermined that indicates a can is present.
As the can moves into view of the sensor, at some point
analogValue becomes greater than YES_CAN so we know
there is a can and we set ‘yes’ equal to 1 for true (yup,
there is definitely a can present). Then, we keep measuring
as the can slides past and the analogInput drops to a value
less than NO_CAN. We check and see that ‘yes’ is true, so
there was a can, but now our analogInput reading says
there is no can, so it must have passed by. We set ‘yes’ to
0 and increment the can count. Whew! This will probably
■ FIGURE 10.
Tomato soup can
October 2009 21