Các cảm biến ánh sáng với Arduino – Điện Tử Hello

Cảm biến ánh sáng MAX44009

Cảm biến cường độ ánh sáng MAX44009 Digital Light Sensor được sử dụng để đo cường độ ánh sáng của môi trường tự nhiên xung quanh với độ đúng mực và độ không thay đổi cao, cảm biến trả ra giá trị cường độ ánh sáng Lux qua tiếp xúc I2C, thích hợp với những ứng dụng trong nông nghiệp, nhà mưu trí, đo cường độ sáng …
Module Cảm Biến Ánh Sáng MAX44009_Ánh Sáng_Cảm Biến_Module - Cảm Biến_ -  MinhHaGroup.Com

  • IC chính: MAX44009 từ hãng Maxim.
  • Điện áp sử dụng: 3.3~5VDC
  • Điện áp giao tiếp: TTL 3.3~5VDC
  • Tiêu thụ: ICC = 0.65µA 
  • Chuẩn giao tiếp: I2C
  • Cường độ ánh sáng đo được: 0.045~188,000 Lux (22 bit)
  • Kích thước module: 60 x 80mm
  • Schematic của module:

Cảm biến cường độ ánh sáng MAX44009 Digital Light Sensor

Code với Arduino Uno R3 :

#include
 
#define Addr 0x4A
 
void setup()
{
 
Wire.begin();
// Initialise serial communication
Serial.begin(9600);
 
Wire.beginTransmission(Addr);
Wire.write(0x02);
Wire.write(0x40);
Wire.endTransmission();
delay(300);
}
 
void loop()
{
unsigned int data[2];
Wire.beginTransmission(Addr);
Wire.write(0x03);
Wire.endTransmission();
 
// Request 2 bytes of data
Wire.requestFrom(Addr, 2);
 
// Read 2 bytes of data luminance msb, luminance lsb
if (Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
 
// Convert the data to lux
int exponent = (data[0] & 0xF0) >> 4;
int mantissa = ((data[0] & 0x0F) << 4) | (data[1] & 0x0F);
float luminance = pow(2, exponent) * mantissa * 0.045;
 
Serial.print("Ambient Light luminance :");
Serial.print(luminance);
Serial.println(" lux");
delay(500);
}

Kết quả trên hành lang cửa số Terminal của Arduino IDE :

Ambient Light luminance :4.59 lux
Ambient Light luminance :6.12 lux
Ambient Light luminance :6.12 lux
Ambient Light luminance :36.72 lux
Ambient Light luminance :36.72 lux
Ambient Light luminance :36.72 lux
Ambient Light luminance :73.44 lux
Ambient Light luminance :73.44 lux
Ambient Light luminance :73.44 lux
Ambient Light luminance :9.95 lux
Ambient Light luminance :9.95 lux
Ambient Light luminance :12.24 lux

Cảm biến ánh sáng BH1750 

Cảm biến cường độ ánh sáng Lux BH1750 được sử dụng để đo cường độ ánh sáng theo đơn vị lux, cảm biến có ADC nội và bộ tiền xử lý nên giá trị được trả ra là giá trị trực tiếp cường độ ánh sáng lux mà không phải qua bất kỳ xử lý hay tính toán nào thông qua giao tiếp I2C .

Module Đo Cường Độ Ánh Sáng BH1750- GY30 | Tiki.vn

Thông số kỹ thuật module

  • Nguồn: 3~5VDC
  • Giao tiếp: I2C
  • Khoảng đo: 1 -> 65535 lux
  • Kích cỡ: 21*16*3.3mm

GY-30 BH1750VI Cảm Biến Cường Độ Ánh Sáng, Nguồn: 3~5VDC, giao...

Một số ví dụ về độ rọi của ánh sáng:

  • Vào buổi tối : 0.001 – 0.02 Lux
  • Ánh trăng : 0.02 – 0.3 lux
  • Trời nhiều mây trong nhà : 5 – 50 lux
  • Trời nhiều mây ngoài trời : 50 – 500 lux
  • Trời nắng trong nhà : 100 – 1000 lux
  • Ánh sáng cần thiết để đọc sách: 50 – 60 lux

Kết nối với Arduino

Code :

#include 
#include  
int BH1750address = 0x23; //i2c address
 
byte buff[2];
void setup()
{
  Wire.begin();
  Serial.begin(57600);
}
void loop()
{
  int i;
  uint16_t val=0;
  BH1750_Init(BH1750address);
  delay(200);
  if(2==BH1750_Read(BH1750address))
  {
    val=((buff[0]<<8)|buff[1])/1.2;
    Serial.print(val,DEC);     
    Serial.println("lux"); 
  }
  delay(150);
}
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);//1lx reolution 120ms
  Wire.endTransmission();
}

Kết quả trên hành lang cửa số Terminal của Arduino IDE :

1070 lux
5006 lux
7427 lux
8200 lux
8996 lux
8656 lux
6569 lux
150 lux
5 lux
2 lux
2 lux
3 lux
2 lux
10 lux
38 lux
266 lux
259 lux

Cảm biến màu và ánh sáng TCS34725 

