V predchádzajúcom článku som ukázal moj prenosný luxmeter. Kedže mi prišiel nový senzor pre meranie dopadajúceho svetla v rozsahu
188 mikroluxov až 88000 luxov, využil som ho na meranie svetelného znečistenia počas noci a pridal som senzor HTU21D pre meranie teploty a vlhkosti. Merá s presnosťou ±0.3 °C teplotu a ±2 % relatívnu vlhkosť.
Link na projekt https://www.instructables.com/id/Portab ... Observers/
Nočné znečistenie je svetlo z lámp, áut, domov, obrovských lcd panelov v meste a z každého svetla vyrobeného človekom. Pre pozorovateľov je umelé svetlo hlavným problémom vidieť hviezdy z mesta a musia ísť mimo mesto. Pre človeka je vysoké znečistenie svetlom škodlivé. A tiež pre stromy, trávu a zvieratá.
Pre potreby svetelného znečistenia meriam iba luxy a vypočítavam z toho magnitúdu na oblúkovu sekundu (mag / arsec2)
Platí rovnosť
1 cd / m2 = 1 lux
Pre výpočet mag / arcsec2 využívam vzťah:
[hodnota v mag / arcsec2] = Log10 ([hodnota v cd / m2] / 108000) / - 0,4
Zdroj: unihedron.com/projects/darksky/magconv.php
BOM
https://cdn.instructables.com/FHD/8BPC/ ... &width=525
Pre tento projekt potrebujete:
1. WEMOS D1 Mini alebo akýkoľvek mikrokontrolér
(Používam wemos, pretože je najmenší, s portom USB môžete vyskúšať Arduino Nano)
https://www.aliexpress.com/item/3265174 ... e6aa5ae2d2
https://www.aliexpress.com/item/3264419 ... e6aa5ae2d2
https://www.aliexpress.com/item/3265125 ... e6aa5ae2d2
USB kábel na programovanie a nahrávanie kódu do wemos
https://www.aliexpress.com/item/3283393 ... e6aa5ae2d2
2. Senzor TSL2591
https://www.aliexpress.com/item/3301267 ... e6aa5ae2d2
https://www.aliexpress.com/item/3299661 ... e6aa5ae2d2
https://www.aliexpress.com/item/3301530 ... e6aa5ae2d2
3. Snímač teploty a vlhkosti HTU21D
https://www.aliexpress.com/item/3248017 ... e6aa5ae2d2
https://www.aliexpress.com/item/3278728 ... e6aa5ae2d2
4. OLED displej 0,96 (128 x 64)
https://www.aliexpress.com/item/3283585 ... e6aa5ae2d2
https://www.aliexpress.com/item/3298193 ... e6aa5ae2d2
https://www.aliexpress.com/item/3283052 ... e6aa5ae2d2
5. Batéria 18650
https://www.aliexpress.com/item/3300200 ... e6aa5ae2d2
https://www.aliexpress.com/item/3302701 ... e6aa5ae2d2
držiak batérie 18650
https://www.aliexpress.com/item/3290490 ... e6aa5ae2d2
6. Nabíjací modul TP4056
https://www.aliexpress.com/item/3279783 ... e6aa5ae2d2
https://www.aliexpress.com/item/3267080 ... e6aa5ae2d2
7. prepínacie tlačidlá alebo prepojovacie mostíky
swtich red dip
https://www.aliexpress.com/item/3270071 ... e6aa5ae2d2
Switchers, veľa rôznych
https://www.aliexpress.com/item/3285920 ... e6aa5ae2d2
8. káble na dosku a dupont kable
https://www.aliexpress.com/item/3291473 ... e6aa5ae2d2
sada
https://www.aliexpress.com/item/3226872 ... e6aa5ae2d2
9. červená páska
https://www.aliexpress.com/item/3292829 ... e6aa5ae2d2
Prusa 3D tlačiareň, dúfam, že raz urobím puzdro z plastu: D
https://www.aliexpress.com/item/3297598 ... e6aa5ae2d2
Obvod:
Kód:
Stiahni radsej, nez kopiruj zo stranky.
Kód: Vybrat vše
//https://lastminuteengineers.com/oled-display-arduino-tutorial/<br>//http://javl.github.io/image2cpp/
// mcd to magnitude <a href="http://unihedron.com/projects/darksky/magconv.php?ACTION=SOLVEMAGS&txtCDM2=0.1" rel="nofollow"> http://unihedron.com/projects/darksky/magconv.php...</a>
// The HD44780 is a controller for character-based liquid crystal displays (LCDs). <a href="https://www.quinapalus.com/hd44780udg.html" rel="nofollow"> http://unihedron.com/projects/darksky/magconv.php...</a>
#include <Wire.h><p>#include <Fonts/FreeSerif9pt7b.h></p>#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include "Adafruit_HTU21DF.h"
#include "Adafruit_TSL2591.h"
int counter;
// OLED display TWI address
#define OLED_ADDR 0x3C
Adafruit_SSD1306 display(-1); // - 1 for restart display with restart button on arduino board
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
uint32_t lum;
uint16_t ir, full;
int ulux;
float lux;
float temp;
float rel_hum;
float mag_arcsec2; // visual mags/arcsecond² [value in mag/arcsec2] = Log10([value in cd/m2]/108000)/-0.4
// symbols
// degree for Celsius
const unsigned char degree [] PROGMEM =
{
0xe,0x11,0x11,0x11,0xe,0x0,0x0,0x0
};
// exponent 2
const unsigned char exponent [] PROGMEM =
{
0xe,0x1b,0x3,0x6,0xc,0x18,0x1f,0x0
};
// 'moon_logo', 128x64px
const unsigned char intro [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x03, 0xff, 0xc0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x07, 0xff, 0xe0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x07, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x0f, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x0f, 0xff, 0x77, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x1f, 0xbe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x1f, 0xcc, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x3f, 0xc0, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x3f, 0xc0, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x3f, 0xe0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x3f, 0x80, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x3f, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x3f, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x3f, 0xf9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x3f, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe0, 0x18, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe0, 0x60, 0xff, 0xff, 0xff, 0xff, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xe1, 0xe7, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x18, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x0f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x38, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x0f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x48, 0x7f, 0xff, 0xff, 0xff, 0xc0, 0x1f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x80, 0x3f, 0xff, 0xff, 0xff, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0xc4, 0x1f, 0xff, 0xff, 0xfc, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x60, 0x0f, 0xff, 0xff, 0xff, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0xf0, 0x03, 0xff, 0xff, 0xff, 0xf0, 0x07, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xf0, 0xe3, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x01, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x43, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x4f, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x5f, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x3f, 0xff, 0xff, 0x87, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x03, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x01, 0xff, 0xff, 0xb7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfc, 0x01, 0x0f, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfc, 0x01, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x01, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x7f, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x1f, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
void setup() {
// htu21d
htu.begin();
// tsl2591
sensor_t sensor;
tsl.getSensor(&sensor);
tsl.setGain(TSL2591_GAIN_MAX); // MAX, HIGH MED,LOW,
tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // 100MS, 200 MS, 300MS, 400MS,500MS, 600MS
// setup for oled display
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();
display.display();
display.drawBitmap(0, 0, intro, 128, 64, WHITE);
display.display();
delay(1000);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setFont(&FreeSerif9pt7b);
display.clearDisplay();
}
void loop() {
lux = 0;
ulux =0;
mag_arcsec2=0;
temp=0;
rel_hum=0;
delay(100);
lum = tsl.getFullLuminosity();
ir = lum >> 16;
full = lum & 0xFFFF;
delay(100);
lux = tsl.calculateLux(full, ir); // light intensiti in microlux
ulux= lux*1000000;
if (ulux<0)
{
ulux=0;
}
mag_arcsec2 = log10(lux/108000)/-0.4; //(log((ulux/108000) ) /(-0.4)
temp = htu.readTemperature();
rel_hum = htu.readHumidity();
display_values();
}
void display_values()
{
//display.drawPixel(120, 50, WHITE);
display.clearDisplay();
display.setCursor(1, 15);
display.print(temp);
display.drawBitmap(42, 2, degree, 8,5 , WHITE);
display.setCursor(50, 15);
display.print("C");
display.setCursor(70, 15);
display.print(rel_hum);
display.setCursor(114, 15);
display.print("%");
display.drawLine(1, 20, 127, 20, WHITE);
display.drawLine(67, 1, 67, 20, WHITE);
display.setCursor(1, 35);
display.print("ulux =");
display.setCursor(50, 35);
display.print(ulux);
display.setCursor(1, 55);
display.print("mag/arsec");
display.drawBitmap(70, 45, exponent, 8,8 , WHITE);
display.setCursor(83, 55);
display.print(mag_arcsec2);
display.display();
}