GithubHelp home page GithubHelp logo

esp32-fan-controller's Introduction

Build

ESP32 fan controller with MQTT support

This project describes how to use an ESP32 microcontroller for controlling a 4 pin fan (pwm controlled fan). Main features are:

  • mode 1 (fan mode or pwm mode): directly setting fan speed via pwm signal

  • mode 2 (climate mode or temperature controller mode): fan speed automatically increases if temperature is getting close to or higher than target temperature. Of course temperature can never get lower than air temperature of room.

  • measurement of fan speed via tacho signal

  • measurement of ambient values via BME280: temperature, humidity, pressure

  • support of MQTT

  • support of OTA (over the air updates of firmware). Please see Wiki: 07 OTA Over the air updates

  • TFT display for showing status information, different resolutions supported (tested with 320x240 and 160x128)

  • TFT touch display for setting pwm or target temperature

  • optional: integration into home automation software Home Assistant (with MQTT discovery) or openHAB.

Even if you don't want to use all of these features, the project can hopefully easily be simplified or extended. With some minor modifications an ESP8266 / D1 mini should be usable.

I did this project for having an automatic temperature controller for my 3D printer housing. But of course at least the ideas used here could be used for many other purposes.

For more information please see the Wiki

Integration in Home Assistant

With mqtt discovery, you can integrate the fan controller with almost no effort in Home Assistant.

Please see Wiki: 05 Home Assistant

Operation modes

You can operate the ESP32 fan controller mainly in two different modes, depending on your needs:

mode description how to set PWM how to set actual temperature how to set target temperature
fan mode fan speed directly set via PWM signal MQTT, touch or both BME280 (optional, only used for information)
climate mode automatic temperature control
fan speed is automatically set depending on difference between target temperature and actual temperature
MQTT or BME280 MQTT, touch or both

In both modes, a TFT panel can optionally be used for showing status information from the fan, ambient (BME280: temperature, humidity, pressure) and the chosen target temperature. Different resolutions of the TFT panel are supported, layout will automatically be adapted (tested with 320x240 and 160x128).

If you use a TFT touch panel, you can set the PWM value or target temperature via the touch panel (otherwise you have to use MQTT).

For more information please see the Wiki: 03 Examples - operation modes and breadboards

Wiring diagram for fan and BME280

Wiring diagram fan and BME280

For more information please see the Wiki: 01 Wiring diagram

Part list

Function Parts Remarks approx. price
mandatory
microcontroller ESP32 e.g. from AZ-Delivery 8 EUR
fan 4 pin fan (4 pin means pwm controlled), 5V or 12V tested with a standard CPU fan and a Noctua NF-F12 PWM
for a list of premium fans see https://noctua.at/en/products/fan
20 EUR for Noctua
measuring tacho signal of fan - pullup resistor 10 kΩ
- RC circuit: resistor 3.3 kΩ; ceramic capacitor 100 pF
power supply - 5V for ESP32, 5V or 12V for fan (depending on fan)
or
-12V when using AZ-touch (see below)
e.g. with 5.5×2.5 mm coaxial power connector 12 EUR
optional
temperature sensor - BME280
- 2 pullup resistors 3.3 kΩ (for I2C)
e.g. from AZ-Delivery 6.50 EUR
optional
TFT display (non touch) 1.8 inch 160x128, ST7735 e.g. from AZ-Delivery 6.80 EUR
TFT touch display with ESP32 housing AZ-touch from AZ delivery
including voltage regulator and TFT touch display (2.8 inch 320x240, ILI9341, XPT2046)
e.g. from AZ-Delivery
(you can also use the older 2.4 inch ArduiTouch)
30 EUR
connectors for detaching parts from AZ-touch - e.g. 5.5×2.5 mm coaxial power connector male
- JST-XH 2.54 mm for BME280
- included extra cables and connectors in case of Noctua fan

Other TFTs can most likely easily be used, as long as there is a library from Adafruit for it. If resolution is smaller than 160x128 it might be necessary to change the code in file tft.cpp. Anything bigger should automatically be rearranged. If you want to use touch, your TFT should have the XPT2046 chip to use it without any code change.

Software installation

If you're only used to the Arduino IDE, I highly recommend having a look at PlatformIO IDE.

