Most of us are familiar with the switches used in household devices. A relay is a type of switch that can be connected to an Arduino or any other microcontroller.
In this tutorial, we will use the Arduino to control a relay on and off every three seconds. You can use the same code to control a fan to be turned on and off automatically every 10 minutes to save power!
Connect the wires between the relay and the Arduino, as shown in the image below.
Connections from the Arduino to the DHT11:
• Arduino GND pin → DHT11 GND pin (- pin)
• Arduino 5V pin → DHT11 VCC pin (+ pin)
• Arduino pin 3 → DHT11 out pin
Now access the serial monitor on your Arduino IDE by clicking on the magnifying glass icon at the top right corner.
As we can see in the following image, the serial monitor displays the relay state. You can also hear the sound of the relay switching on and off every three seconds.