DIY

Adaptive lighting for PC

Adaptive lighting for PC  Adaptive lighting for PC Adaptive lighting for PC Smartphones have this smart function like adaptive lighting. This function is also present in some TV models. But, for some reason, computers do not have an automatic brightness control system. To change the brightness, you have to press the keys each time. And on some computers you need to press a key combination.
This is somewhat inconvenient and distracting from work.
The master has developed a simple device that can be connected to any computer, and its brightness will be adjusted automatically, just like in smartphones.
Tools and materials: -Arduino Pro Micro;
-LDR (photoresistors) – 2 pcs; -Resistor 10 K;
-User board;
-Pin connectors; -USB-cable; -Tools for soldering;
-Knife;
Adaptive lighting for PC Adaptive lighting for PC Adaptive lighting for PC Adaptive lighting for PC  Adaptive lighting for PC Adaptive lighting for PC  Adaptive lighting for PC Adaptive lighting for PC Step one: principle of operation
The device works as follows:
Data from a photoresistor directed on the user's face are sent to Arduino. This is analog data in the range 0 to 1024.
If you compare the values ​​(0-1024) with lighting, then you can control the brightness. The wizard uses a Python program running on a PC as software.
Step Two: Testing the Circuit
To test the device's performance, the master assembled the circuit on a breadboard. As software, wrote a simple program to output sensor data (light intensity data) to an Arduino serial monitor.

 //define sensor pin int sensor_pin = A3; void setup () & # 123; //set things here Serial.begin (9600); //init serial communication at 9600 bps} void loop () & # 123; //mainloop int sensorValue = analogRead (sensor_pin); //read the input on analog pin A3 & # 58; Serial.println (sensorValue); //send data over serial delay (200); //a little delay to make things work better}  