While the Arduino IDE is sufficient for flashing, it is not very comfortable for software development. There is no syntax highlighting and no autocompletion. All the needed libraries have to be installed manually, and you will sooner or later run into trouble with different versions of the same library.

This cannot happen with PlatformIO. All libraries will automatically be installed into the project folder and cannot influence other projects.

If you absolutely want to use the Arduino IDE, please have look at the file "platformio.ini" for the libraries needed.

For installing PlatformIO IDE, follow this guide. It is as simple as:

  • install VSCode (Visual Studio Code)
  • install PlatformIO as an VSCode extension
  • clone this repository or download it
  • use "open folder" in VSCode to open this repository
  • check settings in "config.h"
  • upload to ESP32

Images

ArduiTouch running in "climate mode"

TempControllerModeArduiTouch

Images of ESP32 fan controller used in a 3D printer housing

3DPrinter

For more information please see the Wiki: 04 AZ‐touch / ArduiTouch

esp32-fan-controller's People

Contributors

ffa95 avatar klausmu avatar nhangeland avatar s4saken avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp32-fan-controller's Issues

updates, project.

Hi Klaus,

I see your very busy making this great. Thanks man for all the effort.
I got a new touch display and its working great again.

I managed to setup new pwm channels to.
Because i have 2 fans for my case. I wanted to create a positive pressure for in/out. So i got this working on a second temp control, but with an offset. Kinda great.

The second channel i use for a build in filter, for when i dont need any temp control.
Also bought a 2 channel relais module. Gonna create 2 switches for light and case power.
I am gonna add the mqtt discovery messages for these also.

All and all, very nice project, nice base and just a very good smart device.

Testing the new updates right now.

Kind Regards,

Fan never stops

Here is a problem, when temperature falling below target point fan never stops.

Multiple fan support?

Hi,

I'm thinking about using this for a PV inverter that has no active cooling but gets pretty hot. For that I'd like to control 4 fans that should spin up when the temperature sensor gets high values. That sensor I'd like to attach to the heatsink of the inverter.
Does this sound doable to you with your project?

Thank you

esp8266 setup

I'm trying to get the d1 mini to work with this, since the guide mentioned it could be done with minor modifications. I'm only getting a lot of compilation errors and I haven't got much succes with it.

No level shifter?

I see there is no level shifter from 3.3 to 5v for the PWM line. I thought pwm needed to run 5v minimum?

How to connect three fans

Hi,
Is it possible to connect three fans to this scheme?
The three fans must be controlled all together (for example, if I set the speed to 50% with PWM, all three will go to 50%), if the temperature exceeds a certain threshold, the three fans must start and must adapt the speed based on the thresholds that I set.

I am able to make changes to the software, but for the electrical scheme I need help.

Thanks

Switch between sensor source? Temp <> Humidity

Hello Klaus,
thank you for offering that code. Is there a possibility to add function to switch between sensor source? Means PWM control based on temperature or humidity values? Maybe with a slider to change between source?

Regards,
Daniel.

Compilation Error

Hi,

I got a compilation error on my board.
I didn't know if the problem is my board, or if i'm missing something.

src/wifiCommunication.cpp:126:70: error: no matching function for call to 'WiFiClass::onEvent(void (&)(arduino_event_id_t, arduino_event_info_t), system_event_id_t)'
   WiFi.onEvent(WiFiStationDisconnected, SYSTEM_EVENT_STA_DISCONNECTED);
                                                                      ^

src/wifiCommunication.cpp:155:64: error: no matching function for call to 'WiFiClass::onEvent(void (&)(arduino_event_id_t, arduino_event_info_t), system_event_id_t)'
   WiFi.onEvent(WiFiStationConnected, SYSTEM_EVENT_STA_CONNECTED);
                                                                ^
src/wifiCommunication.cpp:156:50: error: no matching function for call to 'WiFiClass::onEvent(void (&)(arduino_event_id_t, arduino_event_info_t), system_event_id_t)'
   WiFi.onEvent(WiFiGotIP, SYSTEM_EVENT_STA_GOT_IP);
                                                  ^
