Automatically adjusts a Windows laptop's screen brightness using the webcam.
This small Python utility reads the average brightness from the webcam, maps it to a target screen brightness and applies smooth, stable changes via Windows WMI. It's intended for personal use on Windows laptops where automatic brightness hardware features are limited or unavailable.
- Real-time ambient light measurement via webcam
- Smooth transitions and deadzone to avoid flicker
- Configurable parameters (camera index, smoothing, limits)
-
Windows (uses WMI to change brightness)
-
Python 3.8+
-
See
requirements.txtfor Python packages: -
opencv-python
-
WMI
-
pywin32
- Create or activate a Python virtual environment (recommended).
- Install dependencies:
pip install -r requirements.txtRun the script from the project folder:
python auto_brightness.py- The script prints camera average, target brightness and current screen brightness to the console.
- Press
Qin the camera window orCtrl+Cin the console to stop.
To enable the on-screen preview window while testing, open auto_brightness.py
and set SHOW_CAMERA = True.
All runtime options are plain constants at the top of auto_brightness.py:
CAMERA_INDEX— index of webcam (0, 1, ...)READ_INTERVAL— seconds between camera reads (default 0.5)SMOOTHING_SAMPLES— how many camera readings to averageSTABLE_TIME— seconds to wait while lighting is stable before changingMIN_BRIGHTNESS,MAX_BRIGHTNESS— limits applied to the screen valueCAMERA_DARK,CAMERA_BRIGHT— camera calibration points mapped to min/maxBRIGHTNESS_DEADZONE— minimum change required to trigger adjustmentBRIGHTNESS_STEP— how much to change screen brightness per stepSHOW_CAMERA— show webcam overlay for debugging
Edit those values directly in the file and re-run the script to change behaviour.
- The script only works on Windows because it uses WMI to set brightness.
- Some monitors or drivers may not support
WmiSetBrightness— if brightness does not change, check your device driver and try running the script as an elevated (administrator) user. - If the webcam cannot be opened, try changing
CAMERA_INDEXto another value (0, 1, 2, ...). Use other camera apps to confirm the index. - If console output looks noisy, increase
SMOOTHING_SAMPLESorSTABLE_TIME.
- This tool is best for laptops where the physical brightness controls are accessible through WMI. It is provided as-is for experimentation.