Arduino Nano 33 IoT - Control Heating Element

This guide shows you how to use the Arduino Nano 33 IoT to control a heating element. In another guide, you will learn how to build a heating system.

The heater can be driven in two ways. The first way uses a relay, which only gives you two states: heating at full power or not heating at all. The second way uses a MOSFET module. It also turns the heater ON and OFF, but it can set the heat level too, for example 30% or 70% of full power. It is silent, and its parts do not wear out when it switches often. We will go through both ways on this page.

Arduino Nano 33 IoT Heating Element

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×Relay
1×Alternatively, MOSFET Module (AOD4184, LR7843 or FR120N)
1×Heating Element
1×12V Power Adapter
1×Optionally, DC Power Jack
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of Heating Element

Pinout

Arduino Nano 33 IoT Heating Element Pinout

A heating element normally has two pins.

  • The red positive (+) pin should go to the 12V of the DC power supply.
  • The black negative (-) pin should go to the ground (GND) of the DC power supply.

How to Control Heating Element

A 12V heating element warms up when it gets power from a 12V supply. To control the heating element, use a relay between the Arduino Nano 33 IoT and the heating element. The Arduino Nano 33 IoT sends signals to the relay, which then turns the heating element on or off. If you are not familiar with relays (what pins they use, how they work, how to program them, etc.), learn more in the Arduino Nano 33 IoT - Relay tutorial tutorial.

Instead of the relay, you can also put a MOSFET module between the board and the heater. New to this module? The Arduino Nano 33 IoT - MOSFET Module tutorial covers how it works and how to use it.

Relay or MOSFET Module for a Heating Element?

Feature Relay MOSFET Module
Heat control Full heat or no heat Full heat, no heat, or any level in between (PWM)
Switching often Contacts wear out a little each time No contacts, so nothing wears out
Sound Audible click Silent
Speed Takes a few milliseconds Switches almost instantly
Power type Works with AC and DC heaters Works with DC heaters only
Supply needed for the heater Any voltage within the relay rating 6V or higher
Separation from the board Coil and contacts are separated PC817 optocoupler keeps the sides apart
Use it for AC heaters and simple ON/OFF heating 12V DC heaters, heat level control, frequent switching

A temperature controller often turns the heater ON and OFF many times per hour. For a 12V DC heater, the MOSFET module handles this better and lets you set a gentle heat level. If the heater runs on AC mains, you must stay with the relay.

Wiring Diagram

The wiring diagram between Arduino Nano and 33 IoT Heating Element

This image is created using Fritzing. Click to enlarge image

Arduino Nano 33 IoT Code

This code repeatedly turns the heating element on for five seconds and then off for five seconds.

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-controls-heating-element */ #define RELAY_PIN 2 // The Arduino Nano 33 IoT pin connected to the heating element via the relay // The setup function runs once on reset or power-up void setup() { // initialize digital pin D2 as an output. pinMode(RELAY_PIN, OUTPUT); } // The loop function repeats indefinitely 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

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.
  • Copy the code provided above and paste it into the Arduino software.
  • Click the Upload button to compile and send the code to your Arduino Nano 33 IoT board.
  • Look at the temperature of the heating element.

WARNING

Be careful. It can burn you and your home. This is very serious, and we want you to be safe. If you are not 100% sure about what you are doing, please do not touch anything. Ask someone who understands. We are not responsible for your safety.

Code Explanation

The Arduino Nano 33 IoT code above has an explanation for each line. Please read the comments in the code!

Arduino Nano 33 IoT Code - Control Heat Level with MOSFET Module

This part swaps the relay for a MOSFET module. With PWM, the Arduino Nano 33 IoT can give the heater only part of its full power, so it warms up less.

Wiring Diagram

The wiring diagram between Arduino Nano and 33 IoT heating element MOSFET module

This image is created using Fritzing. Click to enlarge image

Make these connections:

  • Pin D9 of the Arduino Nano 33 IoT → PWM pin of the module
  • GND of the Arduino Nano 33 IoT → GND pin of the module
  • Positive wire of the 12V adapter → + terminal
  • Red (+) wire of the heating element → the same + terminal
  • Black (−) wire of the heating element → LOAD terminal
  • Negative wire of the 12V adapter → − terminal

A heating element is not a coil, so no flyback diode is needed here.

Arduino Nano 33 IoT Code

The program turns the heater fully ON for 2 seconds, then OFF for 2 seconds. After that, it raises the power from 10% to 100% and lowers it back to 0%. A heater changes temperature slowly, so you will notice the heat change only after some time.

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-controls-heating-element */ const int MOSFET_PIN = 9; // Arduino Nano 33 IoT 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); }

Detailed Instructions

  • Prepare the Arduino IDE and select the board as shown in the relay Quick Steps above.
  • With the 12V adapter unplugged, wire the heater and the module as in the diagram.
  • Upload the code above to the Arduino Nano 33 IoT.
  • Plug in the 12V adapter.
  • Open the Serial Monitor (9600 baud) to see the power level the board is sending.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano 33 IoT
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano 33 IoT' 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 Nano 33 IoT on COM15
2

※ NOTE THAT:

Use the MOSFET module with a DC heater only, powered by about 6V or more. An AC heater needs 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!