Pololu 3pi Robot User Manual

Page 18

Advertising
background image

The sensing element of the reflectance sensor is the phototransistor shown in the left half of U4, which is connected in
series with capacitor C21. A separate connection leads through resistor R12 to pin PC0. This circuit takes advantage
of the fact the digital inputs of the AVR can be reconfigured as digital outputs on the fly. A digital output presents a
voltage of 5 V or 0 V, depending on whether it is set to a 1 or a 0 by your program. The way it works is that the pin
is set to an output and driven high (5 V) to charge the output node. The pin is then set to an input, and the voltage
falls as current flows through the phototransistor. Here is an oscilloscope trace showing the voltage on the capacitor
(yellow) dropping as current flows through the phototransistor, and the resulting digital input value of pin PC0 (blue):

The rate of current flow through the phototransistor depends on the light level, so that when the robot is over a bright
white surface, the value returns to 0 much more quickly than when it is over a black surface. The trace shown above
was taken when the sensor was on the edge between a black surface and a white one – this is what it looks like on
pure white:

The length of time that the digital input stays at 1 is very short when over white, and very long when over black. The
function

read_line_sensors()

in the Pololu AVR Library switches the port as described above and returns the time

for each of the five sensors. Here is a simplified version of the code that reads the sensors:

Pololu 3pi Robot User's Guide

© 2001–2014 Pololu Corporation

5. How Your 3pi Works

Page 18 of 63

Advertising