device works with no problems at 3. 3 volts. I was prepared
to install a level-shifting circuit between the pinger control
pin and the MCU using a single-transistor circuit (which
has appeared several times in the pages of Nuts & Volts),
but it seemed to be unnecessary in this case.
I have included a description of a suitable level-shifter
with the information package at the article link if you
should choose to go that way.
The firmware for the garage sentinel project was
written entirely in the Propeller Spin language, and is very
basic and easy to understand. The program begins by
initializing the I/O pins and retrieving the near and far
limits of the comfort zone (program variables nearmark
and farmark), which have been stored in EEPROM during
the calibration process.
Next, it enters an endless loop which repeats every
250 milliseconds, where the first order of business is to
check the state of the calibration pushbutton.
If the button is depressed (logic low), a calibration
routine (called “method” in the Spin language) is entered.
If not, the program sets the MCU pinger control pin as an
output and pulses it high for 50 microseconds.
Next, it sets the pin as an input and monitors the
duration of the return signal. The duration is converted
from system clock counts to distance in centimeters and is
stored in the program variable distance.
A series of comparisons follow:
• If distance is greater than 260 cm, both LEDs are
• If distance is less than 260 cm, the car is
approaching the comfort zone and the amber LED
is turned on.
• If distance is less than the maximum zone boundary
(farmark), the car is within the comfort zone and the
red LED only is turned on.
• If distance is less than the minimum zone boundary
(nearmark), it’s beyond the comfort zone and the
red LED flashes at a rate of twice per second.
The loop then repeats from the beginning.
In this mode, the user gets to set the distances
marking the near and far limits of the comfort zone for
parking the vehicle. These distances are stored in program
variables nearmark and farmark, respectively, and also in
EEPROM so they can be retrieved every time power is
applied to the system. As mentioned in the firmware
description, the firmware periodically checks the state of
August 2015 37
■ FIGURE 3. Electrical schematic. All components shown here (except for the pinger and optical sensor) are
through-hole devices and are mounted in the prototyping area of the Propeller USB project board.