Tìm kiếm mã

Mã Arduino và Video cho Mô-đun Cảm biến Hall KY-024

Mã Arduino và Video cho Mô-đun Cảm biến Hall KY-024

Trong hướng dẫn này, chúng ta sẽ khám phá cách sử dụng mô-đun cảm biến Hall KY-024 với Arduino để phát hiện từ trường. Cảm biến Hall sẽ được sử dụng để kích hoạt một hành động khi nó phát hiện từ trường và chúng ta sẽ hiển thị kết quả trên Serial Monitor. Kết quả là một cách đơn giản nhưng hiệu quả để tích hợp cảm biến từ vào các dự án của bạn, tạo nền tảng để mở rộng thêm. Để có giải thích chi tiết hơn, hãy xem video (trong video tại 00:00).

3144 hall sensor module
Mô-đun cảm biến Hall 3144 màu đỏ
3144 hall sensor module
3144 hall sensor module

Giải thích phần cứng

Mô-đun cảm biến Hall được thiết kế để phát hiện từ trường và thường được sử dụng trong nhiều ứng dụng khác nhau, bao gồm cảm biến tiệm cận và phát hiện tốc độ. Khi có từ trường, cảm biến sẽ xuất ra tín hiệu mà Arduino có thể đọc được. Điều này cho phép Arduino biết khi nào có vật thể mang từ trường ở gần.

Trong dự án này, chúng ta cũng sẽ sử dụng một còi báo động (buzzer) làm thiết bị hành động. Khi cảm biến Hall phát hiện từ trường, Arduino sẽ kích hoạt còi để phát ra cảnh báo âm thanh. Các thành phần cơ bản liên quan bao gồm cảm biến Hall, bo mạch Arduino và còi báo động.

Chi tiết từ bảng dữ liệu

Nhà sản xuất Honeywell
Số bộ phận SS495A1
Điện áp Logic/IO 4,5 – 10 V
Điện áp cấp nguồn 4,5 – 10 V
Dòng điện đầu ra (mỗi kênh) 20 mA tối đa
Dòng điện đỉnh (mỗi kênh) 50 mA tối đa
Hướng dẫn tần số PWM Không áp dụng
Ngưỡng logic đầu vào 0,7 V (cao), 0,3 V (thấp)
Sụt áp / RDS(on) / bão hòa 0,4 V tối đa
Giới hạn nhiệt độ -40 đến +85 °C
Kiểu đóng gói TO-92
Ghi chú / biến thể Có sẵn ở các độ nhạy khác nhau

 

  • Đảm bảo nguồn điện phù hợp trong phạm vi điện áp quy định.
  • Chú ý đến giới hạn dòng điện đầu ra để tránh làm hỏng mô-đun.
  • Sử dụng điện trở kéo lên nếu cần thiết để có kết quả đọc ổn định.
  • Giữ cảm biến tránh xa các trường điện từ mạnh có thể gây nhiễu.
  • Hiệu chỉnh cảm biến theo nhu cầu ứng dụng cụ thể.

Hướng dẫn đấu dây

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

Để đấu dây mô-đun cảm biến Hall với Arduino, hãy bắt đầu bằng cách kết nối chân VCC của cảm biến với chân 5V của Arduino để cấp nguồn. Tiếp theo, kết nối chân GND với chân GND của Arduino để hoàn thành mạch điện. Chân đầu ra của cảm biến Hall, thường được đánh dấu là OUT, nên được kết nối với chân kỹ thuật số 2 trên Arduino.

Đối với còi báo động, kết nối cực dương với chân kỹ thuật số 8 trên Arduino và kết nối cực âm với GND. Thiết lập này cho phép Arduino đọc tín hiệu đầu ra của cảm biến và kích hoạt còi khi phát hiện từ trường.

3144 hall sensor module black

Ví dụ mã và hướng dẫn chi tiết

Đoạn mã sau khởi tạo cảm biến Hall và còi báo động. Nó định nghĩa các chân cho cảm biến và hành động. Vòng lặp chính đọc trạng thái cảm biến và kích hoạt còi tương ứng.


#define DETECT 2 // chân 2 cho cảm biến
#define ACTION 8 // chân 8 cho hành động

void setup() {
  Serial.begin(9600);
  pinMode(DETECT, INPUT); // định nghĩa chân đầu vào phát hiện
  pinMode(ACTION, OUTPUT); // định nghĩa chân đầu ra ACTION
}

