Jump to content

Stargazers Lounge Uses Cookies

Like most websites, SGL uses cookies in order to deliver a secure, personalised service, to provide social media functions and to analyse our traffic. Continued use of SGL indicates your acceptance of our cookie policy.


Sky Quality Meter with wifi

Recommended Posts

Just finished work on a sky quality meter with built in wifi. The device is based on the ambient light sensor TSL2591 and the wifi board ESP32. Communication between the two boards is through I2C. The device has a 40 degrees lens.

The light sensor is programmable, which means you can set integration time (from 100 to 600 ms) and gain (from 1 to almost 5000, in 4 steps). I implemented automatic adjustment of these parameters to allow for the highest dynamic range (600M:1 accoring to the spec sheet).

The device shows Sky readings as a web page. It is connected to a local wifi network, although it could also create its own access point. So far I haven't been able to calibrate the sqm yet, partly due to eternal cloud cover. But it should only require one parameter to be adjusted.

The code is available on GitHub. Sky-Quality-Meter

Here are som pictures.

The components:


The parts connected:


The finished device:


This is how output is presented:


  • Like 7

Share this post

Link to post
Share on other sites

I used this reference:


But in the end, you still need to do a real calibration to take into account any geometry, glass, etc. In my case a 16 mm 40 degrees lens.

Fortunately @gorann let me borrow his SQM while he's down under.

I will probably change the firmware to also let it connect to INDI, so I get the data directly into Kstars/Ekos.

Edited by wimvb

Share this post

Link to post
Share on other sites


What lens did you use? care to share the link



Edited by fozzybear

Share this post

Link to post
Share on other sites
16 minutes ago, fozzybear said:


What lens did you use? care to share the link




And one of these


I believe it was the 2nd one that I ended up using. Must check


Checked: the 8 mm 40 deg lens it is. 

One of these covers the sensor's pcb almost perfectly


Edited by wimvb
  • Thanks 1

Share this post

Link to post
Share on other sites
12 minutes ago, skybadger said:

I used one of these https://www.ebay.co.uk/c/7020203413?iid=264465139929

Now I've got 9 left...

Attached via araldite. 

damn and double damn just ordered the above  as per Wim from the rain forest got to wait till end of Jan slow boat from china...…...

Edited by fozzybear

Share this post

Link to post
Share on other sites

Interesting thread Wim! So I assume my SQM arrived and did not get lost by Postnord🙄

Just landed in Brisbane waiting for the next plane.😎

Share this post

Link to post
Share on other sites
3 hours ago, gorann said:

Interesting thread Wim! So I assume my SQM arrived and did not get lost by Postnord🙄

No, I got a message from PostNord that it's waiting for me at the local pick up place. Due to my knee condition, I haven't been able to pick it up yet. Will do so on Monday. 

3 hours ago, gorann said:

Just landed in Brisbane waiting for the next plane.😎

Have a nice stay. I hope you get enough clear skies to test your travel AP kit. 

Share this post

Link to post
Share on other sites

I've now made a MQTT version of the sky quality meter. In this version, the device no longer creates a webpage with the SQM readings, but publishes the timestamp and SQM readings to a MQTT broker. The code is in the github link provided in the original post.

Here's what needs to be done:

1. Install a MQTT broker. I installed Mosquitto on a Raspberry Pi I had lying around. Here's a good resource:


