# Automatic Monitor Color Temperature Adjustment

## Overview

https://www.youtube.com/watch?v=yWbRG5oXVYE

Staring at a computer monitor all day is quite stressful. Moving your gaze from the cold, white light of a monitor to warmer indoor light is especially jarring to your senses. Programs like [f.lux](http://justgetflux.com/) and [Redshift](http://jonls.dk/redshift/) were created to ease this strain by adjusting the [color temperature](http://en.wikipedia.org/wiki/Color_temperature) of your monitor. However these programs don't measure color temperature of light in the environment and instead guess the temperature based on location, time of day, and sunrise/sunset time.  
  
This project will show you how to build hardware that measures the temperature of ambient light and automatically adjusts your monitor color to match. With just a simple RGB color sensor and an Arduino or FT232H-based cable, your computer can easily sense and react to light in its environment.  
  
Before building this project, it will be helpful to familiarize yourself with the [color sensor guide](http://learn.adafruit.com/adafruit-color-sensors/overview).

# Automatic Monitor Color Temperature Adjustment

## Hardware

You'll need the following parts to build this project:

## Assembly
The assembly of this project is very simple. Cut the right angle header to size and solder it to the color sensor. Connect the color sensor to the Arduino as follows:  

- Color sensor **5V** to Arduino **5V**
- Color sensor **GND** to Arduino ground
- Color sensor **SDA** to Arduino **SDA** (analog 4 on older Arduinos, check your your [board pinout](http://arduino.cc/en/main/boards#.UyyudFFdV74) to be sure)
- Color sensor **SCL** to Arduino **SCL** (analog 5 on older Arduinos, see above to check others)
- Color sensor **LED** to Arduino ground to disable the built-in LED.

![](https://cdn-learn.adafruit.com/assets/assets/000/015/600/medium800/light_60JiMO6.jpg?1395694782)

Above you can see a picture of the hardware connected to an Arduino Nano.  
  
If you're using the FT232H cable instead of the Arduino, connect it to the sensor as follows:

- **If using the 5V cable** : color sensor **5V** to cable power ( **red** )
- **If using the 3.3V cable** : color sensor **3.3V** to cable power ( **red** )
- Color sensor **GND** to cable ground wire ( **black** )
- Color sensor **SDA** to both the cable **green** and **yellow** wires to duplex the sent and received I2C data.
- Color sensor **SCL** to cable clock wire ( **orange** )
- Color sensor **LED** to cable ground wire ( **black** )

I found it was easiest to cut a few female to male extension cables up and solder them into 2-into-1 Y adapters to connect the **SDA -\> green and yellow** , and **GND & LED -\> ground** connections. ![](https://cdn-learn.adafruit.com/assets/assets/000/015/599/medium800/light_RwrzeVC.jpg?1395691986)

Above you can see a picture of the hardware connected to a **3.3 volt** version of the FT232H cable.  
  
If you have questions about using the FT232H cable, check out its [data sheet here](http://www.ftdichip.com/Products/Cables/USBMPSSE.htm "Link: http://www.ftdichip.com/Products/Cables/USBMPSSE.htm") or this [application note](http://www.ftdichip.com/Support/Documents/AppNotes/AN_190_C232HM_MPSSE_Cable_in_USB_to_I2C_Interface.pdf "Link: http://www.ftdichip.com/Support/Documents/AppNotes/AN\_190\_C232HM\_MPSSE\_Cable\_in\_USB\_to\_I2C\_Interface.pdf") on using the cable to talk I2C.

# Automatic Monitor Color Temperature Adjustment

## Software

## Dependencies
You'll need to download and install the following dependencies for this project's software:  

> 

**[Adafruit TCS34725 Color Sensor Arduino Library](https://github.com/adafruit/Adafruit_TCS34725)**  
If you aren't sure how to install an Arduino library, [check out this tutorial](http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use).  
  
**Python**  
The software for this guide is written in [python](https://www.python.org/) and should work with either python 2.7 or 3+ (although it was primarily tested against version 2.7).   
  
Once you have python installed, follow these steps depending on your platform:  
  

# **Mac OS X**
[Install NumPy](http://www.scipy.org/install.html#individual-binary-and-source-packages) with one of the binary packages [here](http://sourceforge.net/projects/numpy/files/NumPy/).  
  
Install the [PIP](http://pip.readthedocs.org/en/latest/installing.html) python package manager by executing the following commands in a terminal:  

> wget [https://raw.github.com/pypa/pip/master/contrib/get-pip.py](https://raw.github.com/pypa/pip/master/contrib/get-pip.py)  
> python get-pip.py

Finally, install the [colormath](https://code.google.com/p/python-colormath/) and [pyserial](http://pyserial.sourceforge.net/ "Link: http://pyserial.sourceforge.net/") library by executing in a terminal:  

> pip install colormath==1.0.9 pyserial

If you plan to use the FT232H cable, download and install the X code command line tools by following the steps in the [answer here](http://stackoverflow.com/questions/9329243/xcode-4-4-and-later-install-command-line-tools). You will also want to install the [homebrew](http://brew.sh/) package manager too. Once those are installed you can install the required [libftdi](http://www.intra2net.com/en/developer/libftdi/) and [libmpsse](https://code.google.com/p/libmpsse/) dependencies by executing in a terminal:  

> brew install libftdi  
> brew install swig  
> wget [https://libmpsse.googlecode.com/files/libmpsse-1.3.tar.gz](https://libmpsse.googlecode.com/files/libmpsse-1.3.tar.gz)  
> tar xvfz libmpsse-1.3.tar.gz  
> cd libmpsse-1.3  
> ./configure  
> make  
> sudo make install

# **Linux**
These steps are written for Ubuntu, but should be straightforward to adapt to other distributions. In a terminal execute the following commands:  

> sudo apt-get install python-numpy python-pip  
> pip install colormath pyserial

If you plan to use the FT232H cable, execute the following commands to install the required software:  

> sudo apt-get install python-dev libftdi-dev swig  
> wget [https://libmpsse.googlecode.com/files/libmpsse-1.3.tar.gz](https://libmpsse.googlecode.com/files/libmpsse-1.3.tar.gz)  
> tar xvfz libmpsse-1.3.tar.gz  
> cd libmpsse-1.3  
> ./configure  
> make  
> sudo make install

# **Windows**
[Install NumPy](http://www.scipy.org/install.html#individual-binary-and-source-packages) from one of the binary installers [here](http://sourceforge.net/projects/numpy/files/NumPy/).  
  
Install PIP by downloading the [get-pip.py](https://raw.github.com/pypa/pip/master/contrib/get-pip.py) file, opening a command window, navigating to the directory with the file, and executing:  

> python get-pip.py

Note you might need to add python to your path to be able to run scripts from the command line. [This blog post](http://www.anthonydebarros.com/2011/10/15/setting-up-python-in-windows-7/) has a simple set of instructions to add python to your path.  
  
Now execute the following command to install the required colormath and pyserial library:  

> pip install colormath pyserial

At this point all the dependencies for Windows are installed. Unfortunately you won't be able to use the FT232H cable with Windows because the libmpsse library doesn't support it. Stick to using an Arduino to communicate with the color sensor on Windows.  
  
Also note that the software for this project has only been tested on a virtual machine running Windows. Everything should work on a real machine, but if you have issues send them to the [github repository](https://github.com/tdicola/AutoColorTemp) for the project.  
  

# Download Project Software
Download the software for this project from its [github repository](https://github.com/tdicola/AutoColorTemp) by clicking this button:  
[Download Software](https://github.com/tdicola/AutoColorTemp/archive/master.zip)
Unzip the archive and you will find an Arduino sketch, **AutoColorTemp\_Sketch** , and a collection of python scripts.  
  
If you're using an Arduino for this project, load the sketch in Arduino and upload it to your hardware. If you open the serial monitor at 115200 baud you should be able to send a question mark character ? and see the current RGB color (in floating point, with values from 0-1.0) printed.

# Software Usage
To run the software for this project, make sure you've assembled the hardware and connected it to your computer. Open a terminal and navigate to the directory with the downloaded python scripts and execute the following command:  

> python run.py --help

You should see a display of all the command line parameters for the program. Take note that either the --arduino or --ftdi parameters are required to run the program.  
  
For example to run the program with Arduino hardware connected to /dev/ttyUSB0, execute:  

> python run.py --arduino /dev/ttyUSB0

Or to run with an Arduino connected to COM4 on Windows, execute:  

> python run.py --arduino COM4

To use the FTDI cable you need to specify the --ftdi option instead of the --arduino option. No port or other parameter is required when using the --ftdi option.   
  
**However, before the software is run with the --ftdi option you must disable the built in kernel driver for FTDI devices!** Unfortunately the driver built in to recent Linux and Mac OS X kernels is not compatible with the libftdi library and must be temporarily disabled. The provided **run\_ftdi\_linux.sh** and **run\_ftdi\_macos.sh** shell scripts can be run to automatically disable and re-enable the drivers when running the software. These shells scripts need to be run as root with the sudo command.  
  
For example to run with FTDI hardware on a Mac, execute:  

> sudo ./run\_ftdi\_macos.sh --ftdi

Or on Linux execute:  

> sudo ./run\_ftdi\_linux.sh --ftdi

Be aware when the program is running the FTDI drivers will be disabled so you will not be able to program an Arduino or communicate with other FTDI-based devices!  
  
Once the software is running it will query the color sensor every 10 seconds, compute the temperature of the measured color, and adjust the gamma of the primary display to match the measured color temperature. **Make sure to disable or close programs like f.lux before running the software as they might interfere with the gamma adjustment!**  
  
Try shining different colored lights on the sensor to trick it into seeing extreme temperatures (orange, white, or light blue LEDs work best--other colors will be too extreme).  
  
You can press Ctrl-C at any time to quit the application. # Automatic Monitor Color Temperature Adjustment

## Future Work

This project is a great example of using an Arduino or FT232H-based cable to send sensor data to your computer. Using an RGB color sensor you can make your computer aware of the environment and change monitor color temperature based on ambient lighting. Some interesting ways you might extend this project include:

- Flip the sensor around to read color displayed by your monitor and build a calibration tool to adjust colors for perfect display accuracy.
- Use the color sensor to play different music depending on the color of light in the room. Play exciting music to boost productivity in the morning and afternoon, and more relaxed music in the evening and night.
- Build a color matching game for kids where the computer asks to see items of a specific color.
- Extend the [Adalight project](http://learn.adafruit.com/adalight-diy-ambient-tv-lighting/overview "Link: http://learn.adafruit.com/adalight-diy-ambient-tv-lighting/overview") to measure ambient light and adjust itself to match the color.

What can you think of to extend the project?  

## Featured Products

### RGB Color Sensor with IR filter and White LED - TCS34725

[RGB Color Sensor with IR filter and White LED - TCS34725](https://www.adafruit.com/product/1334)
Discontinued - **you can grab** [**Adafruit APDS9960 Proximity, Light, RGB, and Gesture Sensor - STEMMA QT / Qwiic**](https://www.adafruit.com/product/3595) **&nbsp;instead!**

Your electronics can now see in dazzling color with this lovely color light...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1334)
[Related Guides to the Product](https://learn.adafruit.com/products/1334/guides)
### Flora Color Sensor with White Illumination LED - TCS34725

[Flora Color Sensor with White Illumination LED - TCS34725](https://www.adafruit.com/product/1356)
[Discontinued - **you can grab this&nbsp;** Adafruit APDS9960 Proximity, Light, RGB, and Gesture Sensor - STEMMA QT / Qwiic **&nbsp;instead!**](https://www.adafruit.com/product/3595)

Your electronics can now see in dazzling color with this lovely color light sensor. We...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1356)
[Related Guides to the Product](https://learn.adafruit.com/products/1356/guides)
### Adafruit METRO 328 Fully Assembled - Arduino IDE compatible

[Adafruit METRO 328 Fully Assembled - Arduino IDE compatible](https://www.adafruit.com/product/50)
We sure love the ATmega328 here at Adafruit, and we use them&nbsp;_a lot_&nbsp;for our own projects. The processor has plenty of GPIO, Analog inputs, hardware UART SPI and I2C, timers and PWM galore - just enough for most simple projects. When we need to go small, we use a <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/50)
[Related Guides to the Product](https://learn.adafruit.com/products/50/guides)
### Arduino Micro with Headers - 5V 16MHz - (ATmega32u4 - assembled)

[Arduino Micro with Headers - 5V 16MHz - (ATmega32u4 - assembled)](https://www.adafruit.com/product/1086)
_Squee_! It's the cutest, tiniest little Arduino yet! The Arduino Micro packs all of the power of the Arduino Leonardo in a 1.9" x 0.7" (48mm x 18mm) size. Although it may look like a stick of gum, its actually a USB-native 8-bit microcontroller, with 32K of flash, and...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1086)
[Related Guides to the Product](https://learn.adafruit.com/products/1086/guides)
### Break-away 0.1" 36-pin strip right-angle male header (10 pack)

[Break-away 0.1" 36-pin strip right-angle male header (10 pack)](https://www.adafruit.com/product/1540)
Breakaway header is like the duct tape of electronics. Its great for connecting things together, soldering to perf-boards, fits into any breadboard, etc. We go through these guys real fast, and thought that given how handy they are, we'd offer them in a pack of ten!  
  
Each pack...

In Stock
[Buy Now](https://www.adafruit.com/product/1540)
[Related Guides to the Product](https://learn.adafruit.com/products/1540/guides)
### Premium Female/Male 'Extension' Jumper Wires - 40 x 6" (150mm)

[Premium Female/Male 'Extension' Jumper Wires - 40 x 6" (150mm)](https://www.adafruit.com/product/826)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on one end and 0.1" female header contacts...

In Stock
[Buy Now](https://www.adafruit.com/product/826)
[Related Guides to the Product](https://learn.adafruit.com/products/826/guides)

## Related Guides

- [Bluetooth Temperature & Humidity Sensor](https://learn.adafruit.com/bluetooth-temperature-and-humidity-sensor.md)
- [Adafruit VS1053 MP3/AAC/Ogg/MIDI/WAV Codec Breakout Tutorial](https://learn.adafruit.com/adafruit-vs1053-mp3-aac-ogg-midi-wav-play-and-record-codec-tutorial.md)
- [How to Find Hidden COM Ports](https://learn.adafruit.com/how-to-find-hidden-com-ports.md)
- [Bluefruit LE Connect for iOS and Android](https://learn.adafruit.com/bluefruit-le-connect.md)
- [Arduino Lesson 6. Digital Inputs](https://learn.adafruit.com/adafruit-arduino-lesson-6-digital-inputs.md)
- [Using NeoPixels and Servos Together](https://learn.adafruit.com/neopixels-and-servos.md)
- [Current Limiting Stepper Driver with DRV8871](https://learn.adafruit.com/current-limiting-stepper-driver-with-drv8871.md)
- [IR Sensor](https://learn.adafruit.com/ir-sensor.md)
- [20mm LED Pixels](https://learn.adafruit.com/20mm-led-pixels.md)
- [Adafruit  PCA9685 16-Channel Servo Driver](https://learn.adafruit.com/16-channel-pwm-servo-driver.md)
- [Arduino Lesson 16. Stepper Motors](https://learn.adafruit.com/adafruit-arduino-lesson-16-stepper-motors.md)
- [Adafruit 4-Channel ADC Breakouts](https://learn.adafruit.com/adafruit-4-channel-adc-breakouts.md)
- [SMS Texting Pet Food Dish](https://learn.adafruit.com/sms-texting-pet-food-dish.md)
- [How to Build a Testing Jig](https://learn.adafruit.com/how-to-build-a-testing-fixture.md)
- [Arduino Lesson 9. Sensing Light](https://learn.adafruit.com/adafruit-arduino-lesson-9-sensing-light.md)
