14.2.TEMT6000明るさセンサーによる照度計測
プロジェクト概要
SparkfunのTEMT6000明るさセンサモジュールを使用し、明るさを計測するプロジェクトです。光センサーは現代においてあらゆる種類の実用的な用途があり、最も顕著なのは、画面の明るさを自動調整するデバイスや、露出を調整するデジタルカメラです。TEMT6000 は照度(ルクス (lx)で測定されます。
SIG Output Voltage from the divider circuit
GND GND (0V)
VCC Collector Voltage (should not exceed 6V)
ルクスlxへの計算は、まず、センサー電圧から、センサー内部抵抗の電流マイクロアンペアを求めます。TEMT6000データシートには、照度lxとコレクタ電流の関係を示すグラフがあり、そのグラフから式を計算できます。式は
lx = uA*2
です。したがって、変換プログラムは以下となります。
float adVolt = (float)adc_read() * ConversionFactor;
float amps = adVolt/10000.0f; // across 10k Ohms
float microamps = amps * 1000000.0f;
float lux = microamps * 2.0f;
部品リスト
TEMT6000 Ambient Lightセンサー 1 スイッチサイエンス
GROVEの16 x 2 LCD 1 スイッチサイエンス
配線図

ソースリスト
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pico/stdlib.h"
#include "hardware/adc.h"
#include "hardware/i2c.h"
#include "hardware/rtc.h"
//#define PICO_DEFAULT_LED_PIN 25
#define LED_PIN PICO_DEFAULT_LED_PIN
#define I2C_PORT i2c0
#define I2C_SDA 8
#define I2C_SCL 9
#define ADC0_PIN 26
//set up --------------------
//adc ------------------------------
//rtc -----------------------------------
//lcd -------------------------------
//TEMT6000 ---------------------
float ReadTemtAmbientLight ()
{
adc_select_input(0);
float adVolt = (float)adc_read() * ConversionFactor;
float amps = adVolt/10000.0f; // across 10k Ohms
float microamps = amps * 1000000.0f;
float lux = microamps * 2.0f;
return lux;
}
int main()
{
stdio_init_all();
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
gpio_put(LED_PIN, 0);
i2c_init(I2C_PORT, 400*1000);
gpio_set_function(I2C_SDA, GPIO_FUNC_I2C);
gpio_set_function(I2C_SCL, GPIO_FUNC_I2C);
gpio_pull_up(I2C_SDA);
gpio_pull_up(I2C_SCL);
WaitTerminalStartup(30*1000);
printf("\nTerminal connected\n");
ScanI2CBus();
printf("I2C Scan completed\n");
lcd_init();
InitAdc();
InitRtc();
char buf[128];
datetime_t nowdt;
int presec = -1;
while (1) {
rtc_get_datetime(&nowdt);
if(presec != nowdt.sec)
{
float lux = ReadTemtAmbientLight ();
sprintf(buf, "%02d/%02d %02d:%02d:%02d",
nowdt.month, nowdt.day, nowdt.hour,nowdt.min, nowdt.sec);
lcd_set_cursor(0, 0);
lcd_string(buf);
sprintf(buf, " Light:%5.1flx", lux);
lcd_set_cursor(1, 0);
lcd_string(buf);
printf("%4d/%02d/%02d %02d:%02d:%02d Light:%5.1flx\n",
nowdt.year, nowdt.month, nowdt.day,
nowdt.hour,nowdt.min, nowdt.sec, lux);
}
presec = nowdt.sec;
sleep_ms(200);
}
return 0;
}

コメントをお書きください