All-in-one RGBW LEDs Controller With Temperature and PIR Sensors!

by Giovanni Aggiustatutto in Circuits > LEDs

7992 Views, 121 Favorites, 0 Comments

All-in-one RGBW LEDs Controller With Temperature and PIR Sensors!

Video ITA 00_00_30.39.jpg
Video ITA 00_11_01.45.jpg
Video ITA 00_00_52.33.jpg
Video ITA 00_00_53.49.jpg
Costava 100€ e l'ho costruito con 5€! Controller strisce LED RGBW con sensori PIR e Temperatura!

Hi, I am Giovanni Aggiustatutto and welcome to this Instructable! In this guide I will show you how I built a very cheap WiFi RGBW LEDs controller that also includes PIR motion sensors, a temperature sensor and a light sensor. Recently I decide to put some RGBW LED strips on my wardrobe to create a cool lighting effect on the ceiling of my room. After looking online for an LEDs controller that could be connected to Home Assistant and seeing that the average ones cost around 30€, I thought: "I can make this way cheaper!". From this idea, I started searching the right components for my project, and thought that also having some PIR motion sensors to turn the LEDs on automatically would have been pretty cool. Still, smart motion sensors are quite expensive, and run on batteries, which is something I tend to avoid whenever I can. So, why not add PIR sensors directly to the LEDs controller? And, while I was at it, why not also add a temperature sensor, and maybe a light sensor? This way, I could have all the sensors needed to automate an entire room for very cheap, something like 10€ for everything. These sensors can then be used in Home Assistant automations, for example using the motion sensors I created one to automatically turn on the LED strip as soon as I enter the room, setting a different brightness based on the time of day. Obviously for automations the limit is imagination, but in the meantime, let's get started!

As always, I’ve also made a video about this project, that you can find on my YouTube channel (it has English subtitles).

Supplies

Video ITA 00_11_17.68.jpg
Video ITA 00_02_30.98.jpg
Video ITA 00_07_38.26.jpg
Video ITA 00_08_46.99.jpg

To make this project I used:

  1. ESP32 Wemos D1 mini board (link here)
  2. 12V common-positive RGBW LED strip (link here)
  3. 12V 50W power supply for the LEDs (link here)
  4. 4 AOD4184 mosfet modules (link here)
  5. 2 HC-SR602 PIR motion sensors (link here)
  6. SHT31 temperature and humidity sensor (link here)
  7. BH1750 illuminance sensor (link here)
  8. Mini560 5V step-down voltage regulator (link here)
  9. A piece of perfboard (link here)
  10. 24 AWG wire with silicone sheating
  11. Solid copper wire
  12. 4-core 26 AWG cable (link here)
  13. 2-core 18 AWG cable (link here)
  14. PCB male and female jumper 2.54 mm connectors (link here)
  15. two 4-pin, two 3-pin, one 2-pin and one 5-pin JST XH 2.54 mm PCB connector with female connector (JST connector kit: link here)
  16. 4 M3 brass threaded inserts (link here)
  17. 4 M3 10 mm-long bolts (link here)

Tools:

  1. Soldering iron
  2. Hot glue
  3. JST connector crimping tool (link here)
  4. 3D printer with white PLA
  5. Screwdrivers, pliers and other basic tools

Controlling LED Strips

00_34.48.jpg
Video ITA 00_02_24.34.jpg
Video ITA 00_03_20.02.jpg
Video ITA 00_05_20.18.jpg

This project starts from an LED strip, that will be put on to of my wardrobe. I chose a 12V RGBW LED strip, which in addition to all RGB colors can make a good warm white light thanks to the fact that it has dedicated white LEDs in addition to the RGB ones (in normal RGB LED strips, white light is made by turning the three R, G and B channels on, resulting in an ugly light with a blue tint). This kind of LED strip works by connecting a common positive to 12V and giving the negative to the red, green, blue and white channels to create the different colors or have a warm white light. Along with the LED strip I also bought a 12V power supply, so the only thing left is to prepare the controller that will enable us to control the LEDs from Home Assistant via WiFi.

