For an anniversary gift I ordered and received the following framed map from my wife.
It is an aviation map of western Pennsylvania with a multicolor LED placed at each airport location that issues METARs (METeorological Terminal Aviation routine weather Report). The color of each LED indicates the ceiling and visibility.
VFR (>3000ft ceilings and >5nm visibility) = Green
MFR (1000-3000ft ceilings and 3-5nm visibility) = Blue
IFR (500-1000ft ceilings and 1-3nm visibility) = Red
LIFR (<500ft ceilings or <1nm visibility) = Purple
Smoke = Gray
METAR older than 6 hours = Blank
METAR data are processed by a Raspberry Pi, a low-cost single-board computer, which is fastened behind the map. Data are received via a WiFi connection every five minutes. The brightness of the LEDs also changes for day/night conditions.
For several years, I have had a Hanna Products Mail Chime installed on my outdoor mailbox with an indoor receiver. The transmitter is attached to the door of the mailbox. When the door is opened a gravity switch is closed and a signal is sent to the receiver. The receiver sounds an alert and illuminates an LED lamp. The lamp is reset by a momentary contact push-to-close button switch.
I took a receiver apart to see if I could make a simple hack to have a Raspberry Pi sense when the LED lamp was on and then send an email to one of my accounts to indicated the mailbox door had been opened. Another function is to send a signal to a relay module to reset the LED lamp to off.
The project requires some programming skills with Linux and Python, a basic understanding of some electronic components, and some soldering is required. I had my project operating in three short evenings.
Hanna Products, Inc. Mail Chime – Amazon $55 Raspberry Pi Model B – Amazon $56 2 1K ohm resisters – Amazon, pack of 100, $6 1 DaFuRui 8Pcs DC 5V 1 Channel Relay Module – Amazon, pack of 8, $13 1 MCP3008 Microchip – Amazon, Pack of 4, $12.50 1 breadboard – Amazon, ELEGOO 3pcs MB-102, $9 Jumper wires – Amazon, Elegoo EL-CP-004, $7
Optional: Raspberry Pi breakout board and ribbon cable A case for the Raspberry Pi.
Tools: Soldering iron and solder Phillips head screwdriver Small flathead screwdriver wire stripper
The following is the schematic for the project.
Note the half-moon indentation at one end of the MCP3008 microchip. This will orient the chip to access the correct pins.
Begin by opening the bottom of the mail chime. One phillips screw holds the bottom panel to the housing. The printed circuit board is not fastened to the housing. Then solder 4 jumper wires to the printed circuit board inside of the disassembled mail chime as shown.
Then plugin the MCP3008 Microchip, and the 2 1K ohm resistors to the breadboard. Then connect the various jumper wires on the breadboard, and from the breadboard to the Raspberry Pi, the relay module and the mail chime. Use the schematic and photograph as guidance. I used a Raspberry Pi breakout board to easily identify the Raspberry Pi connections.
The resistors act as a voltage splitter to decrease the voltage going to the MCP3008 CH0 pin.
Use the small flathead screwdriver to connect the jumper wires to the relay module.
Python scripts are placed in the following directory on the Raspberry Pi:
Note that the indented lines in the following Python scripts are indented with tabs, not spaces.
import spidev, time
#Open SPI bus
spi = spidev.SpiDev()
#Function to read SPI data from MCP3008 chip
#Channel must be an integer 0-7
adc = spi.xfer2([1, (8 + channel) << 4, 0])
data = ((adc&3) << 8) + adc
#Function to convert data to voltage level
#rounded to specified number of decimal places
volts = (data * 3.3) / float(1023)
volts = round(volts,places)
mySendMail = '/home/pi/projects/mailbox/mail.py'
myResetChime = '/home/pi/projects/mailbox/reset.py'
print ("Check mail was run.")
reading = ReadChannel(0)
voltage = ConvertVolts(reading,2)
print("Reading=%d\tVoltage=%.2f" % (reading, voltage))
#If voltage is greater than or equal to 0.75 V then send an e-#mail
if (voltage >= 0.75):
now = datetime.datetime.now()
print("Mailbox was opened at: ")
print("Mailbox Chime has been reset.")
GMAIL_USER = "firstname.lastname@example.org"
GMAIL_PASS = "password"
now = datetime.datetime.now()
text = 'Your mail box has been opened!!!\n\n'
text = text + 'Time: '+now.strftime("%H:%M:%S %Y-%m-%d")+'\n\n'
sent_from = GMAIL_USER
to = ['email@example.com']
subject = 'Mailbox Alert'
body = text
email_text = """\
""" % (sent_from, ", ".join(to), subject, body)
server = smtplib.SMTP('smtp.gmail.com', 587)
server.login(GMAIL_USER, GMAIL_PASS)server.sendmail(sent_from, to, email_text)
except Exception as e:
Crontab will run the read_volt.py Python script every 5 minutes. Any output to standard output and standard error will be written to the mailbox.log file for trouble shooting purposes. When the mail chime is triggered by the mailbox door sensor, there will be current to the mail chime LED, which is then detected by the MCP3008 microchip at CH0. This in turn triggers the code to send an email, then after 60 seconds, the relay is actuated to reset the mail chime.