Subsection 11.6.6 The Photointerrupter, and Its Pull-Up
The sensor. The phototransistor inside the part can only pull the output down to ground when it conducts; when it stops conducting it lets go of the line entirely, and only the pull-up resistor brings the voltage back up, which is why the resistor’s rail is what sets the HIGH level (Figure 11.5.6). The part in the kit is an Omron EE-SX672, and the EE-SX67 series datasheet, under Ratings and Specifications, gives that behavior its name: the control output is an “NPN open collector”. The same table gives the supply voltage as 5 to 24 V DC, which is why the sensor’s supply and its HIGH level have to be two different rails, and the response frequency as 1 kHz minimum. At the ramp’s fastest, 20 slots at 180 rpm is 60 pulses a second, comfortably under that, so the sensor never limits the measurement. The fourth wire on the cabled version is the part’s L terminal, which selects whether the output switches on light (light-ON) or on dark (dark-ON). Leave it unconnected, and keep it clear of anything else on the board: an unconnected L wire picks up noise.
The pull-up value. Choosing it is a trade-off rather than a calculation. A much smaller resistor wastes current and makes the transistor work harder to pull the line down, because every moment the line is LOW that resistor carries 3.3 V divided by its own resistance straight to ground: at 10 kΩ that is 0.33 mA, and at 1 kΩ it would be ten times that. A much larger one takes too long to bring the line back up against the stray capacitance of the wiring, and picks up more noise while it is doing it. Between those two ends is a wide middle where nothing goes wrong, and 10 kΩ is comfortably inside it, which is why 10 kΩ is a common default. The rail is not a trade-off: whatever the resistor is tied to is the voltage the wire presents to the pin, so it is 3.3 V. In Lab 6 you can keep the external resistor or leave it out and enable the pin’s own internal pull-up with
PUPDR, the way you did for the button. That one is about 40 kΩ, four times the external resistor. The external one is what Day 12 uses, because there is a scope probe on that node; Figure 11.5.19 draws the finished build with the internal one instead, once that probe is gone.
