Nice, thanks for the code.
I'm teaching a class of students how to use sensors with the explorerhat and this is perfect starter code. I'll give them this then get them to be creative and set off an alarm, or take a photo of the intruder.
I've been creating a lot more starter projects with explorerhat and sensors. I'll be adding more as and when I create them PiTime Projects