Search code examples
javascriptraspberry-piraspbian

Determine value of ambient brightness from Rasberry Pi camera in Javascript


I'm wondering if it would be at all possible to use a Raspberry Pi camera (attached to a Pi 3) to read the ambient brightness of the environment, as a light sensor.

I would want to poll the sensor once every 1-5 seconds such that I can adjust a variable based on the value of brightness seen. Something resembling...

var run = setInterval(function() {
    var ambient = <code to read the RPi brightness>;
    if(ambient < 100) { doSomething() }
    else { doSomethingElse() }
}, 1000);

I have seen the following Node-based and javascript controller, but haven't had the chance to play with it thus yet...


Solution

  • I just wrote a python program that captures an image to a jpg file every 60 seconds, then reads the EXIF Brightness Value from the jpg file (logs it and another program plots it.)

    (Not Javascript, but the concept is the same.)

    EXIF Brightness Values:

    • exactly 0.0 for total darkness
    • roughly 0.05 in a dark room with light streaming through the doorway from kitchen 30 feet away
    • roughly 0.7 for a small room lit only by 150 watt overhead lighting
    • roughly 1.0 for a small room with one large window at evening light plus overhead lighting
    • roughly 1.5 for a small room with one large window during end of the world storm outside
    • roughly 2.6 for a small room with one large window with partial blinds and full sun outside

    Code is here: https://github.com/slowrunner/Carl/tree/master/Projects/LogLightValueAndPlot