
No. 22 • Digital
Hall Effect Sensor (KY-003)
ตรวจจับแม่เหล็กด้วย Hall effect sensor
Component NameHall Effect Sensor
Part No. / ModelKY-003
Interface TypeDigital
PinsS, VCC, GND
Note: ใช้แม่เหล็กถาวรเข้าใกล้เพื่อทดสอบสัญญาณ
Wiring Example
ตัวอย่างการต่อวงจรกับ Arduino UNO
| Sensor Pin | Arduino Pin |
|---|---|
| S | D2 |
| VCC | 5V |
| GND | GND |
Arduino IDE Code
// Hall Effect Sensor (KY-003)
// Board: Arduino UNO
// Read digital output from the sensor module.
const int SENSOR_PIN = 2;
void setup() {
Serial.begin(9600);
pinMode(SENSOR_PIN, INPUT);
}
void loop() {
int state = digitalRead(SENSOR_PIN);
Serial.print("Sensor state: ");
Serial.println(state);
delay(300);
}