How to control a 24 volt LED strip using an ESP32 and ESPHome

For the smart Prusa enclosure project I’m working on, I’ve been looking at alternatives to control the two loads (fan and lighting) that will go in the Prusa MK4 enclosure.

One of the alternatives is to use a relay to drive the LEDs and fan, all controlled by an ESP32 device. I didn’t want to use a relay, and I still don’t (I will likely end up using a MOSFET module, since MOSFETs are silent, and relays are not). That said, I still had to try the relay option, just to learn how it works.

Come check it out here!

The reason you shouldnt ever use a relay for an led strip or a DC fan for that matter isnt because of the noise, thats a pretty insignificant problem overall and not to mention there are solid state relays(SSR) which are silent. A relay is only capable of turning something fully on 100% or fully off 0%. That severely limits the functionality of both a fan and the led’s becuase you cant control the speed of the fan or dim led’s if you use a relay. The fan will only be capable of turning On full speed and the led you actually have 2 problems and 1 of them is a major problem!

Led’s require PWM to drive them most of the time, unless they are constant current(CC) which yours dont appear to be so, you wont even be able to turn them on using a relay…

I admire the positive attitude and the fact that you seem esger and made yourself a whole blog to document the journey but, yikes man! You should probably figure out the bare minimum basics of what you’re trying to build before you create a blog and try to convince people to follow your project. You’re going to have people buying all the wrrong parts and wasting their time and money on lights they cant turn on and a fan that ony does 1 speed… We have a saying for when people do stuff like this. “Your’re putting the cart before the horse” and its not going to go very well. Slow down and do your proper due diligence and spend a little time understanding these components and how to operate tnem and dont be in a hurry, thats how you make silly mistakes.

Thanks for the feedback

Replies to your points:

  • The lights turn on just fine using the relay, contrary to your suggestion that this won’t work. You can see it on the video, it clearly works.
  • I only need the lights on or off, this is going to be a light so I can see prints at night remotely. Don’t care about varying intensity, this is not a vanity or décor LED.
  • The fan will only run at a single speed (on or off). A relay would be adequate for this.
  • The final enclosure will not use relays. It will use MOSFETs compatible with PWM. That has already been decided.
  • The post specifically notes the buyer should get a constant current LED strip. I have added a link to those words now, to an explainer of CC vs. CV.

I did in fact learn the basics enough that I pulled this off with near zero electronics knowledge (my background is in software engineering), and to know that a relay is not the ideal way to do this. In fact this is stated upfront in the blog post you read. It’s the product of dozens of hours of learning (reading, watching videos, experimenting) about a topic I knew next to nothing just a few days ago, and I am happy with how it turned out. :blush:

Fair enough THIS one isnt for decor but, why even consider using a relay for led’s that you cant dim and you cant change between cool and warm white? Having no functionality besides on/off may be ok for you and fair point. Where i kind of have an issue snd object is you’re putting it out there as a project for others to follow but they may want to use the led’s and fan to the fullest capabilities and i think its kind of low down dirty to mislead them even with the idea to use relays here.

Im glad your going with mosfets and maybe i misunderstood my initial speed glance of your blog but, i had the impression the mosfets were a consideration and not a final decision. Even if you wont necessarily need dimming or changing the cool/warm channels or even adjusting the fan speed. Its always better to have the options and not use them especially with the lights, theres a huge difference between cool white and warm white and not just its value as decor, but visibility and eye comfort. I would bet youll appreciate having that at some point.

Although i do have some minor objections to your project, which is just my opinion for whatever that’s worth. I do respect and appreciate the effort you made inorder to help others. Thats very cool and im sure it will be helpful to other people who follow in your footsteps.

1 Like

Because learning. As i stated before, the enclosure will use PWM-capable MOSFET boards. This will allow for derating the LEDs and therefore longer LED life.

It sounds like you already have your fets but, if it helps. I really like these and theyve served me well for years. I highly recommend them if you are ever looking for more.

How curious! FETs I bought are almost identical, just single channel ones.

It’s SO FRUSTRATING to find power handling parts that can be driven with 3.3 volt inputs!

Hey do i need a current limiting resistor on the GPIO if I use these FETs?

LEDs don’t ever require PWM to drive them. PWM is a cheap and simple way to make LED drivers that can give a varying output. But essentially, the LED is a device that can be driven with currents of many different levels.
On top of this, switching a relay is just PWM with very long pulses. Or PWM at 100 percent pulse width.

To be fair I tried “PWM” the relay just for shits and giggles, and is makes a HORRIBLE screech. Would not recommend.

Depending on how close components are and how you install things you could have used a 4 channel for everything. 1 channel for cool white, 1 for warm, and the third for the fan and youd have 1 extra for a future addition if you ever needed it.

True but it would not have fit in the corner of the enclosure due to it being too wide. Needs to fit in a trapezoidal volume whose narrowest part is less than an inch to look “stock”.

The LEDs I bought aren’t independent channel WW, they’re just “natural white”. Cheapo under desk lighting.

No, that is definitely not recommendable :rofl:

1 Like

Oh, was it just the option to choose a cool or warm led strip? Theres so flipping many led varieties out there now, its damn near a full time job keeping up with which have what features or bells and whistles.

My main criteria were (1) cheap (2) self-sticking (3) free delivery (4) no moar than 15 days wait.

I believe it. Relays definitely have a place and do serve a valuable purpose, just not here.

I went with led strips for my first led project which was my whole roofline! Talk aboit biting off more than you can chew! That was a project. Led strips are great untill you find yourself at a 90 degree bend, then they are a pain in the third leg! Just a friendly tip but, i tried these out for my under cabinet lighting and holy crap! Dealing with angles isnt a problem anymore!!

1 Like