Arduino ,bluetooth/pc and triac based speed control of ac home fan

Photo of author

By Jackson Taylor

Home » DIY Tech Projects » Arduino ,bluetooth/pc and triac based speed control of ac home fan

As an Amazon Associate we earn from qualifying purchases.

This project shows how to change the speed of an ordinary AC home fan with an Arduino, a TRIAC and a wireless or wired command source. You send a speed level from a phone over Bluetooth, or from a PC over the serial port, and the Arduino adjusts how much of each AC cycle reaches the fan. The video below demonstrates the build.

Safety first: this circuit connects to mains voltage, which can cause serious injury. Build and test it only if you are experienced with mains wiring, keep everything in an insulated enclosure, and never touch the board while it is plugged in. If you are new to this, practise the logic on the Arduino side first, with a low-voltage load such as a small lamp driven through proper isolation.

How the speed control works

A household fan motor does not need a special signal. It needs less average power to run slower. A TRIAC can provide that by switching on part-way through each half cycle of the AC wave. This method is called phase-angle control.

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video
  • If the TRIAC fires early in the half cycle, most of the wave reaches the fan and it runs fast.
  • If the TRIAC fires late, only a small slice of the wave gets through and the fan runs slow.
  • The TRIAC turns itself off when the current crosses zero, so the Arduino has to fire it again in every half cycle.

To fire at the right moment, the Arduino must know where each cycle starts. That is the job of the zero-cross detector.

Parts you will need

  • Arduino board (Uno or Nano are common choices).
  • TRIAC rated comfortably above the fan’s current and the mains voltage, mounted on a heat sink if the load is significant.
  • Optocoupler with a TRIAC output (the MOC30xx family is typical) to isolate the Arduino from the mains side.
  • Zero-cross detection circuit, usually a small step-down transformer or an optocoupler-based detector that gives the Arduino a pulse at every zero crossing.
  • Bluetooth module such as an HC-05 or HC-06 for phone control.
  • USB cable for PC control through the serial port.
  • Resistors, a snubber (a resistor and capacitor across the TRIAC), a fuse and an insulated enclosure.
See also
STEP CLIMBING ROBOT

Always check the datasheets for the exact parts you choose, since resistor values and pin layouts differ between components.

Circuit overview

Zero-cross detection

The zero-cross circuit gives the Arduino a pulse every time the AC wave passes through zero. You connect its output to an interrupt-capable pin, so the Arduino reacts immediately instead of polling. On a 50 Hz supply there are 100 zero crossings per second, and on 60 Hz there are 120.

TRIAC driver

An Arduino pin drives the LED inside the optocoupler through a current-limiting resistor. When that LED lights, the optocoupler triggers the gate of the TRIAC, which then conducts and powers the fan. The optocoupler keeps the low-voltage and mains sides electrically separate, which is why you should not skip it.

Bluetooth and PC link

Both the Bluetooth module and the USB connection talk to the Arduino as serial data. That means the same code can accept commands from a phone app or from a serial terminal on your PC. Remember to disconnect the Bluetooth module’s connection to the RX and TX pins while uploading code if your board shares those pins with USB.

How the Arduino code works

You do not need complex code, only a clear sequence:

  1. Detect a zero crossing through the interrupt.
  2. Wait for a delay that depends on the chosen speed level.
  3. Send a short pulse to the optocoupler to fire the TRIAC.
  4. Repeat for the next half cycle.

The delay can range from nearly zero (full speed) up to just under one half cycle, which is about 10 ms at 50 Hz or about 8.3 ms at 60 Hz (slowest speed). In practice, a fan stops turning well before the longest delay, so you pick a usable range by testing with your own fan.

In the main loop, the Arduino reads incoming serial characters. A simple scheme is to map digits to speed levels, for example 0 for off and 1 to 5 for increasing speed. Each received digit updates a variable that holds the firing delay. Keeping the command set small makes it easy to use from any Bluetooth terminal app or from the PC’s serial monitor.

See also
ARDUINO AND SERVO MOTOR INTERFACING SIMULATION IN PROTEUS

Controlling the fan from a phone or PC

For Bluetooth, pair the phone with the module and open a Bluetooth serial terminal app. Send the speed digit and the fan should respond almost immediately. You can also build a simple app with buttons for each speed.

For the PC, plug in the USB cable, open the serial monitor in the Arduino IDE (or any terminal program) at the baud rate set in your code, and type the same digits. If you want a nicer interface, you can write a small program that sends those characters when you move a slider.

Sustainable Tech

Keep Toxic E-Waste Out of Landfills

Don't throw away your failing laptop, phone, or car batteries. Learn how to recondition them at home in just a few hours. It's better for the planet—and your wallet.

Learn How It Works

Tips for better results

  • Check the fan type. Phase control works well with many common AC fans, but some motors hum or run roughly at low speeds. Fans that already use a capacitor and electronic regulator may behave differently.
  • Use a snubber. The RC snubber across the TRIAC helps with inductive loads such as motors.
  • Keep the code fast. Avoid long blocking delays in the interrupt routine, otherwise the timing drifts and the fan speed flickers.
  • Add a fuse on the live input and keep mains traces wide and well separated from the low-voltage side.
  • Start with a lamp. A bulb makes it easy to see whether the phase control works before you connect a motor.

Related projects

If you want the basics of phase control first, read our guide on power control using TRIAC and Arduino. For an approach without a microcontroller, see AC power control using TRIAC and DIAC.

If you prefer Wi-Fi to Bluetooth, the Wi-Fi controlled fan and light project covers that route. You can also read about home automation using Android mobile to control more appliances from one phone app, or look at speed control of an AC motor if you also need to reverse direction.

Frequently asked questions

Why do I need zero-cross detection?

The Arduino has to fire the TRIAC at a precise moment after each zero crossing. Without that reference point, the firing time would not be tied to the AC wave and the fan speed would be unstable.

See also
SCADA WITH ARDUINO OR ENERGIA

Can I use a relay instead of a TRIAC?

A relay only switches the fan fully on or off, so it cannot vary the speed smoothly. A TRIAC with phase control can. Relays are fine if you only want on and off control.

Will this work with any AC fan?

It works with many simple AC fans, but results vary by motor type. Test with your own fan, and expect some motors to make a slight hum at low speed settings.

Can I control the fan from both a phone and a PC?

Yes. Both the Bluetooth module and the USB connection deliver serial data, so the same commands work from either one. Just make sure only one source sends data at a time.

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works