overhead light off, the meter read over one megohm;
when the light was lit, the resistance dropped to less than
20K ohms. Plenty of range for switching a MOSFET!
I had no qualms about the Propeller MCU chip. From
other projects, I knew it had more than enough capability
for this job, since only four I/O pins are needed: two for
the LEDs; one for the ultrasonic sensor; and one for a
pushbutton switch used for calibrating distance (more on
that later). Processor speed is not an issue either for this
The Circuit Design
At this point, I felt I had enough of a handle on things
to go ahead with the actual circuit design. The system
block diagram in Figure 2 shows how the major
components work together. The system block labeled
“Power Control” contains a P-channel MOSFET whose
function is to switch power to the rest of the circuit under
control of the optical sensor. In other words, it acts as a
Circuit details are shown in the schematic in Figure 3.
The NPN transistor, Q1, is driven to cut off when the
sensor is dark; i.e., when its resistance is high. This allows
the gate of the MOSFET, Q2, to be pulled high, turning off
Q2 and thus cutting off power to the rest of the circuit.
The only current drain now is a few microamps due to
leakage through the MOSFET and the photoresistor.
Diode, D2, in the emitter of Q1 is there just to ensure that
Q1 cuts off completely — even if there may be a slight
leakage of light onto the sensor — as on a bright sunny
day with light streaming through the garage window.
Note that an NPN Darlington transistor — a BC517,
for example — could be used in place of the Q1/D2
combination since the Darlington inherently has a higher
base-to-emitter forward voltage drop (Vbe) than the
2N4401. I just used what I had available.
The LEDs get their power directly from the raw DC
input. As mentioned previously, each LED lamp uses
about 40 mA when it’s on and is controlled by a 2N4401
switching transistor. There is nothing critical about these
transistors, and almost any NPN capable of handling a
collector-to-emitter voltage (Vce) greater than the input
supply voltage will do.
Momentary normally open (NO) pushbutton switch,
S1, simply provides a user input signal for use during the
calibration procedure. This is explained in the Calibration
section of this article. Schottky diode, D1, is in the circuit
to prevent any disastrous consequences if the power
source is accidentally reversed.
The ultrasonic pinger is an easy-to-use non-contacting
distance sensor which operates on the same principle as
range-finding radar. Besides power and ground, it uses just
a single control pin driven by the microcontroller.
When the control pin receives a pulse from the MCU,
The width of the
signal from the control
pin is the same as the
echo time delay, and is
therefore a measure of
the distance to the
reflecting object. Parallax
specifies a supply voltage
of five volts for the pinger,
but I found that the
36 August 2015
■ FIGURE 1. Cadmium sulfide photoresistor and plastic
bottle ready to receive it.
■ FIGURE 2. System block diagram.