An example has been added as an option to implement a magnetic sensor in order to detect when a door or window is open or closed.
The sensor outputs a 0
when it detects the magnetic field and when the field is far away the output would be a 1
; so you can determine when the door is open or closed.
The program in the Arduino is performed as follows:
We define the input signal of the sensor, and configure the serial communication:
void setup() { pinMode(sensor, INPUT_PULLUP); Serial.begin(9600); }
We read the state of the sensor:
void loop() { state = digitalRead(sensor);
It compares the digital input and displays the status of the door in the serial interface:
if (state == LOW){ Serial.println("Door Close"); } if (state == HIGH){ Serial.println("Door Open"); } }