12
Description
The KY003 Hall Magnetic Field Sensor Module is a magnetic switch.
Specs
Parts Required
Arduino UNO (or equivalent)
KY003 Hall Magnetic Field Sensor Module
USB cable
Connections
Pin – = GND, connect to GND
Pin (middle pin) +5 v, connect to +5v
Pin S signal, connect to Arduino pin 3 (or your own choice buit code would need updated)
Code
[codesyntax lang=”cpp”]
int LedPin = 13 ; int HallPin = 3; int val; // define numeric variables val void setup () { pinMode (LedPin, OUTPUT) ; pinMode (HallPin, INPUT) ; } void loop () { val = digitalRead (HallPin) ; // read digital interface is assigned a value of 3 val if (val == HIGH) // When the shock sensor detects a signal, LED flashes { digitalWrite (LedPin, LOW); } else { digitalWrite (LedPin, HIGH); } }
[/codesyntax]