I. List of components
Arduino Pro Mini
GY-30
Second, the wiring
Using IIC communication mode, GY-30VCC connect +5v,gnd grounding. GY-30 SDA, SCL respectively A4, A5
Third, the source code
#include <Wire.h>//GY-30//BH1750FVI//In ADDR ' L ' mode 7bit ADDR #define ADDR 0b0100011//ADDR ' h ' mode//#de
Fine ADDR 0b1011100 void Setup () {//Put your setup code here, to run Once:Serial.begin (9600); while (! Serial) {;//wait for Serial port to connect.
Needed for Leonardo only} wire.begin ();
Wire.begintransmission (ADDR);
Wire.write (0b00000001);
Wire.endtransmission ();
} void Loop () {//Put your main code here, to run repeatedly:int val = 0;
Reset Wire.begintransmission (ADDR);
Wire.write (0b00000111);
Wire.endtransmission ();
Wire.begintransmission (ADDR);
Wire.write (0b00100000);
Wire.endtransmission ();
Typical read delay 120ms delay (120); Wire.requestfrom (ADDR, 2); 2byte every time for (val = 0; Wire.available () >= 1;
) {char c = wire.read ();
Serial.println (c, HEX);
val = (Val << 8) + (C & 0xFF);
} val = val/1.2;
Serial.print ("LX:");
Serial.println (Val); Serial.printlN ("OK");
Delay (100); }