Things used in this project

Hardware components:
Ard nano
Arduino Nano R3
×1
Pmod oledrgb  10258.1456867065.1280.1280
Digilent Pmod OLEDrgb
×1
BH1750-Digital Light intensity Sensor
×1
11026 02
Jumper wires (generic)
×12
Software apps and online services:
Ide web
Arduino IDE

Schematics

Ambient Light Meter - Schema
2 hardware setup e1505962513790 xvx1ez3ocy

Code

Ambient Light MeterC/C++
include "U8glib.h"
 
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0);
 
int BH17_add = 0x23; // I2C address of BH1750
 
byte buff[2];
 
 
void setup() {
 
Wire.begin();
 
BH750_Init(BH17_add);
 
delay(200);
 
}
 
 
void light() {
 
float valf = 0;
 
u8g.setFont(u8g_font_unifont);
 
u8g.setPrintPos(0, 50);
 
if (BH1750_Read(BH17_add) == 2) {
 
valf = ((buff[0] << 8) | buff[1]) / 1.2;
 
if (valf < 0)u8g.print("> 65535");
 
else
 
u8g.setPrintPos(0, 20);
 
u8g.print("Ambient"); // Custom Text
 
u8g.setPrintPos(0, 30);
 
u8g.print("--------------");
 
u8g.setPrintPos(0, 40);
 
u8g.print("Light Meter"); // Custom Text
 
u8g.setPrintPos(0, 60);
 
u8g.print((int)valf, DEC);
 
u8g.print(" LX/SI"); //
 
}
 
delay(100);
 
}
 
 
 
 
void loop() {
 
u8g.firstPage();
 
do {
 
light();
 
} while (u8g.nextPage());
 
 
 
 
}
 
 
 
 
void BH750_Init(int address) {
 
Wire.beginTransmission(address);
 
Wire.write(0x10);
 
Wire.endTransmission();
 
}
 
 
 
 
byte BH1750_Read(int address) {
 
byte i = 0;
 
Wire.beginTransmission(address);
 
Wire.requestFrom(address, 2);
 
while (Wire.available()) {
 
buff[i] = Wire.read();
 
i++;
 
}
 
Wire.endTransmission();
 
return i;
 
}

Credits

9997193f54ec3f58385b89fdc9dec40f l7hnxpkwuk
Bert Bill
2 projects • 2 followers
Learn And Die
Contact

Comments

Add projectSign up / Login