Fan

Move air across to cool a embedded components.

Overview

The fan’s speed can be controlled with a PWM via its duty cycle.

Current

Fan’s motor draw more current than what a GPIO pin can normally provide. So an amplifier like a L2930 should be used to drive the fan.

Example

This can be done via GPIO pins.

Note: The PWM support is still iffy at best on the Raspberry Pi, and this must be run as root.

import (
    "log"
    "time"

    "periph.io/x/conn/v3/gpio"
    "periph.io/x/conn/v3/gpio/gpioreg"
    "periph.io/x/conn/v3/physic"
    "periph.io/x/host/v3"
)

// Start starts the Fan.
func Start(pin gpio.PinIO) {
    // Generate a 33% duty cycle 10KHz signal.
    if err := pin.PWM(gpio.DutyMax/3, 440*physic.Hertz); err != nil {
        log.Fatal(err)
    }
}

// Stop stops the Fan.
func Stop(pin gpio.PinIO) {
    if err := pin.Halt(); err != nil {
        log.Fatal(err)
    }
}

func main() {
    // Make sure periph is initialized.
    if _, err := host.Init(); err != nil {
        log.Fatal(err)
    }

    // Use gpioreg GPIO pin registry to find a GPIO pin by name.
    pin := gpioreg.ByName("GPIO6")

    // start the fan
    Start(pin)

    // stop the fan after 10 seconds
    time.Sleep(10*time.Second)
    Stop(pin)
}

Buying

The periph authors do not endorse any specific seller. These are only provided for your convenience.