light sensor  algorithm added