New in the shop: GY-302

Hello everyone

many of you have certainly been involved in replicaling a weather station or DIY smart home devices. For this application, I would like to introduce you today to a new light sensor.

Until now, we had only one Photo diode on a breakout board as well as the Photodiode with LM393 and adjustable switching contact in our portofolio to measure the ambient brightness, now we finally have a light sensor that can not only distinguish light and dark, but also output values in Lux.

On our new GY-302 Sensor is located a BH1750 which reliably reproducible values can be Lux outputs. Thanks to the fixed voltage regulator used, raspberry, ESPs and Arduinos can operate smoothly.

 

Sure, this sensor module is not a calibrated laboratory measuring device, but these values can be used a lot more than with the usual KY sensors. During my tests with the sensor at home, I found that with the output values it is even possible to distinguish which lamp is lit in my living room.

The sensor BH1750 is quite common and accordingly several libraries are available. For both ESPEasy:

as well as Tasmota:

support this sensor chip.

Since it is a sensor with an I2C interface, only four connections are required, for today's application example we use a UNOR3:

Arduino UNITED Nations GY-302
Gnd Gnd
5v Vcc
A4 Sda
A5 Scl

 

Today we decided against the library from the library manager of the Arduino IDE, because changes in the resolution of the sensor did not lead to the desired result and have discovered a practical alternative:

Click here to go to the GitHub library of Warlocks.

There are many ways to load a library from Git into the IDE, we have shown one of them here.

We liked several things very much at this library, on the one hand the German commentary of the AS_BH1750.h particularly detailed and structured, on the other hand, the developer provides an example of an application with an LCD display right away.

After installing the library and the function test, you can use our sensors to LCD Shield and connect the SCL/SDA pins as usual, our "LightMeter" is ready.

Under Examples -> AS_BH1750 -> Light_Meter_LCD you will find the sketch, changes are not required.

Here again the supplied sample code:

 

#include <Wire.H>
#include <AS_BH1750.H>
#include <LiquidCrystal.H>

/* 
 * LightMeter_LCD
 * 
 * Version 1.2
 * Date: 05.08.2013
 * 
 * The program uses the BH1750 (conversion light sensor)
 * and displays the values in Lux on a 16x2 icon LCD.
 * 
 * Wiring (UNO, Nano...)
 * 
 * BH1750:
 * Sensor SCL pin on A5
 * Sensor SDA pin on A4
 * Sensor VDD pin to 5V
 * Sensor GND pin to GND
 * Sensor ADDR pin free
 *  
 * LCD in 4-bit mode:
 * LCD RS pin to digital pin 8
 * LCD RW pin to digital pin 13
 * LCD Enable pin to digital pin 9
 * LCD D4 pin to digital pin 4
 * LCD D5 pin to digital pin 5
 * LCD D6 pin to digital pin 6
 * LCD D7 pin to digital pin 7
 * 
 *
 * Copyright (c) 2013 Alexander Schulz.  All right reserved.
 *  
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

AS_BH1750 Lightmeter;

Setup LCD Shield
LiquidCrystal Lcd(8, 13, 9, 4, 5, 6, 7);

Void Setup() {   Initialize display   Lcd.Clear();    Lcd.Begin(16, 2); 16x2 characters   Lcd.setCursor(0,0);    Lcd.Print("LightMeter v1.0");    Lcd.setCursor(0,1);    Lcd.Print("Initializing...");    Delay(1000);   Lcd.Clear();   If(!Lightmeter.Begin()){     Check if sensor is present     Lcd.Clear();     Lcd.setCursor(0,0);      Lcd.Print("BH1750 not found");     Lcd.setCursor(0,1);      Lcd.Print("check wiring!");     while (1) {       Delay(1000);     }   }

}

Void Loop() {   Char clux[9];   Reading and reprocessing values   Float Lux = Lightmeter.readLightLevel();   dtostrf(Lux, 8, 1, clux);   Lcd.setCursor(0,0);    Lcd.Print("Light level: ");   Lcd.setCursor(5,1);    Lcd.Print(clux);   Lcd.Print("lx");   Delay(500);
}



 

Until the next post :)

 

 

ProduktvorstellungenSensoren

1 comment

Pohl, Michael

Pohl, Michael

Ich verwende den ESP32. Meine Frage: kann man über die I2C Schnittstelle ohne Probleme die Signale, die etwa 3.3V maximal sein dürfen, allgemein – d. h. auch für andere Sensoren über die I2C Schnittstelle – ohne Gefahr empfangen? Gibt es für den ESP32 entsprechende Libraries?
Mic

Leave a comment

All comments are moderated before being published