LoginSignup
11
15

Raspberry Piを使って来客通知システムをつくる

Last updated at Posted at 2020-09-15

概要

  • 戸建て住宅用のインターホンとして、来客の通知をメールで送信する製品がある
  • 賃貸住宅では備え付けの機器しか使用できず、改造もできない
  • インターホンの呼び出しに応じて、カメラ画像を撮影し、メール送信するシステムをつくる

電源部とバスドラムの回路をつくり、スイッチでテストしている様子
スクリーンショット 2021-03-23 8.24.46.png

他のパートも交えRaspberry Piと接続している様子
19667890_1494514477271382_4849948105847660650_o.jpg

シーケンサーを開発している様子
19488955_1494515827271247_4695634475758483470_o.jpg

用意するもの

  • Raspberry Pi3 Model B (4でもおそらく大丈夫)
  • Raspberry Pi用のケース
  • Raspberry Pi用のヒートシンク
  • Raspberry Pi3 Model B B+ 対応 電源セット(5V 3.0A)
  • GY-30 デジタル光強度センサモジュールI2C
  • サインスマート Raspberry Pi 用 カメラモジュール Camera Module for ラズベリーパイ
  • ジャンパーワイヤー メス-メス
  • 熱収縮チューブ
  • 本立て(100円ショップ)

環境構築

組み立て

Raspberry Piと光センサー(GY-30)、カメラを以下のように接続する
スクリーンショット 2020-09-15 9.39.49.png
※Raspberry Piのピン配置は割愛します。

  • インターホンの画面に光センサーを設置する(呼び出しで画面が明るくなることを利用)
    68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f3730313434352f66383534626535652d343636642d666563352d343961372d6666646461303863656434362e6a706567.jpg
    49472120_2154225237966966_3920311238571065344_o.jpg

プログラミング

  • Pythonでwhile文でloopさせ、光センサーからの値が200Lux以上になったら、
    カメラで撮影し、jpg形式で保存する(撮影のたびに上書き)
  • 撮影した年月日をテキストファイルに一時的に書き込む(上書き) body.txt
  • muttとGmailを使って、撮影した年月日を本文に入れたメール送信を行う guest.sh
  • 5分間のスリープ時間を設ける(オートロックで呼び出し後、部屋のインターホンで再度呼び出されることの考慮)
  • Raspberry Pi起動時に、自動的に guest.py が起動するようにする

メインプログラム

/home/pi/guest/guest.py
import smbus

import picamera

import time

import subprocess

bus = smbus.SMBus(1)

addr = 0x23

camera = picamera.PiCamera()

while True:

    luxRead = bus.read_i2c_block_data(addr,0x11)

    print("Lux: "+str(luxRead[1]* 10))

    if int(luxRead[1]* 10) > 200:

        camera.capture('/home/pi/guest/image.jpg')

        res = subprocess.call("sh /home/pi/guest/guest.sh",shell=True)

        time.sleep(300)

    time.sleep(1)

メール送信用のシェルスクリプト

/home/pi/guest/guest.sh
sudo date > /home/pi/guest/body.txt
sudo mutt -s "guest arrived!" xxxxxx@gmail.com -a /home/pi/guest/image
.jpg < /home/pi/guest/body.txt

自動起動の設定

/etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

sudo python3 /home/pi/guest/guest.py &

exit 0

注意点

  • 検出する光の強さ(Lux)はインターホンによって違うので調整する
    タッチパネルで画面が明るくなるタイプでは、その機能で確かめる
  • スリープ時間は、オートロックのエントランスから部屋の距離で調整する
    68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f3730313434352f39376461346635302d633061352d316236312d353862392d6163643462383432623864612e6a706567.jpg
    68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f3730313434352f38626430643066382d383530662d663932372d663633392d3563633439666666313063352e6a706567.jpg

使ってみて

  • ネット通販を多用しているので不在時に来客があった際の通知は便利
  • 1年半以上使っているが安定動作している
11
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
15