TSL 2561 luxsensor



LUX sensor (lichtintensiteit sensor), type: BH1750 - type GY-30

leverancier: banggood.com




link: https://github.com/claws/BH1750






DOWNLOAD EERST DE BIJBEHORENDE LIBRARY: https://github.com/claws/BH1750


voorbeeldcode 1:

/*
  Example of BH1750 library usage.
  This example initialises the BH1750 object using the default high resolution
  continuous mode and then makes a light level reading every second.
  Connection:
    VCC -> 3V3 or 5V
    GND -> GND
    SCL -> SCL (A5 on Arduino Uno, Leonardo, etc or 21 on Mega and Due, on esp8266 free selectable)
    SDA -> SDA (A4 on Arduino Uno, Leonardo, etc or 20 on Mega and Due, on esp8266 free selectable)
    ADD -> (not connected) or GND
  ADD pin is used to set sensor I2C address. If it has voltage greater or equal to
  0.7VCC voltage (e.g. you've connected it to VCC) the sensor address will be
  0x5C. In other case (if ADD voltage less than 0.7 * VCC) the sensor address will
  be 0x23 (by default).
*/

#include <Wire.h>
#include <BH1750.h>
BH1750 lightMeter;

void setup(){
Serial.begin(9600);
// Initialize the I2C bus (BH1750 library doesn't do this automatically)
Wire.begin();
// On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);
lightMeter.begin();
Serial.println(F("BH1750 Test begin"));
}

void loop() {
uint16_t lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);
}



--------



aansluitschema: TSL2561


voorbeeldcode 2:

#include 
#include "TSL2561.h"


// verbind SCL aan ingang analog 5
// verbind SDA aan ingang analog 4
// verbind VDD aan 3.3V 
// verbind GND (GROUND to common ground
// ADDR can be connected to ground, or vdd or left floating to change the i2c address
TSL2561 tsl(TSL2561_ADDR_FLOAT); 

void setup(void) {

  Serial.begin(9600);
  if (tsl.begin()) {
    Serial.println("sensor gevonden");
  } else {
    Serial.println("geen sensor gevonden!");
    while (1);
  }
  delay(1000);
  tsl.setGain(TSL2561_GAIN_16X);      
  tsl.setTiming(TSL2561_INTEGRATIONTIME_13MS);  
    }

void loop(void) {

  uint32_t lum = tsl.getFullLuminosity();
  uint16_t ir, full;
  ir = lum >> 16;
  full = lum & 0xFFFF;
  Serial.print("aantal Lux: "); Serial.println(tsl.calculateLux(full, ir));
if (full< 100) Serial.print ("Led on"); // maak hier je eigen aanpassing... 
  delay(1000); 
}

library download:  https://github.com/claws/BH1750

 

leveranciers:  TSL 2561 Adafruit: https://www.adafruit.com/product/439

magazijn:  ladekastje 3:52