File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
Project 9-Sensor Cahaya BH1750 GY-302 dengan LCD 16x2 i2c Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < Wire.h>
2+ #include < BH1750.h>
3+ BH1750 lightMeter;
4+ void setup (){
5+ Serial.begin (9600 );
6+ Wire.begin ();
7+ lightMeter.begin ();
8+ Serial.println (F (" BH1750 Test" ));
9+ }
10+ void loop () {
11+ float lux = lightMeter.readLightLevel ();
12+ Serial.print (" Light: " );
13+ Serial.print (lux);
14+ Serial.println (" lx" );
15+ delay (1000 );
16+ }
Original file line number Diff line number Diff line change 1+ #include < Wire.h>
2+ #include < BH1750.h>
3+ #include < LiquidCrystal_I2C.h> // memasukan library LCD
4+ BH1750 lightMeter;
5+ LiquidCrystal_I2C lcd (0x27 , 16 , 2 ); // alamat didapat dari i2c scanner
6+ void setup (){
7+ Serial.begin (9600 ); // Initialize the I2C bus (BH1750 library doesn't do this automatically)
8+ // On esp8266 devices you can select SCL and SDA pins using Wire.begin(D4, D3);
9+ Wire.begin ();
10+ lightMeter.begin ();
11+ Serial.println (F (" BH1750 Test" ));
12+ // Inisialisasi LCD menyalakan backlight LCD,
13+ lcd.init ();
14+ lcd.backlight ();
15+ lcd.setCursor (0 ,0 );
16+ lcd.print (" DHEA MULQI" ); // pada baris pertama
17+ lcd.setCursor (0 ,1 );
18+ lcd.print (" AMALIA HAIDY" ); // pada baris pertama
19+ lcd.setCursor (0 ,2 );
20+ lcd.print (" Light Meter(BH1750)" ); // pada baris kedua dituliskan LCD + BH1750
21+ delay (5000 ); // Waktu jeda
22+ lcd.clear ();
23+ }
24+ void loop () {
25+ float lux = lightMeter.readLightLevel ();
26+ Serial.print (" Light: " );
27+ Serial.print (lux);
28+ Serial.println (" lx" );
29+ lcd.setCursor (0 ,0 );
30+ lcd.print (" Light Meter" );
31+ lcd.setCursor (0 ,1 );
32+ lcd.print (" Light: " ); // prosedur pemanggilan hari
33+ lcd.setCursor (0 ,1 );
34+ lcd.print (" Light: " ); // prosedur pemanggilan hari
35+ lcd.setCursor (7 ,1 );
36+ lcd.print (lux);
37+ lcd.print (" lux" );
38+ }
You can’t perform that action at this time.
0 commit comments