工業製造
産業用モノのインターネット | 工業材料 | 機器のメンテナンスと修理 | 産業プログラミング |
home  MfgRobots >> 工業製造 >  >> Manufacturing Technology >> 製造プロセス

Octopod:Smart IoT Home / Industry Automation Project

コンポーネントと消耗品

>
Arduino UNO
× 1
Arduino MKR WiFi 1010
これまたは他のWifi ESP8266 / ESP32これは私の国では利用できなかったので、NodeMCUを使用しましたESP8266
× 1
Maxim Integrated MAX32630FTHR
MAX32620FTHR、Arduino 1010、または任意のESP8266ボードから選択できます。このボードでは外部WiFiが必要です。 Interent用のモジュールまたはEsp8266チップ
× 1
Raspberry Pi Zero Wireless
通常のRaspi 2/3も使用できます!
× 1
DHT11温度および湿度センサー(4ピン)
× 1
Seed Grove-ガスセンサー(MQ2)
× 1
SparkFun土壌水分センサー(ネジ端子付き)
× 1
PIRモーションセンサー(汎用)
オプション
× 1
RFIDリーダー(汎用)
× 1
リレー(汎用)
2チャンネルが望ましい
× 1
RGB拡散コモンカソード
× 1
ラズベリーパイカメラモジュール
× 1
サーボ(Tower Pro MG996R)
× 1
ブザー
× 2
HC-05Bluetoothモジュール
オプション
× 1
LED(汎用)
× 4
ウォールアダプター/パワーバンク
× 2
メモリーカード
4 Gb以上、できればクラス10(Raspberry Pi OSに必要)
× 1

必要なツールとマシン

>
ホットグルーガン(汎用)
3Dプリンター(汎用)
オプション
ハンドツール
ラジオペンチ、はさみ、カッターなど

アプリとオンラインサービス

>
Blynk
OpenCV

このプロジェクトについて

そこには多くのIoT自動化プロジェクトがありますが、私を信じてください! Octopodは NodeMCU を使用して作成されます (MAX32620FTHRまたはArduino MKR 1010)、 Arduino Uno、 および Raspberry Pi 3 。 Octopodを使用すると、家をスマートにすることができます。 Octopodは、温度などのさまざまなデータを送信します 、湿度 および ガス品質 あなたの家/オフィス/業界の内部。 Octopodから通知が送信されます あらゆる種類の動きを検出したときはいつでも 内部にあり、植物に水をやる必要があるときに通知します 。 アプライアンスを管理することもできます ブリンクを介して スマートフォン上のアプリケーション。 Octopodは、真のムード照明も可能にします!

Octopodには小さなカメラが搭載されています 、ライブフィードを送信します 。このカメラも人工知能を使用しています 視界にいる人間を検出し、写真を送信します 。さらに、 RFID を備えています ドアロック システム !素晴らしいですよね?

すべてがどのように機能しますか?

NodeMCUは、一連のセンサー、リレーモジュール、およびRGBLEDに接続されています。 Wi-Fi経由でスマートフォンのBlynkアプリに接続され、すべてのデータが送信され、家を制御できるようになります。

Raspberry PiはWiFiにも接続されており、Piカメラを介してライブフィードを確認できます。また、PiにOpenCVライブラリをインストールし、視界にいる人間を検出して画像を電子メールで送信するようにPiを構成しました。

スマートドアユニットはRFIDモジュールを使用しています。許可されたRFIDがその範囲内に入ると、自動的にドアが開きます。

ステップ1:メインオクトポッドのコーディング

ほぼすべての行にコメントを追加したので、コピーするだけでなく、理解できます。ここでは、コードを簡単に実行すると実際に何が起こるかを説明します。

  • ライブラリを含む:

このコードは2つのメインライブラリを使用します。BlynkライブラリはコードをBlynkアプリケーションと互換性のあるものにし、もう1つのライブラリはDHT11温度ライブラリで、センサーからの生データを温度と湿度に変換します。これらのライブラリをダウンロードするには、コード内の指定されたリンクに移動してダウンロードします。次に、ArduinoIDEに向かいます スケッチ→ライブラリを含める→.zipライブラリを追加し、ダウンロードしたライブラリを選択します。

  #include  // Blynkライブラリを含める#include  // Blynkライブラリを含める#include  // DHTセンサーライブラリを含める#defineBLYNK_PRINT Serial > 

これは、nodemcuをインターネットに接続し、アプリに対して認証するのに役立つBlynkコードです。

  // Blynkアプリで認証トークンを取得する必要があります。//プロジェクト設定(ナットアイコン)に移動します。charauth[] ="認証キー"; // WiFi認証情報を設定します。//設定オープンネットワークの場合は「」へのパスワード。charssid[] ="Your WiFi SSID"; char pass [] ="Your WiFi Pass";  
  • ピンと整数の定義:

このセグメントでは、さまざまなセンサーのピンを定義します。あなたはあなたの納得に従ってそれらを変えることができます。また、コードの過程で使用する傾向のあるいくつかの整数を定義します。

  #define DHTPIN 2 //どのデジタルピン温度および湿度センサーが接続されているか#definesoilPin 4 //どのデジタルピン土壌水分センサーが接続されているか#definegasPin A0 //どのアナログピンガスセンサーが接続されているかto#define pirPin 12 //どのデジタルピン土壌水分センサーがintpirValueに接続されているか。 //読み取りPIRValueintsoilValueを保存する場所; //読み取りを保存する場所SoilMoisture Valueint PIRpinValue; // Blynk App Pin V0intSOILpinValueによって送信された値を保存する場所。 // Blynk App PinV1によって送信された値を保存する場所 
  • BLYNK_WRITE():

このコードを使用して、Blynkアプリに、ピンV0とピンV1を使用して、モーション検出と土壌水分テストがオンになっているかどうかをコードに通知できることを伝えます。

  BLYNK_WRITE(V0)// BlynkアプリのVOピンは、モーション検出がオンかどうかを示します{PIRpinValue =param.asInt(); } BLYNK_WRITE(V1)// BlynkアプリのV1ピンは、土壌水分がオンかどうかを示します{SOILpinValue =param.asInt(); }  
  • void sendSensor():

