検索コード

Arduinoコードとホールセンサーモジュールのビデオ

Arduinoコードとホールセンサーモジュールのビデオ

このチュートリアルでは、Arduinoとホールセンサーモジュールを使って磁場を検出する方法を解説します。ホールセンサーは磁場を検知したときに動作をトリガーするために使い、結果はシリアルモニターに表示します。その結果、プロジェクトに磁気検知を組み込むためのシンプルで効果的な方法が得られ、さらに拡張するための基礎が築けます。より詳しい説明については、動画(動画内 00:00)をぜひご覧ください。

3144 hall sensor module
3144 hall sensor module

ハードウェアの解説

ホールセンサーモジュールは磁場を検出するように設計されており、近接検知や速度検出などさまざまな用途で一般的に使用されます。磁場が存在するとセンサーはArduinoで読み取れる信号を出力します。これにより、Arduinoは磁場を持つ物体が近くにあることを検知できます。

このプロジェクトでは、動作装置としてブザーも使用します。ホールセンサーが磁場を検知すると、Arduinoがブザーを作動させて音で警告します。基本的な構成要素はホールセンサー、Arduinoボード、ブザーです。

データシートの詳細

製造元ハネウェル
部品番号SS495A1
ロジック/IO電圧4.5〜10V
電源電圧4.5〜10V
出力電流(チャンネルごと)最大20 mA
ピーク電流(チャネルあたり)最大50 mA
PWM周波数に関する指針該当なし
入力論理閾値0.7 V(高)、0.3 V(低)
電圧降下 / Rドレイン・ソース間オン抵抗/ 彩度最大0.4 V
熱限界-40〜+85 °C
パッケージTO-92
備考 / バリエーションさまざまな感度で利用可能です

  • 指定された電圧範囲内で適切な電源供給を確保してください。
  • モジュールを損傷しないよう、出力電流の制限に注意してください。
  • 安定した読み取りを得るために、必要であればプルアップ抵抗を使用してください。
  • 干渉を引き起こすおそれのある強い電磁界からセンサーを離してください。
  • 特定のアプリケーションの要件に合わせてセンサーを校正してください。

配線手順

Arduino wiring for 3144 Hal sensor module (black)
Arduino wiring for 3144 Hal sensor module (black)
Arduino wiring for 3144 Hal sensor module
Arduino wiring for 3144 Hal sensor module

ホールセンサーモジュールをArduinoに配線するには、まずセンサーのVCCArduinoのピンに5V電源用のピン。次に、接続しますGNDArduinoのピンにGND回路を完成させるためのピン。ホールセンサーの出力ピンは、通常はそのように表示されます。OUT、デジタルピンに接続される必要があります2Arduino上で。

ブザーでは、プラス端子をデジタルピンに接続します。8Arduino上で、負極端子を接続するGND. この設定により、Arduinoはセンサーの出力を読み取り、磁場が検出されるとブザーを作動させます。

コード例と解説

以下のコードはホールセンサーとブザーを初期化します。センサー用と動作用のピンを定義します。メインループではセンサーの状態を読み取り、それに応じてブザーを作動させます。

3144 hall sensor module black

#define DETECT 2 // pin 2 for sensor
#define ACTION 8 // pin 8 for action to do something

void setup() {
  Serial.begin(9600);
  pinMode(DETECT, INPUT); // define detect input pin
  pinMode(ACTION, OUTPUT); // define ACTION output pin
}

このコードでは、DETECT変数がピンに割り当てられている2、これはセンサーを読み取るために使用されます。そのACTION変数がピンに割り当てられている8、ブザーが接続されている場所です。setup関数はシリアル通信を初期化し、ピンモードを設定します。


void loop() {
  int detected = digitalRead(DETECT); // read Hall sensor
  if (detected == LOW) {
    digitalWrite(ACTION, HIGH); // set the buzzer ON
    Serial.println("Detected!");
  } else {
    digitalWrite(ACTION, LOW); // Set the buzzer OFF
    Serial.println("Nothing");
  }
  delay(200);
}

このコードの部分はホールセンサーの状態を継続的にチェックします。センサーが磁場を検出した場合(detectedであるLOW)、ブザーをONにしてシリアルモニタに "Detected!" と表示します。フィールドが検出されない場合は、ブザーをOFFにして "Nothing" と表示します。

Wirig relay module to AC load
3144 hall sensor module

デモンストレーション/期待される内容

コードを実行すると、Arduinoはホールセンサーの磁場を常時監視します。磁場が検出されると、ブザーが鳴り、シリアルモニタに "Detected!" と表示されます。磁場が存在しない場合はブザーは鳴らず、"Nothing" と表示されます。配線が逆にならないよう注意してください。逆配線は検出不能につながる可能性があります(動画の06:15で)。

動画のタイムスタンプ

  • 午前00:00- ホールセンサーモジュール入門
  • 02:30- 配線の説明
  • 05:00- コードの解説
  • 08:15- デモンストレーション

画像

Wirig relay module to AC load
Wirig relay module to AC load
3144 hall sensor module black
3144 hall sensor module black
3144 hall sensor module
3144 hall sensor module
3144 hall sensor module
3144 hall sensor module
3144 hall sensor module
3144 hall sensor module red
Arduino wiring for 3144 Hal sensor module (black)
Arduino wiring for 3144 Hal sensor module (black)
Arduino wiring for 3144 Hal sensor module
Arduino wiring for 3144 Hal sensor module
3144 hall sensor module
3144 hall sensor module
65-Hall sensor module for Arduino
言語: C++
/*
 * This is the Arduino code for a Hall Sensor module for Arduino.

 // Written for Robojax.com video 
* A Hall sensor switch will detect the magnetic field, and the module is used to trigger something.
 * Watch the video for details: https://youtu.be/QH1Lw9BwTJI
 * Code is available at: http://robojax.com/learn/arduino

 * 
Written by Ahmad Nejrabi for Robojax.com
on January 28, 2018 at 19:41 in Ajax, Ontario, Canada
 * Permission granted to share this code, given that this
 * note is kept with the code.
 * Disclaimer: This code is "AS IS" and for educational purposes only.
 * 
 */

 /*
 */
  // Hall Sensor code for Robojax.com
#define DETECT 2 // pin 2 for sensor
#define ACTION 8 // pin 8 for action to do something


void setup() {
  Serial.begin(9600);
  Serial.println("Robojax.com Hall Module Test");
  pinMode(DETECT, INPUT);//define detect input pin
  pinMode(ACTION, OUTPUT);//define ACTION output pin
  // Flame sensor code for Robojax.com

}

void loop() {
     // Hall Sensor code for Robojax.com

  int detected = digitalRead(DETECT);// read Hall sensor
  int detectedAn = analogRead(A0);// read flame analog value

  if( detected == LOW)
  {
    digitalWrite(ACTION,HIGH);// set the buzzer ON
    Serial.println("Detected!");
   // Serial.println(detectedAn);// print analog value
  }else{
    digitalWrite(ACTION,LOW); // Set the buzzer OFF
    Serial.println("Nothing");
     // Hall Sensor code for Robojax.com

  }



  delay(200);
}

リソースと参考文献

ファイル📁

ファイルは利用できません。