2. Install a MQTT client. For this I use MQTT.fx ( https://mqttfx.jensd.de/ ) on my Windows computer. There are several clients available, including Mosquitto.

3. Get a simple mqtt client for the esp32:


This version of the sky quality meter is not (yet?) compatible with INDI, you would need an INDI MQTT driver for this.

  • Like 1

Share this post

Link to post
Share on other sites

Update. Tonight I compared my SQM with a Unihedron model L. I had already done a few tests indoors and "matched" readings. Pointing North, away from the full moon, my SQM measured 18.78, and the Unihedron 18.70. Pointing at zenith (closer to the moon which was at its highest point, almost due South), my SQM showed a somewhat higher reading than the Unihedron. It seems that mine has a smaller fov because of the difference in lenses. All in all, I'm pleased with the result.

  • Like 1

Share this post

Link to post
Share on other sites


Would you mind providing a measure of your Lux measurement range from night to day. ? I'd like something to compare with. 

Currently, in This overcast weather, I'm getting log(Lux) between 3.0 down to -2.5.


I'm concerned whether the on board leds of the ESP are limiting the darkness measurements. 





Share this post

Link to post
Share on other sites

I will check. Atm, it's sunny, with thin clouds. Also, since I'm 60 degrees North, the sun doesn't get that high here.

I thought about that LED, but with the lens and lens mount I use, it's sealed off. You can always cover it with some black electrical tape. Or if you're bold, take it off with a fine solder iron. 

Share this post

Link to post
Share on other sites

I sealed it off too, fixing the board into place using araldite at the back of the lens. But the araldite turned out to be translucent and the leds (one on the power converter, one on the esp and one on the sensor board itself) are all rather bright when I am reaching for that 0.002 Lux of starlight. 

I will be removing the leds after a bit of practice. 

My latitude is 52N and I haven't seen the sun in weeks!

Share this post

Link to post
Share on other sites

Update lens arrived yet lens holders never arrived so refunded and re-ordered another month wait duh...


  • Sad 1

Share this post

Link to post
Share on other sites

Took the leds off the power regulator, the esp8266 and the melexis pcb. Now I get log(Lux) at -3.4 compared to -2.5. So a factor of 8 sensitivity improvement due to a reduced background. Or about 2 magnitudes.


  • Like 2

Share this post

Link to post
Share on other sites
14 minutes ago, skybadger said:

melexis pcb

So, you have a cloud detector as well? I got mine as part of a separate weather station. 

Share this post

Link to post
Share on other sites

It's all in the same box, ir sensor next to the Lux meter lens and both talk i2c via the esp.

Share this post

Link to post
Share on other sites

Ok, and with your lens I can imagine it will affect sky measurement. With my lens and lens holder, the sensor is shielded from the led on the esp board.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Gina
      In this thread I will endeavour to build an MQTT system to read ambient weather conditions outside and in the observatory and control the roll-off-roof etc.
    • By wimvb
      I recently posted my design for a weather station in this section.
      As I had bought several pressure/humidity sensors, as well as ir temperature sensors and ESP32 development boards, I wondered how small a weather monitor could get. The sensors are quite small, and so is the micro controller. Such a weather monitor wouldn't incorporate wind speed measurement nor a rain detector, since these take up more space. But otoh, there is seldom rain without clouds, so if you detect clouds, you should be safe.
      Here it is, a miniature (9.8 x 5.9 x 2.7 cm) weather monitor. The device has built in wifi, is powered from a micro usb contact and is compatible with the INDI Weather Watcher driver.
      The parts:

      (the mat underneath has a 1 inch grid pattern)
      plastic box 9.8 x 5.8 x 2.7 cm a piece of V-board, in my case with copper islands rather than strips ESP32 development board with male headers MLX90614 ir temperature sensor with I2C interface BME280 environmental sensor with I2C interface micro usb cable and power adapter, or a powerbank for wireless operation Assembly is really easy and involves drilling a hole in the box, soldering the components in place and wiring to the ESP.
      The finished monitor in place. As this is a box with a click lid, I used silicone to seal it. The holes on the sides and bottom are drilled at an angle to keep rain out.

      As I built it, the electronics will heat the BME slightly, and because it is mounted inside the casing, it will be slow to reach ambient temperature should this change abruptly. Adding more holes near the ESP would take the inside temperature down. Otoh, temperature readings don't have to be that accurate, and you could use the MLX ambient reading for more accuracy.
      Here's the INDI control panel for the weather monitor

      (Wind and rain are simulated, because I was testing the driver when I took the screen shot)
      Here is how it looks in Ekos scheduler. The red marker indicates that weather conditions are bad. In this case clouds = 100 %. If the tickbox next to "Weather" is checked, Ekos will allow weather conditions to control an imaging sequence.

      And in the ROR driver

      (I know it says Dome, but the ROR driver is derived from the dome driver, and it's still under development. Besides, this is the simulator driver.)
      The code for the esp is on my github page:
      You need the files:
      bme280.py mlx90614.py boot.py (replace the ssid and password with your own, or comment/uncomment lines to create an access point) main_mini.py (which you will have to rename to main.py before uploading to the esp board)  
    • By wimvb
      For quite some time now I've been working on a small weather station. The idea is to add automation to an obsy I'm building. The weather station as is measures temperature, humidity, pressure and presence of cloud. I also have the components to build a rain detector, but haven't implemented that yet.
      First the box:
      Made from vent covers and pieces of aluminium

      All put together

      With sensors. The IR sensor is in the far back (top of the housing) and the BME280 sensor is the free hanging red pcb. The other pcb holds a few pull-up resistors and a capacitor for the I2C wires. Insulation added to keep critters out.

      First I thought of using an Arduino to control and collect the data, but recently I started tinkering with ESP32 wifi boards. These are a lot faster and have more memory than Arduinos, and I wanted to use microPython.

      The ESP32 board is also smaller than an Arduino UNO (about the size of an Arduino nano) and has built in wifi, which means I just need power to the device.
      I uploaded the code to GitHub
      Output is as a HTML file (index.html) which presents data in a simple way. The INDI driver 'Weather Watcher' can read this file.
      For now, temperature is mapped to temperature (of course), and 'clouds' is mapped to 'forecast/Weather' in INDI. 'Clouds' is a parameter that varies from 0 to 1. I used the same criteria as the AAG Cloud Watcher device: if sky temperature is less than -8 degrees, the sky is assumed cloud free. For a sky temperature between -8 and 0 degrees, there is partial cloud, and for a sky temperature higher than 0 degrees, the sky is overcast. This seems very arbitrary, and I expect to have to adjust this piece of code later.

      Major update:
      The weather station now also reads and reports the SQM values from my wifi-SQM. 😋 See further down this thread for details.
    • By Captain Magenta
      Last year I was given a Unihedron SQM-L, the narrow field of view version of their gadget for measuring night-sky brightness. Since then, I’ve nipped outside to take zenith readings whenever I’ve been able, often a few times per night. As a result I now have 85 data-points, all from my back garden in Sunbury on Thames which rates a 19.04 on www.lightpollutionmap.info . As it turns out, this agrees well with the data I’ve collected.
      The darkest I’ve measured at this location has been 19.13, with 4 records better than 19.05 and 10 better than 19.00.
      Plotted against Moon altitude, it looks like:

      One thing I noticed very early on was that the reading generally gets darker and darker as the night goes on. The chart below suggests the data agrees, but how strongly I’m not adept enough yet with my statistics to work out. If anyone fancies doing this for me, I’d be grateful, I’ve attached the data .csv file I think to the end of this post.

      The data itself: each record contains date, time[GMT], SQM value, Moon phase, Moon altitude . For the purposes of my analysis, I’ve converted the time value into hoursafter6pm, which allows the intercept of the regression solution to be loosely considered as the “6pm starting point” for the darkness estimation, which is OK for this dataset as my data is all from this latest Autumn/Winter.
      I’ve done an “ordinary least-squares” regression with multiple input variables. At first glance it seems to me that the SQ vs altitude chart above should not behave well with that: there’s a clear kink, intuitively obvious I guess, at the point the Moon altitude goes negative.
      To cope with that, I divided my data into two and did three separate regressions: “Moon up” data, “Moon down”, and “All data” but treating phase and altitude as zero if the Moon is below -5 degrees (I chose -5 degrees arbitrarily).
      With Moon up, I decided the SQM value will depend on Time of Night, Moon Altitude and Phase. With Moon down, it only needs to depend on time of night.
      Thus my regression model is:
      SkyQual = a + b.timeafter6pm + c.phase + d.altitude + residual
      or rearranged
      residual = a + b.timeafter6pm + c.phase + d.altitude – SkyQual
      The analysis involves minimizing the sum of (the squares of the) residuals, by hunting around for the appropriate values of a, b, c & d which yields this minimum. I used MS Excel’s built-in Solver to do the “hunting around”.
      The following table summarizes the results:

      In words, using “Moon Up” as my subject, my Sky Quality, in magnitudes per arc-second, can be estimated as
      19.28 mags/arc-sec
      plus 0.0314 /hour
      minus 0.864 /full-phase (or 0.216 /quarter)
      minus 0.0186 /degree above horizon (or 0.186 /10 degrees).
      This is a pretty simple analysis. I’m sure there’s theory and formulae available relating Moon-altitude and -phase to extra sky brightness, but I haven’t used any of that here. And the “error model” I’ve used implicitly assumes that the relationships between SQM-reading and the variables are linear.
      If anyone is curious and wishes to do their own analysis, my raw-ish data is available as a .csv file attachment at the end of this post.
      A note about the data collection: each reading is an average of a few readings at a given time, with outliers rejected. For instance, often the first press yields an outlier, and over the following few seconds subsequent ones tend to settle down. So the series of readings 19.05 (me getting excited), 18.85, 18.86, 18.86 , which is a quite typical pattern, would cause me to record 18.86. My highest recorded reading, 19.13, was indeed where it settled down.
      Other “one-on-one” charts:
    • By Corpze
      So, finally my DIY arduino SQM is finalized, it is not calibrated yet, but hang in there, i will do so in the near future... But first i want to point out that i didn't want any scientific grade SQM but just a simple tool that i can use to compare different photo-sites around my home-town here in Sweden
      Feel free to Use it as you want to, if you wan't to calibrate it, change the value at: const float A = 22.0;
      More pictures and code are available at SGL's Yahoo-site.
      The parts needed for this is:
      Arduino approx. 30USD
      Light to freq-sensor: TSL237 - electrical component shop 5 USD
      0.1-0.01uF capacitator
      20 degree lens - ebay 1USD
      UV/IR-cut filter between the lens and the sensor - ebay 1 USD
      Some kind of housing and cables/connectors
      The lens is mounted to a plastic cover with superglue, the UV/IR filter is mounted underneath it and underneath that, the sensor.

      The sensor has three connectors, one gnd, one vdd and one signal, so it quiet simple to connect, you should use a capacitator to stabilize the +5v.
      Here is a video of it how it works (not the best quality i'm afraid.

      And here is the code:
      The libraries you need is at the top of the code.

      // Author: Daniel Sundström and Ola Karlsson, Arvika, Sweden

      #include <FreqMeasure.h>
      #include <Math.h>
      #include <LiquidCrystal.h>
      float Msqm;
      const float A = 22.0;
      int buttonSQM = A2;
      int val = 0;
      int reading = 0;
      int percentage = 0;
      LiquidCrystal lcd (12, 11, 10, 9, 7, 6);

      void setup() {

      pinMode(buttonSQM, INPUT_PULLUP);
      digitalWrite(buttonSQM, HIGH);
      double sum=0;
      int count=0;
      void loop() {
      val = digitalRead(buttonSQM);
      if (val == LOW) {
      reading = 1;
      while(reading) {

      if (FreqMeasure.available()) {
      // average several reading together
      sum = sum + FreqMeasure.read();
      count +=1;

      percentage = count/31.0*100.0;

      if (count > 30) {
      double frequency = F_CPU / (sum / count);
      sum = 0;
      count = 0;

      Msqm = A - 2.5*log10(frequency); //Frequency to magnitudes/arcSecond2 formula

      lcd.println("Mag/As2: ");
      reading = 0;
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.