52

weeks

Week 23 - Light Exposure Tracking App

This week I created an iOS app called LighterUp that tracks your daily light exposure and gives you daily scores.

Tools I used:

  • Xcode, SwiftUI + ChatGPT - to code, test, and upload the app

  • Charts - to plot the data

  • Photone - to calibrate my light sensor reading

  • Sunlight - the thing we’re measuring

  • P’s wisdom - to teach me about the ideal daily light exposure

Context

So it turns out sitting inside all day and then staying up late with bright lights isn’t healthy.

Imagine living as a hunter-gatherer, waking up with the sun, being out in the sun all day, then winding down early evening, and sleeping once the sun sets because you can’t really see anything after that. There have been times in my life where I’ve fully disconnected from computers and phones and lived this way, and I’ve always felt great.

There have been many studies done on the effect of light on circadian rhythm, but in my observations I don’t see these results changing people’s behaviour. In particular, having bright lights and screens in the hours before bed delays melatonin onset and shortens its effects, leading to poor sleep quality and probably a lack of deep sleep. And being outside and getting sunlight ASAP after waking up in the morning has a lot of health benefits too.

So I thought I’d make a simple app (isn’t that ironic) to track light exposure using your phone camera, and give you a score based on how close you are to a recommended amount of light in the mornings, afternoons, and evenings.

Process

Measuring ambient light levels is easy to do with a dedicated sensor, but the iPhone camera isn’t designed for that task and is not very accurate. I had previously tried Lux Light Meter Pro - but after doing a bit of research it turns out that this app and similar ones are not accurate.

The only iOS app that is comparable to a real light meter is Photone. Unfortunately but not surprisingly, their whitepaper only discusses their accuracy, but not their method for achieving it.

The best I could do was make my own light calculation and then calibrate it against Photone in the same conditions. This app isn’t meant to be a scientific or objective guide, just a small nudge :)

So I found a way to measure light intensity with the phone camera (the method involves calculating RGB values for every pixel in a camera frame and assigning it a luminance, then averaging that over the entire frame, and over a few seconds). I assigned an (arbitrary) number to it and scaled that to 1500 (the peak lumens in the recommended chart).

Then I plotted it using the Charts package (although I should swap to Swift Charts to make it look native and pretty), added logic for different date ranges, and created a scoring system that generates scores for the morning, afternoon, evening, and overall. In the morning and afternoon you are penalized for underexposure (compared to the recommended curve) and in the evening you are penalized for overexposure.

So give it a try and let me know what you think: here’s the app store link.

Learnings

  • Light is important

  • Creating arbitrary scores is pretty motivating, even when I know it’s made up

Next steps

  • Improve the look/feel of the app

  • Calibrate the light readings

  • Can I sync this to Apple Health?

  • Correlate with sleep / other metrics

  • Build a wearable

  • Make a similar tracker for air and noise pollution