Alarm system with the KY-003 Hall sensor

FunduinoPublished on

Magnetfelder erkennen und einen Alarm auslösen

Ein Hall-Sensor erkennt Magnetfelder. Führst du einen Magneten am KY-003 vorbei, leuchtet eine LED und ein Lautsprecher gibt einen Ton aus – das Grundprinzip jeder Fenster- und Türüberwachung in einer Alarmanlage.

Die Anleitung erklärt zuerst, wie ein Hall-Sensor überhaupt funktioniert und worin sich unipolare, bipolare, latching und non-latching Sensoren unterscheiden. Danach baust du die Schaltung auf und überträgst das Programm.

The KY-003 Hall sensor on its circuit board
The KY-003

You need this

KY-003 Hall sensor - digital magnetic switch, 3.3-5 V KY-003 Hall sensor - digital magnetic switch, 3.3-5 V 1,23 € *Item no. F23106679About the product — KY-003 Hall sensor - digital magnetic switch, 3.3-5 V
Passive buzzer - 5 V speaker, PWM control Passive buzzer - 5 V speaker, PWM control 0,90 € *Item no. F23106769About the product — Passive buzzer - 5 V speaker, PWM control
LED Assortment - 200 pieces, 10 colors, 3 mm and 5 mm LED Assortment - 200 pieces, 10 colors, 3 mm and 5 mm 6,10 € *Item no. F23108842About the product — LED Assortment - 200 pieces, 10 colors, 3 mm and 5 mm
Resistor Assortment - 8 Values, 10 Pieces Each, 10 Ohms to 100 kOhms, ±5% Resistor Assortment - 8 Values, 10 Pieces Each, 10 Ohms to 100 kOhms, ±5% 1,30 € *Item no. F23106603About the product — Resistor Assortment - 8 Values, 10 Pieces Each, 10 Ohms to 100 kOhms, ±5%

All 4 parts together 9,53 € *

* All prices include statutory VAT, plus shipping costs.

How a Hall sensor works

A Hall sensor consists of a semiconductor element carrying current and a permanently installed magnet behind it. This magnetically biases the semiconductor element.

When another magnet approaches this magnetic field, the measurable voltage in the semiconductor element changes. The microcontroller evaluates this change.

Hall sensors are used to switch devices on and off, automatically open and close windows and doors, monitor the status of alarm systems, and determine the speed and direction of rotation of motors.

The four designs

  • unipolar – responds to only one pole of the magnet
  • bipolar – responds to both poles
  • latching – changes state in a magnetic field and retains it even after the magnet is removed; only another magnetic field switches it back
  • non-latching – changes state in a magnetic field and returns to its original state when the magnet is removed
Characteristic curve of a unipolar Hall sensor
Unipolar: responds to only one pole
Characteristic curve of a bipolar Hall sensor
Bipolar: responds to both poles
1 / 2

The KY-003

The KY-003 is a unipolar, non-latching sensor. It reacts to only one pole of the magnet, and as soon as you remove the magnet, it returns to its initial state.

The KY-003 Hall sensor on its circuit board
The KY-003

Build the circuit

In addition to the microcontroller, you need a KY-003, a passive speaker, an LED with a 220-ohm series resistor, and a magnet for the alarm system.

The sensor is connected to Pin 6, the LED to Pin 7 , and the speaker to Pin 8.

You also need a magnet for the alarm system.

Circuit diagram of the alarm system with Hall sensor, LED, and speaker
The circuit diagram

The program

As soon as the sensor detects a magnetic field, the microcontroller reads a LOW signal. The LED then lights up and the speaker emits a tone at 1000 hertz. When the magnet is removed, both turn off again.

Alarm when a magnetic field is detected
int MAGNETSENSOR = 6;
int LED = 7;
int SPEAKER = 8;
void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(MAGNETSENSOR, INPUT);
}
void loop()
{
  int SensorReading = digitalRead(MAGNETSENSOR);
  if (SensorReading == LOW)
  {
    digitalWrite(LED, HIGH);
    tone(SPEAKER, 1000);
  }
  else
  {
    digitalWrite(LED, LOW);
    noTone(SPEAKER);
  }
}
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.