Arduino Giga R1 WiFi Control Fan

This guide covers DC fan control with the Arduino Giga R1 WiFi using relay-based switching. The implementation uses relay switching to provide electrical isolation between the Arduino's low-voltage digital signals and the fan's power circuit.

This tutorial walks through relay interfacing, safety considerations for motor control, and working code examples. You'll implement a basic on/off fan controller suitable for temperature-responsive cooling systems or automated thermal management.

There are two ways to drive the fan from the Giga: a relay or a MOSFET module. A relay can only switch the fan fully ON or fully OFF. A MOSFET module can do that too, and it can also set the fan speed with PWM, with no click sound. This page shows both ways: the relay first, then the MOSFET module.

Arduino Giga R1 WiFi - Controls Fan

Overview of DC Fan

DC fans convert DC electrical energy into rotational mechanical energy for forced air circulation. Operating voltages are typically 5V, 12V, or 24V DC, with current consumption from 50mA to 2A depending on size. Rotational speeds range from 1000 to 6000 RPM.

DC fans require relay interfacing for safe power switching, as direct GPIO drive cannot handle fan current demands. The Arduino Giga R1 WiFi's 3.3V logic levels work with relay modules for electrical isolation and current handling.

Pinout

The pinout defines the electrical interface between the fan motor and external power supply. Correct polarity connection is essential — reversed polarity may damage the internal motor controller in brushless fans or cause reverse rotation in brushed variants.

Negative (-) pin (black): DC return connection, 0V reference. Connects to the negative terminal of the DC power supply and system ground. Current capacity must match fan specifications — typically 100mA to 2A depending on fan size and speed rating.

Positive (+) pin (red): DC supply connection, rated voltage input. Connects to the positive terminal of the DC power supply through switching circuitry. Voltage tolerance is typically ±10% of rated voltage. Exceeding voltage specifications may cause overspeed conditions and premature bearing failure.

Fan Pinout
image source: diyables.io

The fan operates on DC voltage matching its specification rating — 5V, 12V, or 24V are common variants. Voltage regulation within ±5% ensures optimal performance and longevity. Some advanced fans include additional pins for tachometer feedback (speed sensing) and PWM input (speed control), but basic cooling fans use the two-wire interface shown above.

Common wiring errors include reversed polarity (may damage brushless controllers), insufficient wire gauge for current capacity (causes voltage drop and overheating), and missing flyback protection (can damage switching components). The Arduino Giga R1 WiFi's 3.3V GPIO outputs cannot directly drive fan loads — relay interfacing provides the necessary isolation and current capacity.

How to Control Fan

DC fan control methods depend on the application requirements and desired performance characteristics. For simple on/off operation, relay switching provides complete electrical isolation and handles the full fan current without Arduino GPIO stress. For variable speed control, PWM drive circuits can modulate effective voltage to achieve proportional speed regulation.

Relay-Based Switching: When the relay coil is energized by the Arduino Giga R1 WiFi's digital output, the relay contacts close, connecting the fan to its DC power supply. The fan operates at full speed determined by the supply voltage. When the relay de-energizes, the contacts open, disconnecting power and stopping the fan. This method provides complete on/off control with electrical isolation.

PWM Speed Control: For variable speed operation, PWM signals can drive power MOSFETs or dedicated motor driver ICs to control effective voltage applied to the fan. Duty cycle modulation from 0-100% provides proportional speed control from stop to full speed. This advanced technique requires additional driver circuitry and will be covered in subsequent Arduino Giga R1 WiFi fan speed control tutorials.

The relay approach demonstrated in this tutorial offers several advantages: complete electrical isolation protects the Arduino from motor transients, full current capacity eliminates GPIO limitations, and reliable switching for continuous operation. Relay switching introduces minimal delay (typically 5-10ms) but provides robust operation for automation and thermal management applications.

To turn on/off a fan using the Arduino Giga R1 WiFi, relay interfacing is essential for safe operation. The Arduino controls the relay coil through a digital output pin, while the relay contacts switch the fan's power circuit. If you need detailed relay information including pinout specifications, operating principles, and programming techniques, refer to the comprehensive Arduino - Relay tutorial for complete implementation guidance.

The PWM method above does not need a custom driver circuit: a ready-made MOSFET module does the job. New to this module? The Arduino Giga R1 WiFi - MOSFET Module tutorial explains its pins and how it works.

Relay or MOSFET Module for a Fan?

Relay MOSFET Module
What you control ON and OFF only ON, OFF and fan speed (PWM)
Noise a click at every switch no sound
How fast it switches slow, a few milliseconds very fast
Life contacts wear out with use nothing moves, so it lasts long
Fan type AC or DC fans DC fans only
Fan supply any voltage within the relay rating 6V or more (the gate needs it)
Isolation yes, coil and contacts are apart yes, PC817 optocoupler
Good choice for AC fans and plain ON/OFF 12V DC fans with speed control

