Arduino Nano 33 IoT - DHT11 - Relay
This guide shows you how to use the Arduino Nano 33 IoT board to control a relay using the temperature from a DHT11 sensor.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of Relay and DHT11 Sensor
If you're new to using the Relay, DHT11 Sensor, and Arduino Nano 33 IoT, please check out these tutorials:
These tutorials explain how Relay and DHT11 Sensor work, their pinouts, how to connect them to the Arduino Nano 33 IoT, and how to program Arduino Nano 33 IoT to work with the Relay and DHT11 Sensor.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
How System Works
- The Arduino Nano 33 IoT gets the temperature using the DHT11 sensor.
- When the temperature goes above a set level, the Arduino turns on the relay.
- When the temperature goes below a set level, the Arduino turns off the relay.
This process goes on forever in a loop.
If you want to switch the relay on when the temperature goes above a set value, and off when it goes below that same value, simply set both the maximum and minimum limits to that number.
Arduino Nano 33 IoT Code
In the code above, the Arduino Nano 33 IoT turns on the relay when the temperature goes above 25°C, and it stays on until the temperature falls below 20°C.
Detailed Instructions
If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:
- Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
- Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
- Click on the Libraries icon on the left side of the Arduino IDE.
- Search for DHT and then find the DHT sensor library by Adafruit.
- Click the Install button to add the library.

- You will be asked to install some extra library components.
- Click the Install All button to install all the necessary libraries.

- Copy the code for your sensor and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to send the code to your Arduino Nano 33 IoT.
- Change the temperature around the sensor by making it hotter or colder.
- Watch the relay to see its status.