Yesterday I learned how to turn off sensors on an Android phone running Android 10 or later. First, you enable developer options. Then you go to System - Developer options, choose "Quick settings developer tiles", and turn on the "Sensors Off" option. Now an option will appear in your Quick Settings menu which can switch off/on all the sensors.
Note that and cameras and microphones are considered as sensors too, and are therefore controlled by this option. Speakers, flashlights etc. are not affected.