Cảm biến sắc tố TCS34725 tiếp xúc I2C và UART là phiên bản tăng cấp của cảm biến màu TCS3200, được sử dụng để phân biệt sắc tố bằng cách đo phản xạ 3 sắc tố cơ bản từ vật thể là đỏ, xanh lá và xanh dương sau đó giải quyết và xử lý và truyền thông số đo được của những màu này qua tiếp xúc I2C hoặc UART, tổng hợp thông tin của 3 màu trên ta có được sắc tố của vật thể cần đo .
Cảm biến sắc tố TCS34725 tiếp xúc I2C và UART có tích hợp MCU trên mạch để quy đổi từ tiếp xúc I2C của TCS34725 sang tiếp xúc UART hoặc I2C của MCU giúp dể dàng tiếp xúc và lập trình, ta hoàn toàn có thể thuận tiện lựa chọn tiếp xúc muốn sử dụng bằng cách Set những Jumper trên mạch .

  • IC chính: TCS34725
  • Điện áp sử dụng: 3~5VDC
  • Dòng tiêu thụ: 15mA
  • Giải màu sắc đo: RGB 0~255
  • Tích hợp MCU xử lý và chuyển đổi giao tiếp.
  • Giao tiếp có thể lựa chọn qua Jumper:
    • I2C của TCS34725.
    • I2C của MCU.
    • UART của MCU.
  • Kích thước: 24.3 x 26.7mm

Schematic :
Tcs34725 color sensor rgb color detect color sensing recognition switch  module color unit grove i2c m5stack® for arduino - products that work with  official arduino boards Sale - Banggood.com

Kết nối Arduino:

Code :
Thư viện : https://github.com/adafruit/Adafruit_TCS34725

#include 
#include "Adafruit_TCS34725.h"
 
/* Example code for the Adafruit TCS34725 breakout library */
 
/* Connect SCL to analog 5
Connect SDA to analog 4
Connect VDD to 3.3V DC
Connect GROUND to common ground */
 
/* Initialise with default values (int time = 2.4ms, gain = 1x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();
 
/* Initialise with specific int time and gain values */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
 
void setup(void) {
Serial.begin(9600);
 
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1);
}
 
// Now we're ready to get readings!
}
 
void loop(void) {
uint16_t r, g, b, c, colorTemp, lux;
 
tcs.getRawData(&r, &g, &b, &c);
colorTemp = tcs.calculateColorTemperature(r, g, b);
lux = tcs.calculateLux(r, g, b);
 
Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
Serial.println(" ");
}

Kết quả trên hành lang cửa số Terminal :

Color Temp: 4554 K – Lux: 379 – R: 1122 G: 831 B: 776 C: 1429
Color Temp: 3173 K – Lux: 181 – R: 475 G: 339 B: 272 C: 707
Color Temp: 3425 K – Lux: 224 – R: 604 G: 435 B: 364 C: 868
Color Temp: 2833 K – Lux: 1497 – R: 2983 G: 2240 B: 1461 C: 5723
Color Temp: 5847 K – Lux: 109 – R: 4109 G: 1327 B: 890 C: 5814
Color Temp: 2767 K – Lux: 460 – R: 4468 G: 1703 B: 1062 C: 6734
Color Temp: 4381 K – Lux: 463 – R: 1379 G: 1012 B: 938 C: 1789
Color Temp: 4276 K – Lux: 588 – R: 1464 G: 1136 B: 997 C: 2153
Color Temp: 3952 K – Lux: 646 – R: 1424 G: 1135 B: 933 C: 2350
Color Temp: 3528 K – Lux: 835 – R: 1713 G: 1362 B: 1036 C: 3101

Cảm biến TSL2561 

Cảm biến cường độ ánh sáng ( Lux ) TSL2561 được sử dụng để đo cường độ ánh sáng thường, hồng ngoại theo đơn vị chức năng lux với độ không thay đổi và độ đúng mực cao .

Càm biến tích hợp ADC nội và bộ tiền xử lý nên giá trị được trả ra là giá trị trực tiếp cường độ ánh sáng (lux) mà không phải qua bất kỳ xử lý hay tính toán nào thông qua giao tiếp I2C.

  1. IC chính: TSL2561
  2. Nguồn: 3.3~5VDC
  3. Dòng điện tiêu thụ: 0.6mA
  4. Đo được cường độ ánh sáng thường và hồng ngoại (IR).
  5. Giao tiếp: I2C mức TTL 3.3~5VDC
  6. Khoảng đo: 0.1 ~ 40.000 Lux
  7. Kích cỡ: 20 x 14mm

34TSL2561 LUMINOSITY SENSOR BREAKOUT INFRARED LIGHT SENSOR INTEGRATING SENSOR

Device Pin Arduino
GND GND
Vcc / 3.3 (or Vin on Adafruit modules) 3.3 or 5v
SCL D1
SDA D2
ADDR N/C
Int N/C

Code Arduino :
Thư viện : https://github.com/adafruit/Adafruit_TSL2561

#include 
#include 
#include 
 
 
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
 
 
void configureSensor(void)
{
  tsl.enableAutoRange(true);            /* Auto-gain ... switches automatically between 1x and 16x */
  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);      /* fast but low resolution */
}
 
 
void setup(void) 
{
  Serial.begin(9600);
  Serial.println("Light Sensor Test"); 
  Serial.println("");
 
  /* Initialise the sensor */
  if(!tsl.begin())
  {
    Serial.print("no TSL2561 detected!");
    while(1);
  }
 
  configureSensor();
 
}
 
 
void loop(void) 
{  
  /* Get a new sensor event */ 
  sensors_event_t event;
  tsl.getEvent(&event);
 
  /* Display the results (light is measured in lux) */
  if (event.light)
  {
    Serial.print(event.light); 
    Serial.println(" lux");
  }
  else
  {
    Serial.println("Sensor overload");
  }
  delay(500);
}

Kết quả trên hành lang cửa số Terminal của Arduino IDE :

349.00 lux
757.00 lux
892.00 lux
992.00 lux
1192.00 lux
1890.00 lux
3324.00 lux
4051.00 lux
2708.00 lux
314.00 lux
128.00 lux
105.00 lux
112.00 lux
108.00 lux

Có thể bạn quan tâm
© Copyright 2008 - 2016 Dịch Vụ Bách khoa Sửa Chữa Chuyên nghiệp.
Alternate Text Gọi ngay