Arduino rise piece digital optical sensor 09-

Digital Light Sensor

Photoresistor light sensing element is used, but its relatively narrow sensing range, slow response and large outside interference. To receiving light, the need for more accurate digital lit sensor. This introduction using GY-30 module, a digital light BH1750 its onboard sensors for IC.

Optical sensor 1. Introduction

GY-30 based BH1750FVI chip module, IIC communication modules, built 16bit ADC converter, a digital output directly, light intensity range: 0 ~ 65525 lx, Lux "Lux, often abbreviated as lx" is the illuminance international units.

GY-30 Module

main feature

  • Built-in 16Bit ADC converter.
  • IIC communication protocol, direct digital output.
  • Power: 3 ~ 5V.
  • Range: 0 ~ 65535lx.
  • Does not distinguish between ambient light source, the spectral characteristics close to visual sensitivity.
  • On-board communication level conversion.

2. Experimental Materials

  • Uno R3 Development Board
  • Supporting USB data cable
  • Bread plate and supporting cables
  • Digital optical sensor module GY-30

3. Experimental Procedure

1. The schematic circuit diagram of a building.

VCC GY-30 module, GND are connected to the boards 5V, GND, module SDA, SCL development board are connected to A4, A5 pins ADD module pins are not connected.

Principle is shown below:

Experimental schematics

Physical connection is shown below:

Physical connection diagram

2. Create a new sketch, the following code replacement copies of the automatically generated code and save it.

/*
 * BH1750
 * 数字光照传感器实验
 */
 
#include <Wire.h> //IIC

int BH1750address = 0x23;
byte buff[2];
uint16_t val = 0;

void setup()
{
  Wire.begin();
  BH1750_Init(BH1750address);
  Serial.begin(9600);
}

void loop()
{
  if (2 == BH1750_Read(BH1750address))
  {
    if (buff[0] == 255 && buff[1] == 255)
    {
      val = 65535;
    } else {
      val = ((buff[0] << 8) | buff[1]) / 1.2; //芯片手册中规定的数值计算方式
    }

    Serial.print(val, DEC);
    Serial.println("[lx]");
  }
  delay(500);
}

int BH1750_Read(int address) 
{
  int i = 0;
  Wire.beginTransmission(address);
  Wire.requestFrom(address, 2);
  while (Wire.available())
  {
    buff[i] = Wire.read();  // receive one byte
    i++;
  }
  Wire.endTransmission();
  return i;
}

void BH1750_Init(int address)
{
  Wire.beginTransmission(address);
  Wire.write(0x10);
  Wire.endTransmission();
}

3. Development Board connector, and set the port number corresponding to the type of boards, for download.

Download

4. Experimental phenomenon

Open the port monitor, the program provided baud rate consistent 9600. The monitor will display the ambient light intensity, the light intensity can be changed by the shutter or irradiation module.

Experimental phenomena

Focus on micro-channel public number: TonyCode
the Arduino learning exchange group: 868 283 450

More, I welcome the attention of the public number. Sweep the micro-channel to follow the Fanger Wei code:
Micro channel scan code added public number: TonyCode

Published 63 original articles · won praise 250 · Views 230,000 +

Guess you like

Origin blog.csdn.net/TonyIOT/article/details/103304060