For the 12V DC fan in this guide, the MOSFET module is the better pick if you want a quiet fan that runs slower when the temperature is low. Keep the relay for an AC mains fan, or for a 5V fan, because the module needs at least about 6V on its load side.

Wiring Diagram

The wiring diagram demonstrates the complete electrical connection between the Arduino Giga R1 WiFi, relay module, and DC cooling fan. This configuration provides safe electrical isolation while enabling full digital control of fan operation through relay switching.

The wiring diagram between Arduino Fan

This image is created using Fritzing. Click to enlarge image

Electrical Note: The diagram above shows the minimum viable connection for Arduino Giga R1 WiFi fan control. For production or extended use, consider adding a flyback diode across the relay coil to suppress inductive kickback, and ensure adequate wire gauge for the fan current rating. The relay contacts should be rated for at least 125% of the fan's maximum current draw to prevent contact degradation over time.

Power supply considerations include maintaining voltage regulation within ±5% of the fan's rated voltage for optimal performance. Current consumption varies with fan size — typically 100-500mA for 12V desktop cooling fans. The Arduino Giga R1 WiFi's 3.3V digital outputs provide sufficient current (typically 8mA) to drive standard relay modules with built-in base resistors and transistor drivers.

Component Pin Arduino Giga R1 WiFi Pin Function
Relay VCC 5V Relay module power supply
Relay GND GND Common ground reference
Relay IN Digital Pin 7 Relay control signal
Fan Positive Relay NO Common Switched DC power supply positive
Fan Negative Power Supply GND DC power supply return
Power Supply Positive Relay NO External DC supply input
Power Supply Negative GND Common ground reference

Arduino Code

The following implementation demonstrates relay-based fan control using digital output switching. The code is structured to handle timed on/off operation with clear state indication through the serial monitor. Key sections include relay initialization, timing control, and status feedback for debugging and monitoring.

The implementation uses Arduino's built-in digitalWrite() function to control the relay state, which in turn switches the fan power circuit. The delay() function provides timing intervals, though more advanced applications might use millis() for non-blocking timing that allows concurrent sensor monitoring or communication tasks. The serial output enables real-time monitoring of fan state changes.

Each code section is explained with inline comments to clarify the relay control logic, timing sequences, and expected hardware behavior. The digitalWrite(HIGH) command energizes the relay coil, closing the contacts and powering the fan, while digitalWrite(LOW) de-energizes the relay, opening the contacts and stopping the fan operation.

The below code repeatedly turns the fan ON for five seconds and OFF for five seconds, demonstrating basic timed cooling operation suitable for applications like intermittent ventilation or thermal cycling tests:

/* * This Arduino Giga R1 WiFi code was developed by newbiely.com * * This Arduino Giga R1 WiFi code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-giga/arduino-giga-r1-wifi-controls-fan */ #define RELAY_PIN 3 // The Arduino Giga R1 WiFi 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 fan 5 seconds delay(5000); digitalWrite(RELAY_PIN, LOW); // turn off fan 5 seconds delay(5000); }

Detailed Instructions

Prerequisites: Arduino IDE installed and the Giga R1 WiFi board package configured. Refer to the Getting Started guide for setup instructions if needed.

  • Connect Hardware: Wire the relay module, DC fan, and power supply according to the wiring diagram. Verify all connections match the pin assignments — relay control to digital pin 7, power supply polarity, and proper grounding. The relay should click audibly when the Arduino powers up if wiring is correct.
  • Open Arduino IDE: Launch the Arduino IDE and select "Arduino Giga R1 WiFi" from the board menu. Ensure the correct COM port is selected under Tools > Port. The Arduino should appear as a recognized USB device when connected properly.
  • Upload Code: Copy the provided code into a new Arduino sketch. Click the Upload button to compile and transfer the program to the Arduino Giga R1 WiFi. The IDE should report "Upload complete" without errors. If compilation fails, verify the board package is properly installed.
  • Monitor Serial Output: Open the Serial Monitor (Tools > Serial Monitor) and set the baud rate to 9600. The monitor should display "Fan: ON" and "Fan: OFF" messages every five seconds, corresponding to the relay switching cycles. This confirms proper code execution and timing.
  • Verify Fan Operation: Observe the physical fan behavior during each cycle. The fan should start spinning when "Fan: ON" appears and stop when "Fan: OFF" is displayed. The relay module LED (if present) should also indicate the switching state. If the fan doesn't respond, check power supply voltage and relay contact ratings.
  • Test Relay Switching: Listen for the relay contact clicking sound during state changes. This confirms the Arduino Giga R1 WiFi is successfully controlling the relay coil. If no clicking occurs, verify the relay module wiring and the Arduino's 5V power output capability.

Technical Note: The 5-second timing intervals are implemented using blocking delay() functions, which halt all other Arduino processing during each delay period. For applications requiring concurrent sensor monitoring or communication, replace delay() with millis()-based non-blocking timing to maintain system responsiveness while controlling fan operation.

Code Explanation

Read the line-by-line explanation in comment lines of code!

