Saturday, 22 July 2017

Working light sensor, ready for write-up

This follows on from Optimisation of the light sensor.

My light sensor is now completely working. :-) (With quite a big bug fix from Tim - the wires were in the wrong place and the code was wrong. Oh well.)

This is the code:

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

#include "rgb_lcd.h"

rgb_lcd lcd;

const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

BH1750 lightMeter;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  lcd.setRGB(colorR, colorG, colorB);

  // Print a message to the LCD.
  lcd.print("Light intensity");

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

  // Clear the bottom line of the LCD
  lcd.print("          ");

  // For LCD: set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset: