All in all, the described method is a very cost-effective way to make an existing device "smart". However, there were a few stumbling blocks, frankly speaking:
- When the gate is half open, it is displayed as "closed"
- The fine-tuning of the sensor was unexpectedly complex
- Whether the electronics are weatherproof enough remains to be seen
For this use case, however, these are points we can live with. In any case, I learned a lot in this little project, especially that code that interacts with the real world, such as querying an ultrasonic sensor, requires a high level of tolerance and error handling routines, since dust or insects can falsify the result - this happens rather rarely in a computer.