MKR1000 to

A fairly simple project that attaches everyone’s favorite environmental monitor, the DHT, to the Arduino MKR1000 then transmits sensor data.

Things used in this project

Hardware components

DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
Arduino MKR1000
Arduino MKR1000


Step 1.

Connect the DHT data line out to the MKR1000 Pin1( labeled 1 on back of board).

Step 2. Download the WiFi101 Library and DHT Library from:

Step 3.

Go to the Board Manager in the Arduino IDE

Tools–>Board–>Boards Manager

Search for for Arduino SAMD Boards (32-bits ARM Cortex M0+)

Download version 1.6.3 (I had issues with 1.6.4 as the MKR100 Board didn’t get installed)

Step 4.

Create a free account, label the fields to Graph (humidity and temperatures) and paste your ThingSpeak “write” API key into the provided sketch along with your WiFi SSID and WiFI password.

Step 5.

Select the proper Com Port, looking for the MKR1000, and compile and run the code.

You should see the updates being sent to ThingSpeak in your Serial Window.

have fun!


Board image

Wire DHT data line to MKR100 pin 1 (5th pin up)
connect 5v and ground to DHT sensor, both of which are provided by the MKR1000


A combination of sketches from AdaFruit, WiFi101 WebClient, and ThingSpeak Arduino Templates.
This sketch is a combination of ADAFruits DHT sketch, WiFi101 Webclient
and The arduino example from ThingSpeak
Modified by Stephen Borsay for the MKR1000, feel free to use

#include <SPI.h> //you don't need this as we arn't using the shiled just chip
#include <WiFi101.h>
#include "DHT.h"

#define DHTPIN 1    // what pin we're connected to, pin1 is 5th pin from end

// Uncomment whatever DHT sensor type you're using!
#define DHTTYPE DHT11  // DHT 11
//#define DHTTYPE DHT21  // DHT 21
//#define DHTTYPE DHT22  // DHT 22


String apiKey ="YourApiKeyHere"; // api from ThingSpeak

char ssid[] = "YourSSIDHERE"; //  your network SSID (name)
char pass[] = "YourPasswordHere";    //your network password
int keyIndex = 0;     // your network key Index number (needed only for WEP)

//#define WEBSITE ""

int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "";    // name address for Google (using DNS)

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

void setup() {
  //Initialize serial and wait for port to open:
  while (!Serial) 
    ; // wait for serial port to connect. Needed for native USB port only

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) 
    Serial.print("Attempting to connect to SSID: ");
    //Connect to WPA/WPA2 network.Change this line if using open/WEP network
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
  Serial.println("Connected to wifi");

void loop() {

   // Wait a few seconds between measurements.

  //prefer to use float, but package size or float conversion isnt working
  //will revise in future with a string fuction or float conversion function

  int h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  int t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  int f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f))
    Serial.println("Failed to read from DHT sensor!");

  // Compute heat index in Fahrenheit (the default)
  int hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  int hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(" *C ");
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(" *C ");
  Serial.println(" *F\n");

    Serial.println("\nStarting connection to server..."); 
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected to server");

          client.print(F("POST "));
          +               (String) h
          +  "&field2=" +(String) t
          +  "&field3=" +(String) f
          +  "&field4=" +(String) hic
          +  "&field5=" +(String) hif
          String tsData = "field1="   //need the length to give to ThingSpeak
          +             (String)  h
          +  "&field2=" +(String) t
          +  "&field3=" +(String) f
          +  "&field4=" +(String) hic
          +  "&field5=" +(String) hif

          client.print("POST /update HTTP/1.1\n");  
          client.print("Connection: close\n");
          client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
          client.print("Content-Type: application/x-www-form-urlencoded\n");
          client.print("Content-Length: ");
          client.print(tsData.length());  //send out data string legth to ts


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(" dBm");

About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation, and engineering. I have a clear and simple writing style and am skilled in using infographics and diagrams. I am a great researcher and is able to present information in a well-organized and logical manner.

Scroll to Top