The controller for the LED strip must be able to control in PWM four 12V outputs for the four channels of the LED strip. In order to do this I bought on Aliexpress four modules that have AOD4184 mosfets mounted on them. The mosfets will allow us to control the LEDs, which consume several amps, from the pins of a microcontroller that can be an Arduino or an ESP32/ESP8266. The mosfet modules also have an optoisolator, which allows us to control the mosfets from the 3.3V pins of a microcontroller while achieving maximum efficiency.

The mosfets will be connected to the pins of an ESP32 board. This board can connect to WiFi, which makes it a perfect choice for smart home project. Using the WiFi connection, we will be able to connect the ESP32 to Home Assistant, and use it to control the LED strips from our smart phone.

Mosfet Connections

Video ITA 00_03_42.03.jpg
Video ITA 00_03_50.78.jpg
Video ITA 00_04_22.34.jpg
Video ITA 00_04_10.94.jpg

The PCBs with the mosfets have three terminals on one side for positive and negative of the power supply and for the load, and on the other side they have GND and a PWM input that can be connected to a pin of the microcontroller. The four mosfet modules will be connected with positive and negative of the 12V power supply as well as the GND of the PWM input in common. If I put the boards flat next to one another, these connections on their own would have created a huge mess of wires.

So, to make the connections between the mosfets, I 3D printed a holder to keep the PCBs vertical. With 24 AWG wire from which I removed the sheathing, I connected the positive, negative, and GND of all the boards. The wires go straight from the hole of one PCB to the hole of the next one, and are soldered to the pads. By mounting the boards in this way, I was able to keep the wires a lot neater, and also improve the cooling of the mosfets, which now have air on both sides of the board.

At this point I connected short cables to the PWM input of each board, as well as one cable to the common GND. These cables will be connected to the pins of the ESP32, that will create the PWM signal to dim the LEDs.

Then I moved on to the power part, and connected the four channels of the LED strip to the 4 mosfet outputs, using the connector that was included with the LED strip. To connect the power supply, I cut a piece of two-pin cable, which I connected to the positive and negative screw terminals of the power supply on one side and to the positive and negative inputs of the mosfets (+ and -) on the other side. To the positive from the power supply I also connected the common positive of the LED strip, which counter intuitively is the black wire on the connector.

PIR Motion Sensors

Video ITA 00_06_32.28.jpg
Video ITA 00_06_47.82.jpg
Video ITA 00_06_49.36.jpg
Video ITA 00_07_16.00.jpg

As I said before, the RGBW controller that I'm building will also have some sensors connected to it. The first sensor I worked on is the motion sensor. First I designed and 3D printed a case in which to mount it. The case is composed of a base, a lid that has a hole for the sensor and a stand, which is secured to the base with a ball joint. The stand comes in two versions: one to put the sensor on a table and one to secure it onto a closet or any other furniture. The ball joint allows us to find the perfect orientation for the sensor once it is already mounted in its final spot.

To connect the sensor to the ESP32, I decided to use a four-pin 26 AWG cable, that I cut to the lenght that will be needed to go from the main controller to the spot I want to put the sensor in. The sensor actually requires three wires, but I chose a four-core cable because the next sensors we are going to build need four pins; if you have it, you can of course use some three-core cable. I routed the cable through the hole in the base. Then, I soldered three wires of cable to negative, positive and output of the motion sensor. I glued the sensor at the centre of the base with hot glue, and put the lid on top of the base; the lid secures to the base with some snap features that I added to the design. As I said before, the mount is secured to the sensor with a ball joint, which simply snaps in place.

Lastly, I crimped a three-pin JST connector to the end of the cable, using a JST crimping tool.

Finally, our sensor is ready. To cover my entire room, I made two motion sensors, that are going to be placed in two different spots.

Temperature and Light Sensors

Video ITA 00_07_46.49.jpg
Video ITA 00_00_53.49.jpg
Video ITA 00_08_00.48.jpg
Video ITA 00_08_33.04.jpg

Now that the motion sensor is ready I moved on to the temperature sensor. For this purpose I chose the SHT31 temperature sensor, which is very accurate, in addition to temperature can also measure humidity, and communicates with the microcontroller using the i2c protocol. This sensor is also extremely compact, just consider that the actual sensor is that little black square just 2.5 millimeters wide.