Trong mã này, biến DETECT được gán cho chân 2, dùng để đọc cảm biến. Biến ACTION được gán cho chân 8, nơi kết nối còi báo động. Hàm setup khởi tạo giao tiếp nối tiếp và đặt chế độ cho các chân.

Wirig relay module to AC load
3144 hall sensor module

void loop() {
  int detected = digitalRead(DETECT); // đọc cảm biến Hall
  if (detected == LOW) {
    digitalWrite(ACTION, HIGH); // bật còi
    Serial.println("Đã phát hiện!");
  } else {
    digitalWrite(ACTION, LOW); // tắt còi
    Serial.println("Không có gì");
  }
  delay(200);
}

Phần mã này liên tục kiểm tra trạng thái của cảm biến Hall. Nếu cảm biến phát hiện từ trường (khi detectedLOW), nó sẽ bật còi và in "Đã phát hiện!" lên Serial Monitor. Nếu không phát hiện từ trường, nó sẽ tắt còi và in "Không có gì".

Trình diễn / Điều gì sẽ xảy ra

Khi bạn chạy mã, Arduino sẽ liên tục theo dõi cảm biến Hall để phát hiện bất kỳ từ trường nào. Nếu phát hiện từ trường, còi sẽ kêu và bạn sẽ thấy "Đã phát hiện!" trên Serial Monitor. Nếu không có từ trường, còi sẽ tắt và hiển thị "Không có gì". Hãy cẩn thận với việc đấu dây để tránh đảo cực, điều này có thể dẫn đến lỗi phát hiện (trong video tại 06:15).

Mốc thời gian video

  • 00:00 - Giới thiệu về mô-đun cảm biến Hall
  • 02:30 - Giải thích cách đấu dây
  • 05:00 - Hướng dẫn chi tiết mã
  • 08:15 - Trình diễn

Hình ảnh

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
Ngôn ngữ: 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);
}

Tài nguyên & tài liệu tham khảo

Tập tin📁

Bảng dữ liệu (pdf)

  • SS49E_SS39ET_SS59ET_hall_sensor_honeywell_49E
    The SS39ET/SS49E/SS59ET Series low-cost linear Hall-effect sensor ICs are small, versatile devices that are operated by the magnetic field from a permanent magnet or an electromagnet. They are designed and manufactured for cost competitiveness. The linear sourcing output voltage is set by the supply voltage and varies in proportion to the strength of the magnetic field. Low voltage capability as low as 2.7 Vdc and reduced current consumption of only 6 mA typically at 5 Vdc help make this product energy efficient. The integrated circuitry features low noise output, which makes it unnecessary to use external filtering. These sensor ICs Interface with many electrical components without buffering. They also include thin film resistors to provide increased temperature stability and accuracy. These linear Hall-effect sensor ICs have an operating temperature range of -40 °C to 100°C [-40 °F to 212 °F], appropriate for industrial and medical environments. Thermal balancing allows for stable operation over the full temperature range. They are available in three package styles, all of which may be supplied on tape for automated, lower-cost assembly: • SOT-23: SS39ET. This small footprint takes up less space on the PC board, typically allowing for more components. • Flat TO-92-style, with different lead configurations: SS49E, SS49E-L, SS49E-F. • SOT-89B: SS59ET.
    SS49E_SS39ET_hall_sensor_honeywell_49E.pdf 0.98 MB
  • 49E YANGZHOU Hall-effect linear hall sensor
    The 49E Series Economical Linear Hall-effect sensors are small, versatile linear Hall-effect devices that are operated by the magnetic field from a permanent magnet or an electromagnet. The linear sourcing output voltage is set by the supply voltage and varies in proportion to the strength of the magnetic field. The integrated circuitry features low noise output, which makes it unnecessary to use external filtering. It also includes thin film resistors to provide increased temperature stability and accuracy. These linear Hall sensors have an operating temperature range of -40 °C to 100 °C, appropriate for commercial, consumer, and industrial environments.
    49E_YANGZHOU_Hall-effect_linear_hall_sensor.pdf 0.49 MB
  • SS49E SS39ET Hall Sensor Honeywell 49E
    Datasheet for Honeywell SS49E and SS39ET linear Hall-effect sensor ICs. These sensors provide analog output proportional to magnetic flux density, operate from 4.5V to 10.5V, and are available in a small SIP package.
    SS49E_SS39ET_hall_sensor_honeywell_49E.pdf 0.98 MB