Measuring Brightness with a LED

14 May 2020

twentysixer has developed a simple but effective way to detect brightness with the TinyLoRa. All that is needed is a simple LED:


With the TinyLoRa and a simple led you can detect brightness and darkness.

The LED is connected to 2 GPIOs in the reverse direction. The LED is charged and measured until it is discharged again. The darker it is, the longer it will take to discharge it. Clear LEDs with a low forward voltage are best suited, e.g. red or yellow

The GPIOs which the LED is connected to have to be defined in the secconfig.h:

#define LED_K as cathode
#define LED_A as anode

Furthermore, it is necessary to select the respective sensor and the brightness measurement.

#define HAS_SHT21_BRIGHTNESS - SHT21 + brightness via LED
#define HAS_BME280_BRIGHTNESS - BME280 + brightness via LED

Brightness measurement alone without one of the climate sensors is not currently implemented, do it yourself if necessary.


I have tested this setup with one of my sensors and a clear red 5mm LED connected between pins B2 and A3. Here ist the resulting graph for the sensor "looking" out of my Window.

Brightness Graph

You can clearly see the difference between day and night. The value reported gets lower with more light. One can even distinguish sunny from cloudy weather in the low (=bright) parts.