As I did for the PIR sensor, also for the temperature sensor I cut a piece of four-core cable. If for the PIR sensor you can use any cable length that you want, for the temperature sensor you are limited to about 1.5 meters of cable, as the i2c signal does not work with longer cables. I soldered the four wires of the cable to the positive, negative, SCL and SDA pins of the sensor. As before, I connected a JST connector at the end of the cable, this time using a four-pin connector.

In my installation, the sensor will be hidden in the space between the wall and the edge of a cabinet, so to keep it as compact as possible I did not make a 3D-printed enclosure for it.

Now we are left with the light sensor. To be fair, among all the sensor this is the lest useful one, and I haven't found a use for it yet. Anyway, I went with a BH1750 light sensor, that like the temperature sensor works with the i2c protocol. The connections are the same as for the temperature sensor, and as the temperature sensor, also the light sensor got a four-pin JST connector at the end of the cable.

Main Circuit Board

Video ITA 00_09_59.23.jpg
Video ITA 00_09_18.07.jpg
Video ITA 00_09_16.72.jpg
Video ITA 00_09_52.54.jpg

Now that we have all the sensors as well as the mosfets we need to make the circuit with the ESP32 board to which they will be connected. First I cut a 55x70 mm piece of perfboard. Then I soldered some male jumper connectors to the ESP32 board; with female jumper connectors, I soldered the ESP32 board on the perfboard. On the board I also soldered some JST connectors: two four-pins connectors for the temperature and light sensors, two three-pins connectors for the two motion sensors, one five-pin connector for connecting the mosfets that control the LEDs and a two-pins one for powering the board with 5V.

The connections between the components are very simple. All sensors receive ground and 3.3V power supply from the ESP32; the ESP32 receives ground and 5V from the power connector on the board. The two motion sensors have a digital output (it can only be 3.3V or 0V), which I connected directly to pins 16 and 17 of the ESP32. The temperature and brightness sensors use the i2c protocol, which needs two pins for SDA and SCL. As each sensor has a different address, these pins can be shared between multiple sensors. So, the SDA and SCL of both the temperature and light sensors are connected to pins 21 and 22. On these pins I also added two 2.2k Ohm resistors connected to 3.3V. The four pins of the mosfets are connected directly to the ESP32 pins 26 for red channel, 18 for green, 19 for blue and 23 for white. The mosfets also get a pin for GND. As you have seen, the connection are quite simple, and if you want to replicate this project you can find the wiring diagram attached below.

Following the wiring diagram, and with a lot of patience, I made the connections under the board. For the connections I used some stiff copper wire to make some traces and wires with silicone sheathing for the intersecting traces.

If you prefer, instead of making the circuit board by hand you can design a simple PCB for this project and have it manufactured.

Downloads

Final Assembly

Video ITA 00_11_17.68.jpg
Video ITA 00_10_47.05.jpg
Video ITA 00_11_23.92.jpg
Video ITA 00_11_06.26.jpg

Now that the main board is ready, I designed and 3D printed an enclosure to install all the components. The enclosure is very simple and is only composed of a box and a lid. The box has four holes in which I put some M3 threaded inserts, heating them using a soldering iron; these threaded inserts will be used to close the box with screws.

Before mounting everything in the enclosure we need to make the last connections. First, I installed a five-pin JST connector on the wires coming from the mosfets. Using this connector, I connected them to the board. Then we need a way of powering the ESP32, that needs 5V on the input, from the 12V power supply that will power the LEDs. For this purpose, I used a small 5V voltage regulator. Using some wires, I connected the input of the regulator to the 12V wires coming from the power supply, and the output of the regulator to the 5V connector on the main board, using a two-pins JST connector.

Now, I could finally mount the main board, the mosfets and the voltage regulator in the 3D printed box. For installing the mosfets, I designed some slots on the base of the enclosure. The board and the mosfets are then secured with hot glue. At this point, after connecting the wires coming from the sensors to the connectors on the main board, I could close the lid with some M3 screws.

Downloads

Connecting the ESP32 to Home Assistant

Video ITA 00_10_58.99.jpg
Video ITA 00_00_30.39.jpg
Video ITA 00_00_53.49.jpg

