version française

english version

A simple Arduino code for Sky Quality Meter (SQM) based on TSL237 for use in dark conditions

Simple Sky Quality Meter (SQM)

DIY : Simple Arduino ESP32 code to compute TSL237 counts, frequency and magnitude

by yapo and jompo (07/2022), SQM for rather low frequencies (i.e. dark conditions)

This simple arduino program for ESP32 (download here) displays the counts (in the given period), the frequency of the TSL235/TLS237, and computed magnitude on a ST7789 IPS screen (display in red color for amateur astronomers ;-)


The wiring scheme can be found here and see the picture here

The TLS 237 is behind a UV-IR cut filter and a LED collimator or lens

We have found information for this project on various forum discussion as this one, in project as this one or that one and SQM discussion as this web page


About the code :

The two following defines can be modified in the very beginning of the arduino code :

#define period 20000000UL // period of measure of TSL237 counts in micro-seconds, longer is the period, more counts will be done (i.e. in very dark condition, 20 seconds are ok). For having more frequent measures, you can lower to 10 seconds or 5 seconds (i.e. 5 000 000 micro-seconds)

#define MAGNITUDECONST 21 // magnitude constant in the following equation : Magnitude = MAGNITUDECONST - 2.5*log10(frequency)

This code will work up to ~100KHz on an ESP32 chip, above that frequency the interrupts saturate the processor.

The only external library needed is for the ST7789 IPS screen, i.e. the Adafruit_ST7789 library


Digital Pin layout ESP32 and components


The parts needed for this project :

Powering of the ESP32 can be made by a Dual 18650 Lithium Battery Shield V8/V9 Mobile Power Expansion Board Module 5V/3A 3V/1A Micro USB For Arduino ESP32 ESP8266 (see picture). This power board costs about 4-5 euros (without the 16850 batteries)

All these components can be found on ebay or aliexpress


The arduino code is here