Ideally, the data should range from 0 to 1024 (theoretically). But in practice, no LDR is perfect (even in one batch). As a result, the master I received data from 0 to 950.
In any case, it works, and a small error does not matter.
Adaptive lighting for PC  Adaptive lighting for PC Step three: design and manufacture the custom board. Next, the master designed the printed circuit board. On the board you can see that there are two sensors, two sensors. This is really just for design. With two LDRs, it looks like a snail. LDR_L is an LDR that is not used in this assembly.
Then he made the PCB on the appropriate site.
Files for making the board can be downloaded here [/url.
Adaptive lighting for PC Adaptive lighting for PC Adaptive lighting for PC Step four: assembly
Assembly is very simple. You need to install Arduino on the board and solder the contact pads. You also need to solder the photoresistors.
Instead of soldering, you can use pin headers.
Adaptive lighting for PC Adaptive lighting for PC Step five: code
Next, you need to program the board.
First of all, he determined the Arduino contact to which the sensor enters data.

 //define sensor pin int sensor_pin = A3; & lt; br & gt;  

In the setup function, set up serial communication at 9600. The setup function runs only once every time the Arduino board is turned on.

  void setup () & # 123; //set things here Serial.begin (9600); //init serial communication at 9600 bps} & lt; br & gt;  

Then, in the main loop, the Arduino receives the data and sends it over the serial link. A small delay of 200ms, needed for smooth operation.

 void loop () & # 123; //mainloop int sensorValue = analogRead (sensor_pin); //read the input on analog pin A3 & # 58; Serial.println (sensorValue); //send data over serial delay (200); //a little delay to make things work better}  

The complete code for Arduino can be downloaded below.

 /* Computer Hack! Brightness Controller (C) License & # 58; GPL3-General Public License author & # 58; ashraf minhaj mail & # 58; [email protected] *///define sensor pin int sensor_pin = A3; void setup () & # 123; //set things here Serial.begin (9600); //init serial communication at 9600 bps} void loop () & # 123; //mainloop int sensorValue = analogRead (sensor_pin); //read the input on analog pin A3 & # 58; Serial.println (sensorValue); //send data over serial delay (200); //a little delay to make things work better}  

Now we need to prepare the Python software.
As mentioned earlier, the sensor sends data to the Arduino, and python does the rest. The wizard wrote a simple Python script.
Anyway, if you do not have it installed, install The latest version of Python can be downloaded [url = http: //python.org/download] here . When installing, make sure that the 'add python to environment variable path' checkbox is checked.
You also need to install two libraries, Pyserial and screen-bright -control, using the commands below ($ signs should denote them as a terminal command, copy without them)

  $ pip install pyserial $ pip install screen-brightness-control & lt; br & gt;  

Now let's take a look at parts of the code in case someone wants to edit it.
This part imports the 'serial.tools.list_ports' libraries needed to automatically detect the Arduino board.

  # import necessary libraries import serial # for serial communication import serial.tools.list_ports # to get Arduino port automatically import screen_brightness_control as brightness # to control brightness  

Sets the speed and port number. For this board the speed is 9600

  BUAD_RATE = 9600 # Pro Micro & # 39; s buad rate is 9600 PORT = & # 34; & # 34;  

This section automatically detects USB ports and tries to connect to the Arduino.

 # get sender device port automatically serial_ports = list (serial.tools.list_ports.comports ()) # get list of ports for s_port in serial_ports & # 58; # iterate through all ports if & # 39; Arduino Micro & # 39; in s_port.description & # 58; # look for Pro Micro board PORT = str (s_port & # 91; 0 & # 93;) # select first found board and break # proceed # connect with sender device sender = serial.Serial (PORT, BUAD_RATE) & lt; br & gt;  

The following function converts Arduino data (0 to 1024) to% data 0 to 100. This is called mapping.

 def map_value (value, in_min = 0, in_max = 1024, out_min = 0, out_max = 100) & # 58; & # 34; & # 34; & # 34; To map values. Arduio sends values ​​from 0 to 1024. My goal is to make them in between 0 to 100. & # 34; & # 34; & # 34; return int ((value - in_min) * (out_max - out_min)/(in_max - in_min) + out_min)  

The rest of the code just makes sure the brightness stays at the given light intensity .

 # mainloop while 1 & # 58; # convert byte data into string then integer sensor_value = int (sender.readline (). decode (& # 34; utf-8 & # 34;)) # get data final_value = map_value (value = sensor_value) # map value (brightness in percentage ) #print (sensor_value) print (final_value) brightness.set_brightness (final_value) # set brightness # close port properly so that others can use it sender.close () & lt; br & gt;  

Full the code can be downloaded below.

 & # 34; & # 34; & # 34; Computer Hack! Brightness Controller (C) License & # 58; GPL3-General Public License author & # 58; ashraf minhaj mail & # 58; [email protected] & # 34; & # 34; & # 34; & # 34; & # 34; & # 34; libraries - $ pip install pyserial $ pip install screen-brightness-control & # 34; & # 34; & # 34; # import necessary libraries import serial # for serial communication import serial.tools.list_ports # to get Arduino port automatically import screen_brightness_control as brightness # to control brightness # device buadrate (bit per second) # (change buadrate according to your need) BUAD_RATE = 9600 # Pro Micro & # 39; s buad rate is 9600 PORT = & # 34; & # 34; # get sender device port automatically serial_ports = list (serial.tools.list_ports.comports ()) # get list of ports for s_port in serial_ports & # 58; # iterate through all ports if & # 39; Arduino Micro & # 39; in s_port.description & # 58; # look for Pro Micro board PORT = str (s_port & # 91; 0 & # 93;) # select first found board and break # proceed # connect with sender device sender = serial.Serial (PORT, BUAD_RATE) def map_value (value, in_min = 0, in_max = 1024, out_min = 0, out_max = 100) & # 58; & # 34; & # 34; & # 34; To map values. Arduio sends values ​​from 0 to 1024. My goal is to make them in between 0 to 100. & # 34; & # 34; & # 34; return int ((value - in_min) * (out_max - out_min)/(in_max - in_min) + out_min) # mainloop while 1 & # 58; # convert byte data into string then integer sensor_value = int (sender.readline (). decode (& # 34; utf-8 & # 34;)) # get data final_value = map_value (value = sensor_value) # map value (brightness in percentage ) #print (sensor_value) print (final_value) brightness.set_brightness (final_value) # set brightness # close port properly so that others can use it sender.close ()  

 Adaptive lighting for PC Now it remains to connect the board with a cable to the computer and place it in a convenient place. The master glued it to the laptop lid from the back.
The whole process of making such a board, its programming and testing can be seen in the video.

Source:

usamodelkina.ru

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button