Serial Monitor Output

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Giga R1
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Giga R1' on 'COM15')
New Line
9600 baud
Fan: ON Fan: OFF Fan: ON Fan: OFF Fan: ON Fan: OFF
Ln 11, Col 1
Arduino Giga R1 on COM15
2

Arduino Giga R1 WiFi Code - Fan Speed Control with MOSFET Module

Now let's swap the relay for a MOSFET module. The fan still turns on and off, but this time the Giga can also make it spin slow, medium or fast.

Wiring Diagram for the MOSFET Module

The wiring diagram between Arduino Giga R1 WiFi cooling fan MOSFET module

This image is created using Fritzing. Click to enlarge image

From To
Giga pin 2 module PWM pin
Giga GND module GND pin
12V adapter + (via DC power jack) module + terminal
Fan red wire (+) module + terminal (same terminal as the adapter +)
Fan black wire (−) module LOAD terminal
12V adapter − (via DC power jack) module − terminal

The fan motor has a coil, so add a flyback diode (1N4007 or 1N5819) across the fan wires. The end with the stripe (cathode) goes to fan +, the other end goes to fan −.

Code

The sketch below is the same one used in the MOSFET module tutorial. It drives pin 2 with PWM:

/* * This Arduino Giga R1 WiFi code was developed by newbiely.com * * This Arduino Giga R1 WiFi code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-giga/arduino-giga-r1-wifi-controls-fan */ const int MOSFET_PIN = 2; // Arduino Giga R1 WiFi 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); }

What you will see: the fan runs at full speed for 2 seconds and stops for 2 seconds. Then it speeds up step by step from 10% to 100%, and slows down again to 0%. At very low power, many fans do not spin at all. This is normal.

Detailed Instructions

  • Do the board setup the same way as in the relay Quick Steps above.
  • Wire the fan, the MOSFET module and the 12V adapter as shown in the diagram. Keep the adapter unplugged for now.
  • Upload the code to the Giga R1 WiFi, then plug in the 12V adapter.
  • Open the Serial Monitor at 9600 baud and watch the fan change its speed.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Giga R1
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Giga R1' 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 Giga R1 on COM15
2

Tip: the MOSFET module works with DC fans only, and its load supply must be about 6V or higher. For an AC fan, keep using the relay.

Application Ideas

Thermal Management System: Implement temperature-responsive cooling for electronics enclosures or server rooms. The Arduino Giga R1 WiFi's analog inputs can monitor temperature sensors, triggering fan operation when thermal thresholds are exceeded. The board's dual-core architecture enables simultaneous temperature monitoring and fan control with precise hysteresis implementation.

Automated Ventilation Controller: Create scheduled ventilation systems for greenhouses, tutorials, or storage areas. The Arduino Giga R1 WiFi's WiFi capability allows remote scheduling and monitoring, while multiple digital outputs can control several fan zones independently based on time schedules or environmental conditions.

Industrial Process Cooling: Deploy in manufacturing environments where equipment cooling follows production schedules. The Arduino Giga R1 WiFi's robust I/O can interface with industrial sensors and PLCs, providing integrated cooling control that scales with production demands and equipment thermal loads.

Data Logger Integration: Combine fan control with environmental data logging for HVAC performance analysis. The Arduino Giga R1 WiFi's expanded memory supports extensive data storage, while WiFi connectivity enables cloud-based monitoring and remote system diagnostics for predictive maintenance.

Smart Home Climate Control: Integrate with home automation systems for energy-efficient cooling. The Arduino Giga R1 WiFi can communicate with smart thermostats, occupancy sensors, and mobile apps to optimize fan operation based on room usage patterns and energy costs.

Laboratory Equipment Cooling: Control cooling fans for laboratory instruments that require precise thermal regulation. The Arduino Giga R1 WiFi's timing precision ensures accurate temperature cycling for analytical equipment, while serial communication provides integration with laboratory data acquisition systems.

Challenge Yourself

Challenge: Implement temperature-based fan control using a DHT22 sensor. Add hysteresis logic to prevent rapid on/off cycling around the threshold temperature, and include configurable temperature setpoints via serial commands.

Challenge: Create a multi-zone cooling system controlling three fans independently. Use different temperature sensors for each zone and implement priority-based cooling that activates the most critical zones first during high thermal load conditions.

Challenge: Add PWM speed control to create variable fan speed based on temperature differential. Replace the relay with a MOSFET driver circuit and implement proportional cooling that adjusts fan speed linearly with temperature above the baseline threshold.

Challenge: Develop a WiFi-enabled fan controller with web interface control. Use the Arduino Giga R1 WiFi's WiFi capabilities to create a web server that displays current fan status, allows remote on/off control, and provides historical runtime data for maintenance scheduling.

Challenge: Implement a smart cooling system that learns usage patterns and pre-emptively activates cooling based on predicted thermal loads. Store historical temperature and usage data in the Arduino's expanded memory, then use simple prediction algorithms to optimize cooling efficiency and energy consumption.

※ 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!