このコードは、DHT11からデータを取得して使用できるようにし、それをそれぞれピンV5とV6に送信します。

  void sendSensor(){int h =dht.readHumidity(); int t =dht.readTemperature(); //または華氏の場合はdht.readTemperature(true)if(isnan(h)|| isnan(t)){Serial.println( "DHTセンサーからの読み取りに失敗しました!"); //センサーがfalse値を送信していないかどうかを確認するにはreturn; } //いつでも任意の値を送信できます。 // 1秒あたり10を超える値を送信しないでください。 Blynk.virtualWrite(V5、h); //湿度をピンV5に送信しますBlynk.virtualWrite(V6、t); //温度をピンV7に送信}  
  • void getPirValue()&void getSoilValue():

センサーからデジタル値を読み取り、if-else条件を実行してセンサーの状態をチェックします。センサーが必要な状態の場合、Blynkアプリからの通知をプッシュします。

  void getPirValue(void){pirValue =digitalRead(pirPin); if(pirValue)// PIRのデジタルピンは人間の検出に高い値を与えます{Serial.println( "モーション検出"); Blynk.notify( "モーションが検出されました"); }} void getSoilValue(void){soilValue =digitalRead(soilPin); if(soilValue ==HIGH)//湿度が低い場合、土壌センサーのデジタルピンは低い値を示します{Serial.println( "Water Plants"); Blynk.notify( "水生植物"); }}  
  • void setup():

セットアップでは、1回だけ実行することを意図したいくつかのことを実行します。例:固定ボーレートでシリアル通信を開始し、このコードをBlynkアプリケーションに承認し、Dhtセンサーの読み取りを開始し、スマートホームプロジェクトがオンラインであることをTwitterハンドルにツイートし、ノードにPir Pin and SoilSensorを通知します。ピンは入力のみを取得するためのものです。

  void setup(){//デバッグコンソールSerial.begin(9600); Blynk.begin(auth、ssid、pass); //サーバーを指定することもできます://Blynk.begin(auth、ssid、pass、 "blynk-cloud.com"、8442); //Blynk.begin(auth、ssid、pass、IPAddress(192,168,1,100)、8442); dht.begin(); // DHTの読み取りを開始しますBlynk.tweet( "OCTOPOD IS ONLINE!"); //プロジェクトするTwitterハンドルを微調整するのはオンラインですpinMode(pirPin、INPUT); // Pirピンが入力のみを取ることを意図していることを定義するpinMode(soilPin、INPUT); //土壌センサーピンが入力のみを受け取ることを意図していることを定義する//毎秒呼び出される関数を設定するtimer.setInterval(1000L、sendSensor);}  
  • void loop():

ループでは、何度も繰り返されることを記述します。ここでは、セットアップの前に作成したコードが実行されることを確認します。次に、ピンV0とピンV1の状態をチェックし、それに応じてセンサーから値を取得する2つのIf-Elseステートメントを記述します。

  void loop(){Blynk.run(); timer.run(); if(PIRpinValue ==HIGH)// BlynkアプリのVOピンは、モーション検出がオンかどうかを通知します{getPirValue(); } if(SOILpinValue ==HIGH)// BlynkアプリのV1ピンは、土壌水分がオンかどうかを示します{getSoilValue(); }}  

ステップ2:RFIDスマートロックのコーディング

正直なところ、これはシンプルで簡単なコードであり、多くの説明は必要ありません。しかし、これが何をするのかを簡単に説明します。コードには2つのバージョンがあります。1つはドアユニットボックスをBluetoothに接続して、シリアル端末を介してドアが開いたときに通知する場合です。他の送信はシリアルに送信されるため、Arduinoをコンピューターに接続すると表示できます。私はBluetoothバージョンのないシンプルなものを好みます。さあ、行きましょう!

  • [スケッチ]→[ライブラリを含める]→[ライブラリの管理]→検索バーMFRC522に入力し、ライブラリをインストールします。次に、[ファイル]→[例]→[カスタムライブラリ]→[MFRC522]→[dumpInfoSketch]に移動します。最初に、ピンの接続方法を読むことができます(または写真を参照してください)。次に、コードを実行してシリアルモニターを開き、RFIDカードをMFRC522モジュールの前に1枚持ってきて、5秒間待ちます。次に、同様の方法でカードのUIDをメモし、他のカードとキーチェーンのUIDをメモします。
  • 次に、好きなコードをダウンロードします。コードを開き、この行に移動します。ここで、これらのXの代わりに、ドアを開くために使用するカードのUIDを追加します。これで準備が整いました。コードをアップロードするだけです。
  if(content.substring(1)=="XX XX XX XX"){}  

このコードでは、主に2つのことを行います。それは、コードのIf-Else部分です。カードのUIDが上記のUIDと一致する場合は、サーボを動かして(ドアが開くように)、LEDを点滅させ、ブザーを使用して音を鳴らすようにarduinoに伝えます。それ以外の場合、UIDがLEDを点滅させたり、ブザーを使用して音を鳴らしたりしない場合。

ステップ3:RaspberryPiの人間検出AIのセットアップ

このガイド付きステップでは、スマートセキュリティカメラの作成方法を学習します。カメラはオブジェクトを検出するたびにメールを送信します。同じWiFiネットワークを使用している場合は、Raspberry PiのIPアドレスを入力することで、カメラからライブ映像にアクセスできます。スマートカメラを一から作る方法を紹介します。行きましょう!

要件:

1。 OpenCV(オープンソースコンピュータービジョンライブラリ)

2。 ラズベリーパイ3B

3。 Raspberry Pi Camera V2

前提条件:

1。 RaspbianStretchがインストールされたRaspberryPi3。 Raspbian Stretch OSをまだお持ちでない場合は、RaspbianStretchの新機能を利用するためにOSをアップグレードする必要があります。

Raspberry Pi3をRaspbianStretchにアップグレードするには、ここからダウンロードして、これらのアップグレード手順(または、初心者に推奨されるNOOBSルートの場合はこれらの手順)に従ってください。

注:Raspberry Pi3をRaspbianJessieからRaspbianStretchにアップグレードする場合、問題が発生する可能性があります。自己責任で続行し、RaspberryPiフォーラムに相談してください。重要:RaspbianStretchの新規インストールを続行することをお勧めします。 RaspbianJessieからのアップグレードはお勧めしません。

2。 ターミナルを開いてコマンドを実行できるようにするためのRaspberryPi3への物理アクセスSSHまたはVNCを介したリモートアクセス。このチュートリアルの大部分はSSH経由で行いますが、ターミナルにアクセスできる限り、簡単にフォローできます。

  • ステップ1:カメラをラズベリーPI3に取り付ける

1。 Raspberry PiCameraモジュールを開きます。静電気によりカメラが破損する恐れがありますのでご注意ください。灰色の静電気防止バッグからカメラを取り出す前に、アースされた物体(ラジエーターやPCシャーシなど)に触れて放電したことを確認してください。

2。 ケーブルをRaspberryPiに挿入して、RaspberryPiカメラモジュールを取り付けます。ケーブルはイーサネットポートとHDMIポートの間にあるコネクタに挿入され、銀色のコネクタはHDMIポートに面しています。

3。 RaspberryPiを起動します。

4。 プロンプトから、「sudoraspi-config」を実行します。 「カメラ」オプションがリストされていない場合は、いくつかのコマンドを実行してRaspberryPiを更新する必要があります。 「sudoapt-getupdate」と「sudoapt-getupgrade」を実行します

5。 「sudoraspi-config」をもう一度実行します。「camera」オプションが表示されます。

コマンド-

  $ sudo raspi-config  

6。 「カメラ」オプションに移動し、それを有効にします(インターフェースオプションの監視)。 「完了」を選択してRaspberryPiを再起動するか、次のように入力します:

  $ sudo restart  
  • ステップ2:CVのインストールを開く

OpenCVを初めてインストールする場合、またはRasbianStretchを使い始めたばかりの場合。これはあなたにぴったりのチュートリアルです。

ステップ1:ファイルシステムを拡張する

Raspbian Stretchの新しいインストールを使用していますか?その場合、最初に行うべきことは、ファイルシステムを拡張して、microSDカードで使用可能なすべてのスペースを含めることです。

コマンド-

  $ sudo raspi-config  

次に、「詳細オプション」メニュー項目を選択し、続いて「ファイルシステムの拡張」を選択します。プロンプトが表示されたら、最初のオプション「A1。 「ファイルシステム」を展開し、キーボードのEnterキーを押し、「」ボタンまで下向き矢印を押してから、Piを再起動します。 8GBカードを使用している場合は、使用可能なスペースの50%近くを使用している可能性があるため、簡単な方法の1つは、LibreOfficeとWolframエンジンの両方を削除して、PIのスペースを解放することです。

コマンド-

  $ sudoapt-getパージwolfram-engine $ sudoapt-getパージlibreoffice * $ sudo apt-get clean $ sudoapt-get自動削除 

Wolfram EngineとLibreOfficeを削除した後、ほぼ1GBを回収できます!

ステップ2: 依存関係をインストールする

Raspberry PiにOpenCVをインストールする方法について説明したのはこれが初めてではないため、これらの手順を簡潔に説明し、インストールプロセスを実行できるようにします。時間も含まれています。各コマンドの実行に時間がかかるため(インターネットの速度によって異なる場合もあります)、それに応じてOpenCV + Raspberry Pi 3のインストールを計画できます(OpenCV自体のコンパイルには約4時間かかります。これについては、後で詳しく説明します)。最初のステップは、既存のパッケージを更新およびアップグレードすることです。

コマンド-

  $ sudo apt-get update &&sudo apt-get upgrade  

次に、OpenCVビルドプロセスの構成に役立つCMakeなどの開発者ツールをインストールする必要があります。RaspbianStretch:OpenCV 3 + PythonをRaspberryPiにインストールする

コマンド-

  $ sudo apt-get install build-essential cmake pkg-config  

次に、ディスクからさまざまな画像ファイル形式をロードできるようにするいくつかの画像I / Oパッケージをインストールする必要があります。このようなファイル形式の例には、JPEG、PNG、TIFFなどがあります。RaspbianStretch

コマンド-

  $ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev  

イメージI / Oパッケージが必要なのと同じように、ビデオI / Oパッケージも必要です。これらのライブラリを使用すると、ディスクからさまざまなビデオファイル形式を読み取ったり、ビデオストリームを直接操作したりできます

コマンド-

  $ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev $ sudo apt-get install libxvidcore-dev libx264-dev  

OpenCVライブラリには、画像を画面に表示し、基本的なGUIを構築するために使用されるhighguiという名前のサブモジュールが付属しています。 highguiモジュールをコンパイルするには、GTK開発ライブラリをインストールする必要があります。RaspbianStretch:OpenCV 3 + PythonをRaspberryPiにインストールします

コマンド-

  $ sudo apt-get install libgtk2.0-dev libgtk-3-dev  

OpenCV内の多くの操作(つまり、マトリックス操作)は、いくつかの追加の依存関係をインストールすることでさらに最適化できます。

コマンド-

  $ sudo apt-get install libatlas-base-dev gfortran  

これらの最適化ライブラリは、RaspberryPiなどのリソースに制約のあるデバイスにとって特に重要です。最後に、Python2.7とPython3の両方のヘッダーファイルをインストールして、Pythonバインディングを使用してOpenCVをコンパイルできるようにします:Raspbian Stretch

コマンド-

  $ sudo apt-get install python2.7-dev python3-dev  

OSの新規インストールを使用している場合は、これらのバージョンのPythonがすでに最新バージョンになっている可能性があります(これを示すターミナルメッセージが表示されます)。この手順をスキップすると、makeを実行してOpenCVをコンパイルするときにPython.hヘッダーファイルが見つからないことに関連するエラーが発生する場合があります。ステップ3:OpenCVソースコードをダウンロードする

ステップ3:OpenCVをダウンロードする ソースコード

依存関係がインストールされたので、公式のOpenCVリポジトリからOpenCVの3.3.0アーカイブを取得しましょう。このバージョンには、OpenCVでディープラーニングを行った以前の投稿で説明したdnnモジュールが含まれています(注:openCVの将来のバージョンがリリースされると、3.3.0を最新のバージョン番号に置き換えることができます):

コマンド-

  $ cd〜 $ wget -O opencv.zip   https://github.com/Itseez/opencv/archive/3.3.0.zi ...>> p $ unzip opencv.zip 

OpenCV 3のフルインストール(たとえば、SIFTやSURFなどの機能にアクセスできるようにするため)が必要になるため、opencv_contribリポジトリも取得する必要があります。RaspbianStretch:OpenCV 3 + PythonをRaspberryPiにインストールします。

コマンド-

  $ wget -O opencv_contrib.zip   https://github.com/Itseez/opencv_contrib/archive / ...>> 3.3.0 $ unzip opencv_contrib.zip  

コピーアンドペースト中に「<=>」ボタンを使用して上記のコマンドを展開する必要がある場合があります。一部のブラウザでは、3.3.0.zipの.zipが途切れているように見える場合があります。 OpenCV 3.3.0アーカイブの完全なURLは次のとおりです。https://github.com/Itseez/opencv_contrib/archive / ...注:opencvとopencv_contribのバージョンが同じであることを確認してください(この場合は3.3.0) 。バージョン番号が一致しない場合は、コンパイル時または実行時のエラーが発生する可能性があります。ステップ4:Python2.7またはPython3? Raspberry Pi 3でOpenCVのコンパイルを開始する前に、まずPythonパッケージマネージャーであるpipをインストールする必要があります

コマンド-

  $ wget    https://bootstrap.pypa.io/get-pip.py> >> > $ sudo python get-pip.py $ sudo python3 get-pip.py  

これらのコマンドを発行すると、pipがすでに最新であるというメッセージが表示される場合がありますが、この手順をスキップしないことをお勧めします。長年のPyImageSearchリーダーであれば、私がvirtualenvとvirtualenvwrapperの両方の大ファンであることをご存知でしょう。

これらのパッケージのインストールは必須ではなく、OpenCVをインストールしなくても絶対にインストールできますが、他の既存のPyImageSearchチュートリアル(および将来のチュートリアル)もPython仮想環境を活用するため、これらをインストールすることを強くお勧めします。

また、このガイドの残りの部分では、virtualenvとvirtualenvwrapperの両方がインストールされていることを前提としています。それでは、virtualenvとvirtualenvwrapperを使用する意味は何ですか?まず、仮想環境は、プロジェクトごとに分離された独立したPython環境を作成することにより、さまざまなプロジェクトに必要な依存関係を別々の場所に保持するために使用される特別なツールであることを理解することが重要です。つまり、「プロジェクトXはバージョン1.xに依存しますが、プロジェクトYには4.xが必要です」というジレンマを解決します。

また、グローバルサイトパッケージを整理整頓し、雑然としないようにします。 Python仮想環境が優れた方法である理由の完全な説明が必要な場合は、RealPythonに関するこの優れたブログ投稿を絶対に読んでください。 Pythonコミュニティでは、ある種の仮想環境を使用するのが標準的な方法であるため、同じことを行うことを強くお勧めします。

コマンド-

  $ sudo pip install virtualenv virtualenvwrapper $ sudo rm -rf〜 / .cache / pip  

virtualenvとvirtualenvwrapperの両方がインストールされたので、〜/ .profileファイルを更新する必要があります。ファイルの下部に次の行を含めます。RaspbianStretch

コマンド-

  $ nano〜 / .profile  

次の行をコピーしてファイルの下部に貼り付けます。

コマンド-

   virtualenvおよびvirtualenvwrapperWORKON_HOME =$ HOME / .virtualenvs source /usr/local/bin/virtualenvwrapper.sh  

または

〜/ .profileの更新を処理するには、単にcatと出力リダイレクトを使用する必要があります:

コマンド-

  $ echo -e "\ n#virtualenv and virtualenvwrapper">>〜/ .profile $ echo "exportWORKON_HOME =$ HOME / .virtualenvs">>〜/ .profile $ echo "source / usr / local / bin / virtualenvwrapper.sh ">>〜/ .profile  

〜/ .profileが更新されたので、変更が有効になるように再ロードする必要があります。 〜/ .profileファイルを強制的にリロードするには、ログアウトしてから再度ログインします。

ターミナルインスタンスを閉じて新しいインスタンスを開く

または私の個人的なお気に入り

コマンド-

  $ source〜 / .profile  

:システム変数が正しく設定されていることを確認するために、新しいターミナルを開くたびにソース〜/ .profileファイルを実行することをお勧めします。 Python仮想環境の作成次に、コンピュータービジョン開発に使用するPython仮想環境を作成しましょう。

コマンド-

  $ mkvirtualenv cv -p python2  

このコマンドは、Python2.7を使用してcvという名前の新しいPython仮想環境を作成します。

代わりにPython3を使用する場合は、代わりに次のコマンドを使用することをお勧めします。

コマンド-

  $ mkvirtualenv cv -p python3 

繰り返しになりますが、この点を十分に強調することはできません。cvPython仮想環境は完全に独立しており、RaspbianStretchのダウンロードに含まれているデフォルトのPythonバージョンから隔離されています。

グローバルsite-packagesディレクトリ内のPythonパッケージは、cv仮想環境では使用できません。同様に、cvのsite-packagesにインストールされているPythonパッケージは、Pythonのグローバルインストールでは使用できません。

Python仮想環境で作業しているときは、このことを覚えておいてください。これは、多くの混乱や頭痛の種を避けるのに役立ちます。 「cv」仮想環境にいるかどうかを確認する方法RaspberryPiを再起動したことがある場合。ログアウトして再度ログインします。または、新しいターミナルを開く場合は、workonコマンドを使用してcv仮想環境に再度アクセスする必要があります。

以前のブログ投稿では、読者がmkvirtualenvコマンドを使用しているのを見てきました—これは完全に不要です! mkvirtualenvコマンドは、実際に仮想環境を作成するために1回だけ実行することを目的としています。その後、workonを使用して、仮想環境にドロップダウンできます:

コマンド-

  $ source〜 / .profile $ workon cv  

cv仮想環境にいることを検証および確認するには、コマンドラインを調べます。プロンプトの前にテキスト(cv)が表示されている場合は、cv仮想環境にいます。「(cv)」テキストが表示されていることを確認してください。プロンプト。cv仮想環境にいることを示します。

それ以外の場合、(cv)テキストが表示されない場合は、cv仮想環境にいません:

プロンプトに「(cv)」というテキストが表示されない場合は、cv仮想環境にいないため、この問題を解決するには「source」と「workon」を実行する必要があります。これを修正するには、上記のsourceコマンドとworkonコマンドを実行するだけです。 Raspberry PiへのNumPyのインストールこれまでに完了したと仮定すると、これでcv仮想環境になっているはずです(このチュートリアルの残りの部分ではこの環境にとどまる必要があります)。

ステップ4:RaspberryPiにNumPyをインストールする

Pythonの唯一の依存関係は、数値処理に使用されるPythonパッケージであるNumPyです。

コマンド-

  $ pip install numpy  

NumPyのインストールには少し時間がかかる場合があります。

ステップ5:OpenCVをコンパイルしてインストールする

コマンド-

  $ workon cv  

cv仮想環境にいることを確認したら、CMakeを使用してビルドをセットアップできます:

コマンド-

  $ cd〜 / opencv-3.3.0 / $ mkdir build $ cd build $ cmake -D CMAKE_BUILD_TYPE =RELEASE \ -D CMAKE_INSTALL_PREFIX =/ usr / local \ -D INSTALL_PYTHON_EXAMPLES =ON \ -D OPENCV_EXTRA_MODULES_PATH =〜 /opencv_contrib-3.3.0/modules \ -D BUILD_EXAMPLES =ON ..  

ここで、実際のコンパイル手順に進む前に、CMakeの出力を確認してください。 Python2およびPython3というタイトルのセクションを下にスクロールすることから始めます。 Python2.7用にOpenCV3をコンパイルする場合は、Python 2セクションにインタープリター、ライブラリ、numpy、パッケージへの有効なパスが含まれていることを確認してください

Raspberry Pi3でRaspbianStretch用にOpenCV3をコンパイルするときにPython3が使用されることを確認します。インタープリターがcv仮想環境にあるpython2.7バイナリをどのように指しているかに注目してください。 numpy変数は、cv環境でのNumPyのインストールも指します。

繰り返しになりますが、Interpreterはcv仮想環境にあるpython3.5バイナリを指し、numpyはNumPyインストールを指します。

いずれの場合も、これらの変数パスにcv仮想環境が表示されない場合は、CMakeを実行する前にcv仮想環境にいないことがほぼ確実です。この場合は、workon cvを使用してcv仮想環境にアクセスし、上記のcmakeコマンドを再実行してください。

コンパイルする前にスワップスペースのサイズを設定するコンパイルプロセスを開始する前に、スワップスペースのサイズを増やす必要があります。 This enables OpenCV to compile with all four cores of the Raspberry PI without the compile hanging due to memory problems.

Open your /etc/dphys-swapfile and then edit the CONF_SWAPSIZE variable

COMMAND-

$ nano /etc/dphys-swapfile  

and then edit the following section of the file:#set size to absolute value, leaving empty (default) then uses computed value # you most likely don't want this, unless you have an special disk situation

# CONF_SWAPSIZE=100 CONF_SWAPSIZE =1024 

Notice that I’ve commented out the 100MB line and added a 1024MB line. This is the secret to getting compiling with multiple cores on the Raspbian Stretch. If you skip this step, OpenCV might not compile.

To activate the new swap space, restart the swap service:

COMMAND-

$ sudo /etc/init.d/dphys-swapfile stop $ sudo /etc/init.d/dphys-swapfile start  

Note:It is possible to burn out the Raspberry Pi microSD card because flash memory has a limited number of writes until the card won’t work. It is highly recommended that you change this setting back to the default when you are done compiling and testing the install (see below). To read more about swap sizes corrupting memory, see this page. Finally, we are now ready to compile OpenCV:

COMMAND-

$ make -j4 

The -j4 switch stands for the number of cores to use when compiling OpenCV. Since we are using a Raspberry Pi 2, we’ll leverage all four cores of the processor for a faster compilation.

However, if your make command errors out, I would suggest starting the compilation over again and only using one core

$ make clean$ make  

Once OpenCV 3 has finished compiling.Our OpenCV 3 compile on Raspbian Stretch has completed successfully.

From there, all you need to do is install OpenCV 3 on your Raspberry Pi 3:

COMMAND-

$ sudo make install$ sudo ldconfig  

Step #6 :Finish installing OpenCV on your Pi

We’re almost done — just a few more steps to go and you’ll be ready to use your Raspberry Pi 3 with OpenCV 3 on Raspbian Stretch.

For Python 2.7:

#5 Provided your Step without error, OpenCV should now be installed in/usr/local/lib/python2.7/site-pacakges . You can verify this using the ls command:

COMMAND-

$ ls -l /usr/local/lib/python2.7/site-packages/ total 1852 -rw-r--r-- 1 root staff 1895772 Mar 20 20:00 cv2.so  

Note:In some cases, OpenCV can be installed in /usr/local/lib/python2.7/dist-packages(note the dist-packages rather than site-packages ). If you do not find the cv2.so bindings insite-packages , we be sure to check dist-packages . Our final step is to sym-link the OpenCV bindings into our cv virtual environment for Python 2.7:

COMMAND-

$ cd ~/.virtualenvs/cv/lib/python2.7/site-packages/ $ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so  

For Python 3:After running make install , your OpenCV + Python bindings should be installed in/usr/local/lib/python3.5/site-packages . Again, you can verify this with the ls command:

COMMAND-

$ ls -l /usr/local/lib/python3.5/site-packages/ total 1852 -rw-r--r-- 1 root staff 1895932 Mar 20 21:51 cv2.cpython-34m.so  

I honestly don’t know why, perhaps it’s a bug in the CMake script, but when compiling OpenCV 3 bindings for Python 3+, the output .so file is named cv2.cpython-35m-arm-linux-gnueabihf.so(or some variant of) rather than simply cv2.so (like in the Python 2.7 bindings). Again, I’m not sure exactly why this happens, but it’s an easy fix. All we need to do is rename the file:

COMMAND-

$ cd /usr/local/lib/python3.5/site-packages/ $ sudo mv cv2.cpython-35m-arm-linux-gnueabihf.so cv2.so  

After renaming to cv2.so , we can sym-link our OpenCV bindings into the cv virtual environment

for Python 3.5:

COMMAND-

$ cd ~/.virtualenvs/cv/lib/python3.5/site-packages/ $ ln -s /usr/local/lib/python3.5/site-packages/cv2.so cv2.so  

Step #7:Testing your OpenCV 3 install

Congratulations, you now have OpenCV 3 installed on your Raspberry Pi 3 running Raspbian Stretch! But before we pop the champagne and get drunk on our victory, let’s first verify that your OpenCV installation is working properly.

Open up a new terminal, execute the source and workon commands, and then finally attempt to import the Python + OpenCV bindings:

COMMAND-

$ source ~/.profile$ workon cv $ python>>> import cv2>>> cv2.__version__ '3.3.0'>>>  

OpenCV 3 has been successfully installed on my Raspberry Pi 3 + Python 3.5 environment . Once OpenCV has been installed, you can remove both the opencv-3.3.0 and opencv_contrib-3.3.0 directories to free up a bunch of space on your disk:

COMMAND-

$ rm -rf opencv-3.3.0 opencv_contrib-3.3.0  

However, be cautious with this command! Make sure OpenCV has been properly installed on your system before blowing away these directories. A mistake here could cost you hours in compile time.

Open your /etc/dphys-swapfile and then edit the CONF_SWAPSIZE variable COMMAND-

# set size to absolute value, leaving empty (default) then uses computed value# you most likely don't want this, unless you have an special disk situation CONF_SWAPSIZE=100 #CONF_SWAPSIZE=1024 

Notice that I’ve commented out the 1024MB line and uncommented the 100MB line. As stated above, larger swap spaces may lead to memory corruption, so I recommend setting it back to 100MB. If you skip this step, your memory card won’t last as long. To revert to the smaller swap space, restart the swap service

COMMAND-

$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start
  • STEP 4:Setting Up Python Program

You can verify that the camera works by running.

COMMAND-

$ raspistill -o image.jpg 

which will save a image from the camera in your current directory.

After you checked the camera is working. Now download all the python files and models from below link :

LINK:

https://drive.google.com/file/d/0B98uoD6BbkpqZU9FT...

You can open up the file inspector and view the image.

Make sure you are using the virtual environment by typing the following commands:

COMMANDS-

$ source ~/.profile $ workon cv  

Next, navigate to the repository directory,

COMMANDS-

$ cd Smart-Security-Camera  

and install the dependencies for the project

COMMANDS-

$ pip install -r requirements.txt  

To get emails when objects are detected, you'll need to make a couple modifications to the mail.py file. Open mail.py with vim vim mail.py , then press i to edit. Scroll down to the following section

# Email you want to send the update from (only works with gmail)fromEmail ='[email protected]' fromEmailPassword ='password1234' # Email you want to send the update to toEmail ='[email protected]'  

and replace with your own email/credentials.

The mail.py file logs into a gmail SMTP server and sends an email with an image of the object detected by the security camera. Press esc then ZZ to save and exit.

You can also modify the main.py file to change some other properties.

email_update_interval =600 # sends an email only once in this time intervalvideo_camera =VideoCamera(flip=True) # creates a camera object, flip verticallyobject_classifier =cv2.CascadeClassifier("models/fullbody_recognition_model.xml") # an opencv classifier facial_recognition_model.xml fullbody_recognition_model.xml upperbody_recognition_model.xml 

Run the program python main.py

You can view a live stream by visiting the IP address of your pi in a browser on the same network. You can find the IP address of your Raspberry Pi by typing ifconfig in the terminal and looking for the inet address. Visit :5000 in your browser to view the stream.

Note:

To view the live stream on a different network than your Raspberry Pi, you can use ngrok to expose a local tunnel. Once downloaded, run ngrok with ./ngrok http 5000 and visit one of the generated links in your browser. Note:The video stream will not start automatically on startup. To start the video stream automatically, you will need to run the program from your /etc/rc.local file see this video for more information about how to configure that. Receiving Emails When receiving an email for the first time, you might get the following notification from Google:

By default, Google blocks apps from using SMTP without permissions. We can solve this by clicking on the allow "less secure apps" link and toggle the feature on. The next object detected will send an email.

STEP 4:Blynk App Interface Setup

This is one of the easiest and fun steps. So let's get started. Shall we?

  • Downloading the Blynk App is the first obvious step. Download it from App Store or Google Play Store. Sign Up or Login in the app to get started.
  • Click on New Project to create a new project. Name it whatever you like. In devices Choose NodeMCU. In connection type choose WiFi and click on Create.
  • Now you will get a Auth key on your Email. Make sure to copy that and add that to your code.
  • Now click on the + sign to add widgets. You may need to buy some energy!
  • Now add three Gauge's. Click on of the Gauge's, name it Temperature. Choose a color of you choice for this gauge. In the pin choose Virtual Pin V6. Set the range from 0 to 50 °C ( not sure for °F), make the label °C/ °F and keep the reading rate to Push.
  • Repeat this for other two Gauges using data as shown in the pictures.
  • Now, add a zeRGBa and set R to digital Pin GP15, B to GP3 and B to GP1.
  • Now add 4 Buttons, change there colors accordingly. Set them as shown in the pictures.
  • Add a SuperChart, add 3 data streams Temperature, Humidity and gas, set there colors, there pins, Range and Suffix.
  • Now, add tabs. Go to the second tab and add Twitter, Notifications, Email and Eventor. In Twitter add you twitter username and password. In Notifications, Switch on Notify when hardware goes off. In Email, set your Email address. In Eventor you can set many triggers, see the picture for the triggers that I have set up.
  • You are done. now click on the play button to use the interface that you have created. You can change the interface as you like. It is really simple and fun process!

STEP 5:Making Octopod Structure

Warning - This is going to be one of most time-consuming process!

NOTE:You can skip this step and 3D print the enclosure that I have provided!

Actually, this step is optional yet the most important step! You can just take a shoe box and avoid all of this hard work. But on the contrary, this hard work makes the project unique. The idea for this unique design striked me while, I was doing my math homework. This shape is inspired from an octagon. Rather, This is a 3D octagon! So let's get started!

Making the Structure:

  • Take your cardboard and draw a rectangle of 9 cm x 9.5 cm (You can change the dimensions as per your convince). Now, joining end to end draw 4 of theses similar rectangles (8 if your cardboard is long enough).
  • Now make partial cuts (somewhat like paper creases) in between these rectangles and cut out this whole long piece. Repeat this process until you have 4 of these long pieces.
  • Now, using a D draw a 135° and cut it out as shown in the images. Make 16 of these same angles.
  • Using Glue gun glue these angles in between the small pieces. Repeat this for all the joints.
  • Now using glue gun join 2 of these open structures to make a closed structure (somewhat octagon) .
  • Now glue the other two open structure perpendicularly, making a 3-D shape.
  • Now Cut 4 More pieces of of 9 x 9.5 cm and glue them in between all the empty spaces.
  • Now you will be left with only 8 open triangles. Using Acrylic Butter paper cut 8 triangles, which will fit on these open areas, but don't glue them now.

Paint Job:

For this you need to head out towards an open area! Wear your Mask and Gloves and just make one coat over the structure that you have created. You can go to Youtube, to learn proper ways to make a perfect coat. Now let this dry for 4- 5 Hours and then apply 1 more coat. I think 3 coats will be good for this.

That's it! You have arrived with a unique piece of art.

STEP 6:Making Door Lock Enclosure

Really simple. Just take a Shoe Box and apply 2- 3 even coats of spray. And maybe for design make check pattern using duck tape like we did!

STEP 7:Assembling the Octopod

I have tried to make this step as simple as possible, by making the schematic diagram. Refer the picture or the file, and make connections accordingly. I will briefly explain all the connections!

  • We have connected the nodeMCU to a large size Solderless Breadboard. We have also connected Breadboard power supply on the breadboard. NodeMCU, all the sensors, LED's and other components are powered by the power supply.
  • Following are the sensor connections:DHT11D4 / GP2 MQ2A0 / adc00 Soil Moisture SensorD2 / GP4 PIRD6 / GP1 RGB R → D8 / GP15, G → Rx / GP3, B → Tx / GP1 RelayLn1D0 / GP16, Ln2D5 / GP14 Make the following connections.
  • For powering this you can use Power Bank or a Wall Adapter, which will be connected to the breadboard Power supply.
  • Now, take your Raspberry Pi along with the Raspberry Pi Camera. Make a small hole in one of the walls of the cardboard and glue or tape your Raspberry Camera.

Now, insert all these electronics inside, through any open triangle and close the triangle by using the cut outs of acrylic butter paper that we made. It is better to leave 1 or 2 open, in case something inside needs to be fixed! Also let the prongs of the Soil Moisture Sensor sit outside.

すべて完了です。 We have completed the making process of the Octopod! Now, Just switch On the power and keep your Octopod over the dining Table or maybe on the Guest's Table and enjoy! To see the live feed from the Raspberry Pi, just open a browser and put in the IP address of the Pi. Enjoy!

STEP 8:Assembling the Door Lock

After uploading the code on your Arduino just make the connections as shown in the picture or in fritzing file! It is quite simple. Then take the handy shoe box that we made make 2 holes in it for the LED's to pop out. and allow the servo to stand out. These days mechanical locks like servo's are also available in the market, though servo works just as fine. This is just an experiment, so please so please don't use this as you actual lock! Glue the Rfid to one wall of the box and also glue the small breadboard and Arduino. You can use a wall adapter or a Power bank to power this. Just power the Arduino and you will be good to go! Done!

CONCLUSION:

This was a really fun project to do!

I was really happy how it turned out. I think the lights look really well, and i think its well worth making even one of these as a side lamp. I really can't thank creators of Blynk and OpenCV libraries enough, they are both really excellent pieces of software and made this project possible! As always, if you have any questions on any part of the process please let me know and I will be happy to try help. Thanks a lot! And Please Vote for Us!

-Saksham

Arduino Blog

Full Instructable

UPDATE:

I have been working on integrating this system with Amazon Alexa, I am almost done. Will upload the code in 2-3 days!

コード

  • octopod.ino
  • octopod_door.ino
  • octopod_door_bluetooth.ino
octopod.inoArduino
This is the main code for Arduino MKR 1010 (NodeMCU in my case)
If you are using MAX32620FTHR, download libraries for it. Then change the board in board settings. Also change the pin as given bellow
ESP MAX
AO - - - - - - - - - - - - GPIO2
A1 - - - - - - - - - - - - - GPIO1

Soil Sensor MAX
analog sensor - - - GPIO3

Gas Sensor (MQ2) MAX
sensor - - - - - - - - - - - GPIO4

PIR Sensor MAX
sensor - - - - - - - - - - - -GPIO0

Relay MAX
1 - - - - - - - - - - - - - - - - - M0
2 - - - - - - - - - - - - - - - - - M1
/*************************************************************************** OCTOPOD:A SMART HOME AUTOMATION PROJECT MADE BY SAKSHAM Download latest Blynk library here:https://github.com/blynkkk/blynk-library/releases/latestDownload latest DHT Sensor library here:https://github.com/adafruit/DHT-sensor-library***************************************************************************/#include  //Include ESP8266 Wifi Library#include  //Include Blynk Library#include  //Include DHT sensor library#define BLYNK_PRINT Serial// You should get Auth Token in the Blynk App.// Go to the Project Settings (nut icon).char auth[] ="Your Blynk Auth Key";// Your WiFi credentials.// Set password to "" for open networks.char ssid[] ="Your WiFi SSID";char pass[] ="Your WiFi Password";#define DHTPIN 2 // What digital pin temperature and humidity sensor is connected to#define soilPin 4 // What digital pin soil moist ure sensor is connected to#define gasPin A0 // What analog pin gas sensor is connected to#define pirPin 12 // What digital pin soil moisture sensor is connected to int pirValue; // Place to store read PIR Valueint soilValue; // Place to store read Soil Moisture Valueint PIRpinValue; // Place to store the value sent by Blynk App Pin V0int SOILpinValue; // Place to store the value sent by Blynk App Pin V1// Uncomment whatever type you're using!#define DHTTYPE DHT11 // DHT 11//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321//#define DHTTYPE DHT21 // DHT 21, AM2301DHT dht(DHTPIN, DHTTYPE);BlynkTimer timer;// This function sends Arduino's up time every second to Virtual Pin (5).// In the app, Widget's reading frequency should be set to PUSH. This means// that you define how often to send data to Blynk App.BLYNK_WRITE(V0) //VO pin from Blynk app tells if Motion Detection is ON{ PIRpinValue =param.asInt(); } BLYNK_WRITE(V1) //V1 pin from Blynk app tells if Soil Moisture is ON{ SOILpinValue =param.asInt(); } void sendSensor(){ int h =dht.readHumidity(); int t =dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); // to check if sensor is not sending any false values return; } // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V5, h); // send humidity to pin V5 Blynk.virtualWrite(V6, t); // send temperature to pin V7}void getPirValue(void){ pirValue =digitalRead(pirPin); if (pirValue) //digital pin of PIR gives high value on human detection { Serial.println("Motion detected"); Blynk.notify("Motion detected"); }}void getSoilValue(void){ soilValue =digitalRead(soilPin); if (soilValue ==HIGH) //digital pin of soil sensor give low value when humidity is less { Serial.println("Water Plants"); Blynk.notify("Water Plants"); }}void setup(){ // Debug console Serial.begin(9600); Blynk.begin(auth, ssid, pass); // You can also specify server://Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442); //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442); dht.begin(); // Begins DHT reading Blynk.tweet("OCTOPOD IS ONLINE! "); // Tweating on your Twitter Handle that you project is online pinMode(pirPin,INPUT); // Defining that Pir Pin is meant to take Input Only pinMode(soilPin,INPUT); // Defining that Soil Sensor Pin is meant to take Input Only // Setup a function to be called every second timer.setInterval(1000L, sendSensor);}void loop(){ Blynk.run(); timer.run(); if (PIRpinValue ==HIGH) //VO pin from Blynk app tells if Motion Detection is ON { getPirValue(); } if (SOILpinValue ==HIGH) //V1 pin from Blynk app tells if Soil Moisture is ON { getSoilValue(); }} 
octopod_door.inoArduino
Code for Automatic Door Lock Control (NO BLUETOOTH VERSION)
/*********************************************************************************************************** OCTOPOD:A SMART HOME AUTOMATION PROJECT MADE BY SAKSHAM ARDUINO RFID DOOR LOCK CODELibrary Required - MFRC522 ************************************************************************************************************/#include #include #include  #define SS_PIN 10#define RST_PIN 9#define LED_G 5 //define green LED pin#define LED_R 4 //define red LED#define BUZZER 2 //buzzer pinMFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.Servo myServo; //define servo name void setup() { Serial.begin(9600); // Initiate a serial communication SPI.begin(); // Initiate SPI bus mfrc522.PCD_Init(); // Initiate MFRC522 myServo.attach(3); //servo pin myServo.write(0); //servo start position pinMode(LED_G, OUTPUT); pinMode(LED_R, OUTPUT); pinMode(BUZZER, OUTPUT); noTone(BUZZER); Serial.println("Put your card to the reader..."); Serial.println();}void loop() { // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) { return; } //Show UID on serial monitor Serial.print("UID tag :"); String content="";バイトレター; for (byte i =0; i  
octopod_door_bluetooth.inoArduino
Code for Automatic Door Lock Control (Bluetooth Version)
/*********************************************************************************************************** OCTOPOD:A SMART HOME AUTOMATION PROJECT MADE BY SAKSHAM ARDUINO RFID DOOR LOCK CODELibrary Required - MFRC522 ************************************************************************************************************/#include SoftwareSerial BTserial(0, 1); // RX | TX#include #include #include #define SS_PIN 10#define RST_PIN 9#define LED_G 5 //define green LED pin#define LED_R 4 //define red LED#define BUZZER 2 //buzzer pinMFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.Servo myServo; //define servo namevoid setup(){ BTserial.begin(9600); // Initiate a serial communication BTserial.println("Waiting for connections..."); SPI.begin(); // Initiate SPI bus mfrc522.PCD_Init(); // Initiate MFRC522 myServo.attach(3); //servo pin myServo.write(0); //servo start position pinMode(LED_G, OUTPUT); pinMode(LED_R, OUTPUT); pinMode(BUZZER, OUTPUT); noTone(BUZZER); BTserial.println("Put your card to the reader..."); BTserial.println();}void loop(){ // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) { return; } //Show UID on serial monitor BTserial.print("UID tag :"); String content ="";バイトレター; for (byte i =0; i  

カスタムパーツとエンクロージャー

This is the basic design that you can use if you want to make the enclosure out of Cardboard/ Wood like me! octopod_v2_ukTmIJ0uMl.f3dProper Enclosure that you can 3D Print! octo_2_v3_sii4tuCF7d.f3d

回路図

Pin configuration might be different with Arduino MKR 1010 Without Bluetooth
For Bluetooth connect Rx (HC-05) --> Tx (Arduino)
Tx (HC-05) --> Rx (Arduino)
and 5v to 5v
Ground to Ground ESP MAX
AO - - - - - - - - - - - - GPIO2
A1 - - - - - - - - - - - - - GPIO1

Soil Sensor MAX
analog sensor - - - GPIO3

Gas Sensor (MQ2) MAX
sensor - - - - - - - - - - - GPIO4

PIR Sensor MAX
sensor - - - - - - - - - - - -GPIO0

Relay MAX
1 - - - - - - - - - - - - - - - - - M0
2 - - - - - - - - - - - - - - - - - M1

製造プロセス

  1. ホームオートメーションのアプリケーション
  2. スマートホームIoTの陰湿なマルバタイジングの餌食
  3. RASPBERRY PI HOME AUTOMATION
  4. スマートブラインド
  5. IOT-ESP8266、Arduino、超音波センサーを使用したスマートジャー
  6. 1Sheeldを使用したスマートホームオートメーションおよびセキュリティシステム
  7. Tech-TicTacToe
  8. Arduinoカウントダウンタイマー
  9. RCポルシェカー(Arduinoプロジェクト)
  10. Arduino&ESP8266によるWiFiログインページを使用したSmart Door Lock
  11. インダストリー4.0の自動化