Tutorial - How to control a PWM fan with an ESP32 and Home Assistant

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today I'm going to show you how to control a 12 volt pwm computer fan remotely with home assistant and an esp32 microcontroller [Music] this is an esp32 a small magical little micro controller that uses Wi-Fi or Bluetooth to do all kinds of fancy little weird things but wirelessly this is a four wire pwm 12 volt 120 millimeter computer fan it does fanny stuff like fan things that needs Fanning this is a standard 120 volt AC to 12 volt DC adapter that single-handedly unites Thomas Edison and Nikola Tesla in matrimony and finally this is a USB Buck converter that will take that scary 12 volt to DC current and calm it down to a nice USB friendly 5 volts that will power the esp32 while still giving us a 12 volt source to power our pwm van moving forward in effort to keep this as short as possible this tutorial is going to assume a basic understanding of electronics therefore simple components used to make electronic connections will not be verbally acknowledged but I will try to include them in the description down below also I'm kind of assuming that you already have home assistant and you already have ESP home installed on home assistant and that you are ready to jump right into the first step of this tutorial so go ahead and grab your esp32 and plug it into the computer running home assistant you will want to make sure that you're using a cable capable of data transfer and depending on your setup you might also have to pass through the USB device to the instance of your home assistant so once you have it plugged in go into home assistant navigate over to the ESP Home tab then on the bottom right hand of the screen click on new device then click continue from the pop-up next create an amazing and unique name for this new device now from this next screen you should see the esp32 at or near the top of the list of device options make sure there's a check mark next to use recommended settings and then click on esp32 the next screen will give you an option to install your encryption key and the configuration to the device click on install when it asks you how you want to install it select the option plug into the computer running ESP home dashboard if all goes well you should see your new setup pop as a USB to uart controller go ahead and click on it if you don't see it you probably didn't pass through the USB device or you need a better cable now the following screen might take a minute but it will show the compilation and upload of your new configuration to the esp32 allow it to complete the process and successfully connect your Wi-Fi you should see the status pop up on the screen once it's done AKA it stops moving around on the bottom right hand side of the screen click edit in the status screen go to the bottom underneath the line captive portal then copy and paste the following configuration you'll be able to find this code in the description of the video down below now this code is going to tell the esp32 to use one of the pins to read the RPM or the pulse width value of the pwm fan and another pin to tell the pwm fan what speed it should be at it does this by reading the pulse of the fan and math on its way to an accurate reading and then using a specific frequency to control the speed once you have copied and pasted everything click on install at the top right of the page again select plug into the computer running ESP home dashboard and then the USB to art controller you should see a familiar compile screen as it does its sorcery and uploads your new configuration after it's done and reconnected to Wi-Fi we can unplug it from the home assistant computer and start wiring our fan the first part of the wiring is going to be the 12 volt backbone that we need for our configuration because the pwm fan is 12 volts but the esp32 is 5 volts we want to use 12 volts to get the maximum speed out of the fan but we also want to use the same ground connection to power the esp32 to get this started first we have to know the pin out of the pwm fan connector so go ahead and grab the fan cable look at the connector and make sure that the side with the two little ridges are facing towards you and then make sure that you're holding the cable so it looks like this now the pin or the hole on the very far right of the connector is the negative connect that to the negative of the power supply the next pin to this is the positive connect that to the positive of your power supply and yes we are connecting this directly if you want to add in a switch that's completely up to you so at this point if you were to power it on your fan would run at full speed by default however with the sp32 we are going to read and control the speed of this fan to do this we need to connect the third pin on the connector to the third pin on the esp32 that's labeled D13 now this is important because the code that you copied and pasted specified that the D13 pin on the sp-32 is the pin that will read the pulse width of the spinning fan this is what tells you what your RPM or the speed of the fan is if you try to use a different pen without first reconfiguring your code it will not work correctly after that go ahead and take the fourth pin which is labeled D12 and connect that to the last pin connector that we have on the pwm fan connector this is the pin that will be used to send out the pwm frequency to the fan to tell it to go faster or slower so if everything looks right now we have to supply power to the esp32 but since the sp32 only runs on 5 volts we're going to use this Buck step down converter to take that 12 volts to a steady USB 5 volt now there's many ways to scan a cat here but this is the simplest way to show you how to power both devices from one power supply after connecting the 12 volt positive and the negative to the Bucks converter input side will get an easy use automatically regulated USB friendly 5 volt power supply now all we have to do is plug the esp32 into the other side of this Buck converter now I know you're eager but before we power this on let's do a little pre-flight check just to make sure we don't start any fires so first you have a 12 volt power supply with a positive and negative the negative will be connected directly to the first pin of the fan connector on the right hand side and the negative side of the buck converter's input then the positive side will be connected to the second pin of the fan connector and the positive input of the buck converter then you have the third pin on your fan connector connected to the pen labeled D13 on the esp32 and then the fourth pin of the fan connector connected to the pen labeled D12 on the esp32 and then finally you have the USB cable or an adapter coming out of the USB butt converter ran into the esp32 if everything looks good go ahead and plug in your power supply and head on over to home assistant after it finishes booting up you should see a notification in a home assistant that it has discovered a new ESP node and that you should be able to easily configure this new device if it doesn't pop up any kind of node configuration alert thing you might have to set up a new ESP home integration and manually specify the IP address so after getting all this added and you click on finish you should now see the new device screen that will probably not have any sensors or settings to configure but don't worry it's probably still just discovering everything that the esp32 is offering once it finishes that you should see a switch option pop up that allows you to turn the fan on or off and below that a pwm fan reading that tells you how fast it is going from here you can either turn it on or off or you can control the speed of the fan by clicking on the text pwm fan this will give you control all the way from 100 down to off depending on what fan you're using now the pwm fan speed control and readings are both new entities that you can use within home assistant in whatever application you have in mind although it's not covered here you can do things like turning the fan on or off or controlling the speed based off of a temperature value of a sensor that you can actually plug into the same esp32 device let me know in the comments down below if you want a tutorial for that as well well that's it for today's tutorial if you guys have any questions or comments make sure to leave those in the comments section down below as always thank you for watching like And subscribe and have yourself a great day
Info
Channel: Byte My Bits
Views: 47,690
Rating: undefined out of 5
Keywords: ESP32, Home Assistant, PWM, Fan, Computer fan, pc fan, wireless speed control
Id: 9-AZF6udg-Q
Channel Id: undefined
Length: 8min 17sec (497 seconds)
Published: Fri Jul 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.