Guest User

Untitled

a guest
Jan 18th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <Wire.h>
  2.  
  3. int BH1750_address = 0x23; // i2c Addresse(OPEN or connecting to GND)
  4. //int BH1750_address = 0x5c; // i2c Addresse(connecting to Vcc)
  5. byte buff[2];
  6.  
  7. void setup() {
  8.  
  9. Wire.begin();
  10. BH1750_Init(BH1750_address);
  11.  
  12. delay(200);
  13. Serial.begin(115200);
  14. Serial.println("Starte Beleuchtungsstaerkemessung - blog.simtronyx.de");
  15. }
  16.  
  17. void loop() {
  18.  
  19. float valf = 0;
  20.  
  21. if (BH1750_Read(BH1750_address) == 2) {
  22.  
  23. valf = ((buff[0] << 8) | buff[1]) / 1.2;
  24.  
  25. if (valf < 0)Serial.print("> 65535");
  26. else Serial.print((int)valf, DEC);
  27.  
  28. Serial.println(" lx");
  29. }
  30. delay(1000);
  31. }
  32.  
  33. void BH1750_Init(int address) {
  34.  
  35. Wire.beginTransmission(address);
  36. Wire.write(0x10); // 1 [lux] aufloesung
  37. Wire.endTransmission();
  38. }
  39.  
  40. byte BH1750_Read(int address) {
  41.  
  42. byte i = 0;
  43. Wire.beginTransmission(address);
  44. Wire.requestFrom(address, 2);
  45. while (Wire.available()) {
  46. buff[i] = Wire.read();
  47. i++;
  48. }
  49. Wire.endTransmission();
  50. return i;
  51. }
Add Comment
Please, Sign In to add comment