Computer Monitor Light for Desk 2 Home Assistant ESP32.
by nilnull in Workshop > Lighting
706 Views, 12 Favorites, 0 Comments
Computer Monitor Light for Desk 2 Home Assistant ESP32.
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
Supplies
- Aluminum profile for LED strip (1 m)
- LED strip (80 cm) (the old strip is shown in the pictures, but I used a piece of COB LED strip for this project)
- LED Power Supply 12W 1A
- Rotary encoder sensor (speed control module)
- ESP8266 Wi-Fi module NodeMCU
- 15A 400W MOSFET trigger switch (PWM regulator)
- DC-DC step-down converter 12V to 3.3V/5V for Arduino
- Bolts and nuts
- Old power cable from a computer
- 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
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
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.
Connecting the control system.
- I took a 12V power supply from the LED strip adapter.
- I reduced the voltage to 5V through a DC-DC module (12V to 3.3V/5V) and powered the ESP32.
- I powered the Rotary encoder sensor and the MOSFET Trigger through the same DC-DC module (12V to 3.3V/5V).
- 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.
- 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).