Switches exist in various incarnations. There are the simple mechanical switches: on/off or push button switches but there are also switches than turn on or off with various external conditions:
and a PIR sensor.
The push button switch is connected to GPIO 17 on the ESP32 board.
Write a script that polls the state of the switch every 100 ms and prints state changes (only print out a message when the switch state has changed). Catch <ctrl> C to smoothly exit the program.
Check https://docs.micropython.org/en/latest/esp8266/tutorial/pins.html and https://docs.micropython.org/en/latest/esp32/quickref.html
for information on how to accomplish this.
Do the same thing as in exercise 1 but use external interrupts and a callback routine to do the job.
Combine this exercise with the exercise on LEDs: Switch the builtin LED on when the button is pressed and off when it is released
Write a program scanning the PIR sensor, indicating if a person is close. The PIR sensor, just like the push button, uses a single GPIO line as input. The boards allows to choose which GPIO to use and I selected D4 = GPIO 16
The sensor kit in the lab contains a big number of sensors acting like switches: