Disconnecting and reconnecting after sketch upload

Hello Arduino users, I am having problems using the MKR1000 board together with Arduino IoT Cloud.

The problem occurs when I use the online editor to upload my sketch to the board. After the upload the boards USB connection to my computer becomes unstable. It connects to the computer for a few seconds, then it disconnects for a few seconds and this repeats continuously. In the few seconds the board is active, I can see in the online editor’s serial monitor that its receiving sensor input from my DHT11 sensor.

What is even more puzzling, to me at least, is that if I use the Arduino IDE program offline, to upload the sketch without "thingProperties.h" and related IoT codes, the program works fine. By fine I mean it prints the sensor data to the serial monitor and there are no USB connection problems with my computer.

This is the code for the DHT11 Temperature and Humidity Sensor and MKR1000 that I am using:

Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudTemperatureSensor temperature;
  String msg;
  CloudRelativeHumidity humidity;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.

#include "thingProperties.h"
#include "DHT.h"
int sensoPin=4;
DHT dht(sensoPin,DHT11);

void setup() {
  // Initialize serial and wait for port to open:
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found

  // Defined in thingProperties.h

  // Connect to Arduino IoT Cloud
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4

void loop() {
  // Your code here 

  Since Msg is READ_WRITE variable, onMsgChange() is
  executed every time a new value is received from IoT Cloud.
void onMsgChange()  {
  // Add your code here to act upon Msg change
  Since Humidity is READ_WRITE variable, onHumidityChange() is
  executed every time a new value is received from IoT Cloud.
void onHumidityChange()  {
  // Add your code here to act upon Humidity change
void dht_sensor_getdata(){
  float hm=dht.readHumidity();
  float temp=dht.readTemperature();
  msg="Temperature =" + String(temperature)+"  Humidity = " + String(humidity);

Unfortunately, I don’t have a Schematic of the board and sensor, but I am hoping that it won’t be necessary as the set-up is quite simple. It consists of the MKR1000 and DHT11 sensor on a breadboard and three wires between the MKR1000 and DHT11, one for 5V one for GND and sensor output from DHT11 to Pin 4 on MKR1000. Besides the setup works offline so I don’t think that is where the problem is.

I hope one of you will be able to help me with this problem, as I have got stuck trying to solve it. To anyone who sees this and want to help me out, I thank you.

Best regards,
from a Arduino newbie.

Does the problem still occur if you remove the MKR1000 from the breadboard, so that there is nothing connected to the board at all? Of course, you won't get any sensor readings without a sensor attached, but it can be a simple test to see whether the circuit is relevant to your problem or not.

I just tried your suggestion. I removed the MKR1000 from the breadboard and detached the sensor from the MKR1000, so that the only things connected to the MKR1000 was the USB cable used to upload the sketch and power it. The problem still persists.

The only thing that changed was the serial monitors output:

***** Arduino IoT Cloud - configuration info *****

Device ID: 4e265d2e-69d2-42cf-bdb3-XXXXXXXXXXXX

Thing ID: 1383c21a-097e-4515-905d-XXXXXXXXXXXX

MQTT Broker: mqtts-sa.iot.arduino.cc:XXXX

WiFi.status(): 0

Current WiFi Firmware: 19.6.1