BH1750Simple.ino 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Example of AS_BH1750 library usage.
  3. *
  4. * This example initalises the BH1750 object using the default
  5. * adaptive auto-high-resolution mode and then makes
  6. * a light level reading about every second.
  7. * (the sensitivity and resolution are automatically adapted
  8. * the current light conditions)
  9. *
  10. * Wiring:
  11. * VCC-5v
  12. * GND-GND
  13. * SCL-SCL(analog pin 5)
  14. * SDA-SDA(analog pin 4)
  15. * ADD-NC or GND
  16. *
  17. * Copyright (c) 2013 Alexander Schulz. All right reserved.
  18. *
  19. * This program is free software: you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation, either version 3 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. */
  32. #include <Wire.h>
  33. #include <AS_BH1750.h>
  34. AS_BH1750 sensor;
  35. void setup(){
  36. Serial.begin(9600);
  37. delay(50);
  38. // for normal sensor resolution (1 lx resolution, 0-65535 lx, 120ms, no PowerDown) use: sensor.begin(RESOLUTION_NORMAL, false);
  39. // Initialize sensor. if sensor is not present, false is returned
  40. if(sensor.begin()) {
  41. Serial.println("Sensor initialized");
  42. }
  43. else {
  44. Serial.println("Sensor not present");
  45. }
  46. /*
  47. // to check the sensor present
  48. if(sensor.isPresent()) {
  49. Serial.println("Sensor present");
  50. }
  51. else {
  52. Serial.println("Sensor not present");
  53. }*/
  54. }
  55. void loop() {
  56. float lux = sensor.readLightLevel();
  57. Serial.print("Light level: ");
  58. Serial.print(lux);
  59. Serial.println(" lx");
  60. delay(1000);
  61. }