Computer Monitor Light for Desk 2 Home Assistant ESP32.

by nilnull in Workshop > Lighting

809 Views, 12 Favorites, 0 Comments

Computer Monitor Light for Desk 2 Home Assistant ESP32.

IMG_20240919_181509.jpg
IMG_20240919_181519.jpg

A project for a monitor light. My goal is more to inspire others to build something similar rather than to provide a detailed step-by-step guide. This is the second version of the project, and I already had a clear idea of what to do. My son got a bigger monitor, and the old light was too small. So, I used the first version as a donor for parts

https://youtu.be/5b_I_KIG1wQ



Supplies

esp.png
HW 517.png
Screenshot 2024-09-20 113346.png
Screenshot 2024-09-20 154451.png
  1. Aluminum profile for LED strip (1 m)
  2. LED strip (80 cm) (the old strip is shown in the pictures, but I used a piece of COB LED strip for this project)
  3. LED Power Supply 12W 1A
  4. Rotary encoder sensor (speed control module)
  5. ESP8266 Wi-Fi module NodeMCU
  6. 15A 400W MOSFET trigger switch (PWM regulator)
  7. DC-DC step-down converter 12V to 3.3V/5V for Arduino
  8. Bolts and nuts
  9. Old power cable from a computer
  10. Several pieces of wire

This project is an improvement over the first version and demonstrates how you can upgrade with available materials and components.

Measuring and Cutting the Aluminum Profiles

IMG_20240830_181825.jpg
IMG_20240830_180944.jpg
IMG_20240830_182507.jpg

I filed down the sharp edges a bit. This time, I designed a different mounting system that allows the lamp to slide along the X-axis by using the profile attached to the monitor as a rail.

Wiring and Installation

IMG_20240830_182650.jpg
IMG_20240830_182610.jpg
IMG_20240830_182701.jpg
IMG_20240830_182907.jpg
IMG_20240831_102241.jpg

I routed the cables and stuck the LED strip to the profile. I bolted a cap in the center of the light fixture and used it to connect the other profile. This made the connection easy to repair if needed.

I made something like a splitter from an old computer cable. One end plugs into the monitor, and the other connects to the monitor's power cable. From this connection, I take 220V to power the LED strip and the ESP32.

IMG_20240901_120413.jpg
IMG_20240901_165506.jpg
Неозаглавен чертеж.jpg

Connecting the control system.

  1. I took a 12V power supply from the LED strip adapter.
  2. I reduced the voltage to 5V through a DC-DC module (12V to 3.3V/5V) and powered the ESP32.
  3. I powered the Rotary encoder sensor and the MOSFET Trigger through the same DC-DC module (12V to 3.3V/5V).
  4. I interrupted only the negative wire going to the LED strip power supply using the MOSFET Trigger, as it only cuts the negative. The control is connected to GPIO27 on the ESP32.
  5. I connected the positive and negative of the Rotary encoder sensor to the ESP32 at GPIO17 and GPIO16 respectively. If these are swapped, it’s not a problem – it will just increase/decrease in the opposite direction.


Programming

output:

- platform: ledc

pin: GPIO27

frequency: 20000Hz

id: ledcout27

# Configures an LED control output on GPIO27 with a frequency of 20kHz.

# The ID "ledcout27" allows it to be referenced in other parts of the config.


light:

- platform: monochromatic

output: ledcout27

id: led_light

name: "LED Strip"

# Creates a monochromatic (single-color) light entity that uses the GPIO27 output (referenced as "ledcout27").

# The light is named "LED Strip", and it can be controlled by other parts of the system.

# The default transition time can be set here but is commented out for now.


text_sensor:

- platform: wifi_info

ip_address:

name: "LED Controller IP Address"

ssid:

name: "LED Controller SSID"

bssid:

name: "LED Controller Connected BSSID"

# Provides WiFi connection information as text sensors:

# - IP address of the device

# - SSID (WiFi network name)

# - BSSID (physical address of the connected WiFi access point)


switch:

- platform: restart

name: "LED Controller Restart"

- platform: shutdown

name: "LED Controller Shutdown"

# Defines switches for system management:

# - One for restarting the LED controller

# - One for shutting down the controller


sensor:

- platform: wifi_signal

name: "LED Controller WiFi Strength"

update_interval: 60s

# Measures and reports the WiFi signal strength every 60 seconds.

- platform: rotary_encoder

id: rotary_key

pin_a: GPIO17

pin_b: GPIO16

resolution: 2 # Most encoders have a resolution of 2

min_value: 0

max_value: 255

name: "LED Brightness Encoder"

on_value:

then:

- light.turn_on:

id: led_light

brightness: !lambda |-

int new_value = x * 5; // We increase the change step by factor 5

if (new_value > 255) {

new_value = 255;

}

return (float(new_value) / 255.0);

#transition_length: 0.5s

# This block sets up a rotary encoder on GPIO17 and GPIO16.

# The encoder adjusts the brightness of the LED strip from 0 to 255.

# A custom lambda function increases the encoder sensitivity by multiplying the change by 5.

# If the calculated value exceeds 255, it's capped at 255.

# You can set a transition time (smooth brightness change) if needed.


binary_sensor:

- platform: gpio

pin:

number: GPIO26

mode: INPUT_PULLUP

name: "Encoder Button"

on_press:

then:

- light.toggle:

id: led_light

# This block sets up a binary sensor (button) on GPIO26 using INPUT_PULLUP mode.

# When the button is pressed, it toggles the state of the LED light (on/off).