We take any R1BBIT board and connect it to an MH sensor: +3.3V and GND for power, and the signal output to ADC1.
We write a simple program — and we have an alarm system for any door, refrigerator, garage, etc.
// D – status flag
// 0 = door is closed (notification not sent)
// 1 = door is open (notification already sent)
VAR D=0
// Endless loop
WHILE (1)
// If analog value on ADC1 is greater than threshold (2)
// It means the sensor detects OPEN state
IF ADC_IN1>2 THEN
// Send notification only once
IF D=0 THEN
SEND_NOTIFY("***The door is OPEN!***")
D=1 // Mark door as open
ENDIF
ENDIF
// If door was open (D=1)
// and analog value falls below threshold
// it means the door is closed again
IF D=1 AND ADC_IN1<2 THEN
SEND_NOTIFY("The door is closed!")
D=0 // Reset status flag
ENDIF
WEND