src/wifiCommunication.cpp:157:70: error: no matching function for call to 'WiFiClass::onEvent(void (&)(arduino_event_id_t, arduino_event_info_t), system_event_id_t)'
   WiFi.onEvent(WiFiStationDisconnected, SYSTEM_EVENT_STA_DISCONNECTED);
                                                                      ^


Any idea how to fix this?
Best regads,
Adrian

Strange behaviour with 2.8 inch touch display

i've installed the software on an AZ-Touch. So far everything works as expected except the touch diplay component. When compiling the code (via PlatformIO) using the option '#define climate_controlledByBME_targetByMQTTandTouch' in config.h the following happens:

  • the display stays dark after an esp32 boot.
  • once a mqtt command is submitted the display lights up with its expected content
    (so in general there seems no hardware / wiring issue)
  • the target temperature cannot be changed (meaning the display does not react to a touch at the +/- buttons)
  • the only touch action working is to toggle the display on/off when touching the lower left area of the display
  • when the display lights up the fans stop

Any idea how to fix this?

DS18B20 Temperature probe

It would be nice to also have the DS18B20 (1-wire) temperature sensor since you can have multiple sensors in the same IO pin you would be able to have a temperature sensor for each Fan and an ambient temperature sensor.

discovery issue

Hi, Great project, thanks for all the work. I am building a great 3d printer enclosure with this.

Small Problem:
After restarting a mqtt client (in my case, ha), the entity is not available until i restart the unit and it republishes via mqtt.

Do you think its possible to add retain on the mqtt messages, so restarting is not necessary?

Question re pullup resistors

Question for you. Is there a reason why are you using pull-up resistors when the esp32 has built-in pull-up resistors?

support for 2 fans

I'm looking at using your code to control fans inside a rack mount enclosure and would it be possible to control 2 fans?

Thanks

incorrect data

Hi
thanks for sharing the code, I've tried to use your code and pair of two PNP proximity sensors to measure 2 motor speeds, but I find if I decrease the tachoUpdateCycle time , it shows the incorrect speeds,
I was thinking it may be a better idea to use a time span between the pulses instead of counting the pulses

LCD Display 20x4

Hi Klaus,
Thank you so much for this great project, it works perfectly! For the moment it's on the breadboard but I will make the circuit soon.
I have a spare 20x4 LCD display that can be driven by I2C, I would like to use it to print the temp, humidity and fan speed values.
I tried to look into it but it's above my coding capability, do you have any suggestion or anything in your to-do list?
Thank you in advance for your help and keep up the good work!

Cheers,
G

Betrieb mit 24v 3-Pin Lüfter

Servus Klaus,

meinst du es wäre möglich die Schaltung soweit umzubauen, dass man das Projekt auch mit einem 24V 3-Pin Lüfter nutzen könnte? Ich habe die Herausforderung einer dezentralen Lüftungsanlage die ziemlich dumm ist und auch gerne mal Funkaussetzer hat. Jetzt war die Überlegung ob ich sie selbst Smart bekommen kann. 24V DC bekomme ich von der originalen Platine abgegriffen, den ESP32 könnte man per StepDown Driver versorgen.

Grüße Sebastian

Question: Using this in an already existing circuit

Hi there.
Can I use this project in an already existing circuit, that has a PWM fan? I don't want to control the PWM, I only want to spy on the tacho pin and read the current RPM.

If I add the RC and the pullup resistor, could that mess up anything on the existing circuit readouts?

Device Goes Offline and Stops Climate Control

Hi Klaus,

Thanks for all the effort you've put into this project. I followed your excellent guide and got everything up and running.

My setup has the BME, makes use of MQTT (with authentication) and has no touch screen. I'm using an ESP32 DevKitC V4 - (ESP32-WROOM-32U) and I updated the source code to use the appropriate pins for that board.

Everything works great off a fresh boot. However, the system can't seem to sustain its sanity for more than about a day. MQTT topics go dark and the fan seems to hold onto it's minimum rpm and not budge from there in response to the changing ambient temperature. A reboot makes everything good again. For a while.

I realize the above might be hard to reproduce, but do you have any idea where it might be falling off the rails or while the failure seems to be wholesale? I wouldn't mind so much if it lost connectivity to the MQTT server but continued to manage the fan.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.