Arduino Nano - Heating Element
This tutorial instructs you how to control a heating element with Arduino Nano. Subsequently, you will be able to apply this knowledge to create a heating system in a separate tutorial.
The Nano can drive the heater through a relay or through a MOSFET module. The relay only switches the heater fully ON or fully OFF. The MOSFET module can do that too, but it can also set the heat level, for example 30% or 70% of the full power. You will learn both methods here.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of Heating Element
The Heating Element Pinout

The heating element typically has two pins:
- The Positive (+) pin (red) should be connected to the 12V of a DC power supply
- The Negative (-) pin (black) should be connected to the GND of a DC power supply
How to Control Heating Element using Arduino Nano
If a 12V heating element is supplied with 12V power, it will generate heat. In order to regulate the heating element, a relay must be placed between the Arduino Nano and the heating element. The Arduino Nano can then control the heating element through the relay.
If you are unfamiliar with relays (pinout, how they work, how to program them, etc.), please refer to the Arduino Nano - Relay tutorial for more information.
The MOSFET module is covered step by step in the Arduino Nano - MOSFET Module tutorial. Read it first if this module is new to you.
Relay vs MOSFET Module for Heating Element
| Relay | MOSFET Module | |
|---|---|---|
| Heater control | full heat or no heat | full heat, no heat, or any heat level in between (PWM) |
| Sound | clicks every time it switches | no sound at all |
| Switching speed | slow (milliseconds) | very fast |
| Switching often | the contacts wear out | no moving parts, no contact wear |
| Supply type | AC or DC | DC only |
| Supply voltage | any (as rated) | about 6V or higher |
| Isolation | yes, between coil and contacts | yes, by a PC817 optocoupler |
| Best use | AC heaters, simple ON/OFF | 12V DC heaters, heat level control, frequent switching |
A heating system often switches the heater ON and OFF many times to hold a temperature. For a 12V DC heater, the MOSFET module handles this well because it does not wear out. Use the relay if your heater runs on AC mains.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
A screw terminal keeps each wire tight, even when the board shakes. You can plug the Arduino Nano into a Screw Terminal Expansion Board for Arduino Nano and connect the wires to its screw terminals. Below is the wiring diagram with the screw terminal board.

This image is created using Fritzing. Click to enlarge image
Arduino Nano Code
The code below will cause the heating element to be switched ON every five seconds and OFF again after five seconds have passed.
Detailed Instructions
- Connect your Arduino Nano to the computer using a USB cable.
- Launch the Arduino IDE, select the appropriate board and port.
- Paste the code into the Arduino IDE.
- Click the Upload button in the Arduino IDE to send the code to the Arduino Nano.
- Check the temperature of the heating element.
WARNING
Take caution. It can hurt you and your home. This is a significant issue, and we want you to be secure. If you are NOT absolutely certain what you are doing, do yourself a favor and don't meddle. Seek advice from someone who is knowledgeable! We do NOT accept any liability for your safety.
Code Explanation
Check out the line-by-line explanation contained in the comments of the source code!
Arduino Nano Code - Control Heating Element with MOSFET Module
In this part, a MOSFET module takes the place of the relay. With PWM, the Nano can give the heater only a part of its power.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
If you plan to keep this circuit, think about screw terminals. Simply plug the Arduino Nano into a Screw Terminal Expansion Board for Arduino Nano. Below is the wiring diagram with the screw terminal board.

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Nano and other components.
- Nano pin D9 goes to the PWM pin of the module, and Nano GND goes to the GND pin of the module.
- The 12V adapter + and the heater + (red) both go to the + terminal.
- The heater − (black) goes to the LOAD terminal.
- The 12V adapter − goes to the − terminal.
- A heating element is not a coil, so no flyback diode is needed.
Code and Quick Steps
The program switches the heater fully ON for 2 seconds, then OFF for 2 seconds. After that, it raises the power from 10% to 100% and brings it back down. A heater warms up and cools down slowly, so you will feel the change only after a while.
- Set up the Arduino IDE in the same way as in the relay Quick Steps.
- Connect the parts as in the diagram above, with the 12V adapter not plugged in.
- Upload the code to the Arduino Nano.
- Plug in the 12V adapter.
- Open the Serial Monitor (9600 baud) to see the power level:
Note: the MOSFET module is for DC heaters only, and the heater supply must be about 6V or more. An AC heater must use the relay.