A Sky Brightness Meter

To follow on from my article regarding setting up the Wemos D1 Mini to work with the Arduino IDE I thought I'd experiment with the idea of a Sky Brightness Meter using a Light Dependent Resistor in a voltage divider with a 1Kohm resistor.

The Wemos board uses an ESP8266 microcontroller that contains built-in Wifi making it the perfect board for a remote device powered with Solar cells and lithium battery. The Wifi connects to a router nearby and sends the sampled Sky value to a web server that displays the sensor value.

The ESP8266 has a single 10 bit A2D input that gives a value from 0 to 1023. By connecting the 1Kohm resistor from the A2D input to ground and the LDR from the A2D input to 3.3Volts we should get a value of '1' in complete darkness and a value of around '600' in bright light. The LDR used in this project is about 200KOhms dark and 600Ohms in bright light.

The LDR sensor should be located inside a plastic tube that limits how much light gets onto the sensor otherwise ambient light could give false readings (from street lighting etc.)

I have been testing using the https://thingspeak.com/channels/581961 website with the soil moisture Arduino code provided by Mathworks.com. We need only add a Wifi AP name, password and the API Key provided from the ThingSpeak account. The sketch uploads every 30 minutes (or 1800 seconds). I recommend setting it to maybe 5 minutes (using a value of 300). The code provides a 'deep sleep' mode for the Arduino to minimise power usage. A link has to be connected on the Wemos board between 'RST' and 'D0' to enable the deep sleep wakeup.

Click HERE to download my modified sketch using a ThingSpeak account. You will need to add your Wifi information and your 'Key' from your own ThingSpeak account.

When the sketch starts it attempts to connect to the specified Wifi network. The serial monitor on the Arduino IDE can be used to monitor progress. The sketch then starts sending Sky Brightness measurements to the website.

The following is the text from the Arduino Serial Monitor window.

Connecting to WiFi
Connecting to WiFi
Sky Brightness = 422
Temperature = 21.00*C
Humidity = 61.00%
Connecting to ThingSpeak for update...
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 2
Connection: close
Status: 200 OK
X-Frame-Options: ALLOWALL
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE, PATCH
Access-Control-Allow-Headers: origin, content-type, X-Requested-With
Access-Control-Max-Age: 1800
ETag: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Cache-Control: max-age=0, private, must-revalidate
Set-Cookie: request_method=POST; path=/
X-Request-Id: 990b22c1-7d98-4f50-84ed-b0263ed4531b
X-Runtime: 0.062499
X-Powered-By: Phusion Passenger 4.0.57
Date: Wed, 26 Sep 2018 23:38:43 GMT
Server: nginx/1.9.3 + Phusion Passenger 4.0.57

Goodnight for 300 Seconds

17.09.2018. 05:12