Alarm system with the KY-003 Hall sensor
FunduinoPublished on
Magnetfelder erkennen und einen Alarm auslösen
You need this
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
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
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%
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
The four designs
1 / 2
The KY-003
Build the circuit
The program
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