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.

Arduino UNO R4 heating element

Overview of Heating Element

Pinout

Arduino UNO R4 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

The wiring diagram between Arduino UNO R4 Heating Element

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.

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-controls-heating-element */ #define RELAY_PIN 3 // The Arduino UNO R4 pin connected to the IN pin of relay // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin as an output. pinMode(RELAY_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(RELAY_PIN, HIGH); // turn on heating element 5 seconds delay(5000); digitalWrite(RELAY_PIN, LOW); // turn off heating element 5 seconds delay(5000); }

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

The wiring diagram between Arduino UNO R4 heating element MOSFET module

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

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-controls-heating-element */ const int MOSFET_PIN = 9; // Arduino UNO R4 pin connected to the PWM pin of the MOSFET module void setup() { Serial.begin(9600); pinMode(MOSFET_PIN, OUTPUT); analogWrite(MOSFET_PIN, 0); // start with the load OFF } void setLoad(int percent) { int duty = map(percent, 0, 100, 0, 255); // convert 0-100% to 0-255 analogWrite(MOSFET_PIN, duty); Serial.print("Load power: "); Serial.print(percent); Serial.println("%"); } void loop() { // turn the load fully ON, then fully OFF Serial.println("Load: ON"); setLoad(100); delay(2000); Serial.println("Load: OFF"); setLoad(0); delay(2000); // increase the power step by step (PWM) for (int percent = 10; percent <= 100; percent += 10) { setLoad(percent); delay(500); } // decrease the power step by step (PWM) for (int percent = 90; percent >= 0; percent -= 10) { setLoad(percent); delay(500); } delay(1000); }

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.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
Load: ON Load power: 100% Load: OFF Load power: 0% Load power: 10% Load power: 20% Load power: 30% Load power: 40% Load power: 50% Load power: 60% Load power: 70% Load power: 80% Load power: 90% Load power: 100% Load power: 90% Load power: 80% Load power: 70% Load power: 60% Load power: 50% Load power: 40% Load power: 30% Load power: 20% Load power: 10% Load power: 0%
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

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.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!