Arduino UNO R4 - Control Heating Element
In this guide, we will learn to control a heating element using Arduino UNO R4. From this guide, you will further learn to create a heating system in a following tutorial.
This page shows two ways to switch the heater. The first way uses a relay, which only turns the heating element fully on or fully off. The second way uses a MOSFET module. It can also turn the heater on and off, but it lets the Arduino UNO R4 choose how much heat it makes, for example 30% or 70%. It is also silent, and its parts do not wear out when it switches often.

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables STEM V4 IoT Starter Kit (Arduino included) | |
| 1 | × | DIYables STEM V4B IoT Starter Kit (Arduino included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of Heating Element
Pinout

A heating element typically has two pins.
- Connect the positive (+) pin (red) to the 12V DC power supply.
- Connect the negative (-) pin (black) to the GND of the DC power supply.
How to Control Heating Element
When a 12V heating element is connected to a 12V power supply, it produces heat. To manage this Heating Element, we use a relay as a connector between the Arduino UNO R4 and the Heating Element. The Arduino UNO R4 can then control the Heating Element through the relay. If you are unfamiliar with how a relay functions, its pin configuration, or how to program it, you can learn more in the Arduino UNO R4 relay tutorial.
Planning to use the MOSFET module instead? Read the Arduino UNO R4 - MOSFET Module tutorial first. It shows the module pins and how PWM sets the power.
Relay vs MOSFET Module for a Heating Element
| Relay | MOSFET Module | |
|---|---|---|
| Heat control | full heat or no heat | full heat, no heat, or any level between (PWM) |
| Switching often | each switch wears the contacts a little | no contacts, so no wear |
| Sound | you hear a click | quiet |
| Speed | a few milliseconds | very fast |
| Supply type | AC or DC | DC only |
| Minimum supply | none, as long as it is in the relay rating | about 6V |
| Isolation | coil and contacts are separate | PC817 optocoupler |
| Best use | AC heaters, simple ON/OFF | DC heaters with heat level control or frequent switching |
A heater in a temperature control project is turned on and off again and again. A MOSFET module handles this better than a relay, and it can also keep the heat at a low level. For a heater that runs on AC mains, the relay is the only choice of the two.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
Arduino UNO R4 Code
The following code turns the Heating Element ON for five seconds and then OFF for five seconds repeatedly.
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Connect the heating element to the Arduino Uno according to the provided diagram.
- Connect the Arduino Uno R4 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Copy the code provided and paste it into the Arduino IDE.
- Click the Upload button in the Arduino IDE to transfer the code to the Arduino UNO R4.
- Monitor the temperature of the Heating Element.
WARNING
Be careful, it can cause burns and fire in your home. This is important and we want you to stay safe. If you are not completely sure about what you are doing, please do not handle anything. Instead, ask someone who knows about it. We are not responsible for your safety.
Code Explanation
The explanation is in the comments section of the Arduino code above.
Arduino UNO R4 Code - Control Heating Element with MOSFET Module
In this part, the MOSFET module takes the place of the relay. With PWM, we can give the heating element only part of the power, so it gets warm but not fully hot.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Uno R4 and other components.
- Pin 9 of the Arduino UNO R4 goes to the PWM pin of the module.
- GND of the Arduino UNO R4 goes to the GND pin of the module.
- The + wire of the 12V adapter and the + wire (red) of the heating element both go to the + terminal.
- The − wire (black) of the heating element goes to the LOAD terminal.
- The − wire of the 12V adapter goes to the − terminal.
A heating element is just a resistor, not a coil, so no flyback diode is needed.
Arduino UNO R4 Code
The code gives the heater full power for 2 seconds, then no power for 2 seconds. After that, the power climbs from 10% to 100% and falls back to 0%. A heating element warms up and cools down slowly, so you will not feel each step. Feel the change after a while, or run one power level for a longer time.
Detailed Instructions
- If you have not set up the Arduino IDE yet, follow the Quick Steps of the relay code above.
- Make the wiring shown in the diagram. Do not plug in the 12V adapter yet.
- Upload the code to the Arduino UNO R4.
- Plug in the 12V adapter.
- Open the Serial Monitor and set the baud rate to 9600.
- Check the power level in the Serial Monitor. Do not touch the heating element.
Tip: the MOSFET module is for DC heaters only, with a supply of about 6V or more. A heating element that runs on AC must use the relay.