Thank you very much for your help.
My code works great now with a delay(7000); after ArduinoCloud.begin(ArduinoIoTPreferredConnection); in setup just as ubidefeo and jomoengineer suggested. It shows the debug messages and executes the code.
I don't see a positive effect when resetting the board with the serial monitor open without a delay as decribed above.
jld13, does your sensor initialize when giving ArduinoCloud.begin some extra time?