Arduino Learning Diary-Using GY-30 light sensor

Source: Internet
Author: User

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); }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.