Before testing the circuit, we need to program the ESP32 so that it can be connected to Home Assistant. After the ESP32 is configured, we will be able to control the LEDs from Home Assistant and read the data from the sensors. Home Assistant will also allow us to create automations using the data from the sensors and the LEDs; for example, I made one that turns the LED strip on as soon as I enter the room.

Home Assistant is a very powerful open-source platform with which we can manage all of our smart devices from a single interface. Home Assistant works in our local network, so we need a device to run it: we can use a Raspberry Pi or, like I do, an old Windows PC with Home Assistant running on a virtual machine. To access the interface you can log into the webpage from a computer or download the Home Assistant app on your smartphone. To connect to my Home Assistant from outside the local network I'm using the Nabu Casa Cloud, which is the simplest and safest solution but it's not free. There are other solutions but they are not totally safe, so I would use them only if you know really well what you are doing.

To connect the ESP32 to Home Assistant we will use ESPHome. ESPHome is an really well-made add-on that allows us to connect ESP32 and ESP8266 boards to Home Assistant via WiFi. To connect the ESP8266 to ESPHome you can follow these steps:

  1. Install the ESPHome plugin in Home Assistant
  2. On ESPHome's dashboard, click on +NEW DEVICE
  3. Give your device a name (in my case it was "RGBW all-in-one controller")
  4. Once you are prompted to install the firmware onto your device, select SKIP THIS STEP: we will install the firmware later
  5. Select ESP32 and click NEXT
  6. Copy the encryption key that is given, we will need it later
  7. Once again, skip the installation of the firmware on the ESP32
  8. Once the device appears in the ESPHome dashboard, click on EDIT to see the device's code
  9. Under wifi, insert your wifi ssid and password:
wifi:
‏‏‎ ‎ ssid: your_wifi_ssid
‏‏‎ ‎ password: your_wifi_password


  1. To make the connection more stable, I strongly recommend setting a static IP address for the ESP32, with this code (to copy the code, use this link: https://pastebin.com/UT05D03L):
wifi:
‏‏‎ ‎ ssid: your_wifi_ssid
‏‏‎ ‎ password: your_wifi_password

manual_ip:
‏‏‎ ‎ # Set this to the IP of the ESP
‏‏‎ ‎ static_ip: 192.168.1.96
‏‏‎ ‎ # Set this to the IP address of the router. Often ends with .1
‏‏‎ ‎ gateway: 192.168.1.1
‏‏‎ ‎ # The subnet of the network. 255.255.255.0 works for most home networks.
‏‏‎ ‎ subnet: 255.255.255.0


  1. At the end of the code given by ESPHome, paste the one you can find at this link: https://pastebin.com/eBjikDpw
output:
‏‏‎ ‎ - platform: ledc
‏‏‎ ‎ ‏‏‎ ‎ pin: 26
‏‏‎ ‎ ‏‏‎ ‎ id: red_output

‏‏‎ ‎ - platform: ledc
‏‏‎ ‎ ‏‏‎ ‎ pin: 18
‏‏‎ ‎ ‏‏‎ ‎ id: green_output

‏‏‎ ‎ - platform: ledc
‏‏‎ ‎ ‏‏‎ ‎ pin: 19
‏‏‎ ‎ ‏‏‎ ‎ id: blue_output

‏‏‎ ‎ - platform: ledc
‏‏‎ ‎ ‏‏‎ ‎ pin: 23
‏‏‎ ‎ ‏‏‎ ‎ id: white_output

‏‏‎light:
‏‏‎ ‎ - platform: rgbw
‏‏‎ ‎ ‏‏‎ ‎ name: "LED strip"
‏‏‎ ‎ ‏‏‎ ‎ red: red_output
‏‏‎ ‎ ‏‏‎ ‎ green: green_output
‏‏‎ ‎ ‏‏‎ ‎ blue: blue_output
‏‏‎ ‎ ‏‏‎ ‎ white: white_output
‏‏‎ ‎ ‏‏‎ ‎ color_interlock: true

i2c:
‏‏‎ ‎ sda: GPIO21
‏‏‎ ‎ scl: GPIO22
‏‏‎ ‎ scan: true

sensor:
‏‏‎ ‎ - platform: sht3xd
‏‏‎ ‎ ‏‏‎ ‎ temperature:
‏‏‎ ‎ ‏‏‎ ‎ name: "Temperature"
‏‏‎ ‎ ‏‏‎ ‎ humidity:
‏‏‎ ‎ ‏‏‎ ‎ name: "Humidity"
‏‏‎ ‎ ‏‏‎ ‎ address: 0x44
‏‏‎ ‎ ‏‏‎ ‎ update_interval: 5s

‏‏‎ ‎ - platform: bh1750
‏‏‎ ‎ ‏‏‎ ‎ name: "Illuminance"
‏‏‎ ‎ ‏‏‎ ‎ address: 0x23
‏‏‎ ‎ ‏‏‎ ‎ update_interval: 5s

binary_sensor:
‏‏‎ ‎ - platform: gpio
‏‏‎ ‎ ‏‏‎ ‎ pin: 16
‏‏‎ ‎ ‏‏‎ ‎ name: "Motion 1"
‏‏‎ ‎ ‏‏‎ ‎ device_class: motion

‏‏‎ ‎ - platform: gpio
‏‏‎ ‎ ‏‏‎ ‎ pin: 17
‏‏‎ ‎ ‏‏‎ ‎ name: "Motion 2"
‏‏‎ ‎ ‏‏‎ ‎ device_class: motion


  1. In the end, your code should look like the one you can find at this link (but don't copy this code directly into the ESPHome configuration).


Note: don't paste the code written above in the black rectangles directly into the ESPHome configuration, as it doesn't have the right indentation; please follow the links to open the properly formatted and ready to be copied code.

Installing the LED Strips

Video ITA 00_00_20.12.jpg
Video ITA 00_11_55.18.jpg
Video ITA 00_11_57.45.jpg
Video ITA 00_11_44.64.jpg

The last step before completing the project is installing the LED strips on top of the wardrobe. As the wardrobe is very tall, nobody will ever see the LED strip, but only the light that gets reflected on the ceiling, so I didn't care too much about making a "clean" install. In order to install the LED strip, I used some 30x2 mm aluminum profiles. After taking all the needed measurements, I cut the profiles to size so that they could follow the shape of the wardrobe. I glued the LED strip onto the aluminum profiles, using a simple 3D-printed jig to keep it centered. Lastly, I connected each segment of LEDs to the next one, using some short pieces of wire. To prevent short circuits between the pads of the LED strip and the aluminum profile, I protected the soldered connections with some heat shrink tubing. I decided aluminum profiles for mounting the LEDs instead of sticking them directly to the wardrobe because this way they have a much better cooling and will consequently last longer.

Final Install

Video ITA 00_11_01.45.jpg
Video ITA 00_12_11.44.jpg
Video ITA 00_07_06.66.jpg
Video ITA 00_05_17.24.jpg

I placed the LED strip as well as the controller and the power supply on the wardrobe. For power I used an outlet I had set up for exactly this purpose a few years ago before assembling the wardrobe. As for the motion sensors, I mounted one on top of the wardrobe and one on top of the window, running the cables to the main controller. With the two sensor mounted this way, I have one detecting me as soon as I enter the door, while the other one detects my movements when I'm working at my desk. Having the whole room covered by the sensors will make sense when we are going to make automations in Home Assistant. For the temperature sensor, I put it in the space between the wall and the edge of the cabinet, to make it completely hidden but still have enough air around it.

It Works!

Video ITA 00_00_30.39.jpg
Video ITA 00_12_24.15.jpg
Video ITA 00_02_29.42.jpg
Video ITA 00_00_52.33.jpg

Now that the LEDs and the sensors are installed, we just need to test them. When I plugged in power, I was very happy to see that everything worked great, both the LEDs and the sensors. The LEDs make an amazing effect reflecting their light on the ceiling, especially in the evening. As I connected the ESP32 to Home Assistant, I made a few automations using the motion sensors and the LEDs. For example, I made one that turns the LED strip on as soon as I enter the room, keeping it on as long as one of the two motion sensors detects movement. Along with the LEDs, the automation also turns on some hexagonal wall-mounted lights that I've built last year. If no movement is detected, the LEDs turn off after 5 minutes.

Overall, I am very happy with how this project turned out, especially considering how cheap it was to build. Also, entering a room with lights that automatically turn on is so cool! To see more details about this project, watch the video on my YouTube channel. Bye!