There's an error in the return from the function line 272. You return the input parameter ch0 rather than the result of the Lux calculation lux1. //return (float)ch0; return (float)lux1;