You should really check out: Serial Input Basics - updated - #3 by Robin2
Also, you are not testing to see that you have received a valid pin # so your code will change any pin.
Check this out: relays - Wokwi ESP32, STM32, Arduino Simulator
You should really check out: Serial Input Basics - updated - #3 by Robin2
Also, you are not testing to see that you have received a valid pin # so your code will change any pin.
Check this out: relays - Wokwi ESP32, STM32, Arduino Simulator