概述
光電管是可以檢測光線的傳感器。它們體積小,價格便宜,功耗低,易于使用且不會磨損。因此,它們經常出現在玩具,小工具和家用電器中。它們通常被稱為CdS電池(它們由硫化鎘制成),光敏電阻器(LDR)和光敏電阻。
光電管基本上是一種電阻器,它會根據照射到彎曲表面上的光量來改變其電阻值(以歐姆Ω為單位)。它們的成本很低,很容易獲得許多尺寸和規格,但是它們很不準確。每個光電管傳感器的動作都將與其他光電管有所不同,即使它們來自同一批次。差異可能很大,高達50%或更高!因此,不應使用它們來確定勒克斯或毫坎德拉的精確照明水平。取而代之的是,您只能確定基本的燈光變化。
對于大多數對光敏感的應用程序,例如“它是亮還是暗”,“傳感器前是否有東西(會阻擋光)”,“是否有干擾的東西”激光束”(斷束傳感器),或“多個傳感器中的哪個具有最大的光束照射力”,光電管可能是一個不錯的選擇!
一些基本統計數據:這些統計數據用于Adafruit商店中的光電管,這與PDV-P8001非常相似。幾乎所有光電管的規格都略有不同,盡管它們的工作原理幾乎相同。如果有數據表,您將需要參考它。
尺寸:圓形,直徑5mm(0.2“)。(其他光電管的最大尺寸為12mm/0.4 “直徑!”
價格:在Adafruit商店中為1.00美元
電阻范圍:200KΩ(暗)到10KΩ(10勒克斯亮度)
靈敏度范圍: CdS電池對400nm之間的光產生響應(紫光) )和600nm(橙色)的波長,峰值約在520nm(綠色)。
電源:幾乎所有高達100V的電源,使用的功率都小于平均1mA的電流(取決于電源電壓)
數據表和另一個數據表
關于使用和選擇光電管的兩個應用筆記,其中幾乎所有這些圖形均來自
您可能會遇到多個傳感器的問題
如果在添加更多傳感器時發現讀數不一致,則表明將模擬讀數電路從一個引腳切換到另一個引腳時,傳感器之間會相互干擾。另一個。您可以通過延遲兩次閱讀并扔掉第一個來解決此問題。
有關更多信息,請參見此帖子
測量光
我們已經說過,光電池的電阻會隨著面部暴露于更多的光而發生變化。漆黑時,傳感器看起來像一個高達10MΩ的大電阻,隨著光線水平的增加,電阻會降低。該圖大致指示了傳感器在不同光照水平下的電阻。記住每個光電管會有所不同,因此僅用作指導!
請注意,該圖不是線性的,它是對數對數圖!
光電管,尤其是您可能會發現的常見CdS光電管,對所有光線都不敏感。特別是它們傾向于對700nm(紅色)和500nm(綠色)之間的光敏感。
基本上,藍光在觸發傳感器方面幾乎不及綠/黃光!
Lux到底是什么? 大多數數據表都使用lux來表示在某些光照水平下的電阻。但是什么是lux?它不是我們傾向于用來描述亮度的方法,因此很難測量。這是來自維基百科有關該主題的文章的表格!
tr》
IlluminanceExample
0.002 lux月夜晴朗的夜空
0.2 lux緊急照明的最小設計(AS2293)。
0.27-1 lux完整在晴朗的夜晚登月
3.4 lux晴朗的天空下市民暮光的黑暗極限
50 lux家庭起居室
80 lux走廊/廁所
100 lux陰暗的日子
300-500 lux晴天時的日出或日落。
1,000 lux陰天;典型的電視演播室照明
10,000-25,000 lux全日光(非直射陽光)
32,000-130,000 lux 直射陽光
測試光電管
確定光電管工作方式的最簡單方法是將電阻測量模式下的萬用表連接到兩條引線,并查看在用傳感器遮蔽傳感器時電阻如何變化您的手,關閉燈等。由于電阻變化很大,因此自動量程表在這里非常有效。否則,只需確保在“放棄”之前嘗試在1MΩ和1KΩ之間嘗試不同的范圍。
div》連接光電管
由于光電管基本上是電阻器,因此它們是無極性的。這意味著您可以“以任何一種方式”將它們連接起來,它們會正常工作!
光電管非常堅固,您可以輕松地將其焊接,夾住引線,將它們插入面包板,使用鱷魚夾等。您應該采取的措施是避免將導線直接彎曲在epoxi傳感器上,因為如果彎曲得太多,它們可能會折斷。
使用光電管
模擬電壓讀數方法最簡單的測量電阻式傳感器的方法是將一端連接到電源,另一端連接到下拉電阻到地。然后將固定下拉電阻器和可變光電管電阻器之間的點連接到微控制器的模擬輸入,例如Arduino(如圖所示)
i》
在此示例中,我顯示的是5V電源,但請注意,將其與3.3v電源一樣容易使用。在這種配置下,模擬電壓讀數的范圍為0V(接地)至大約5V(或與電源電壓大致相同)。
工作原理是,隨著光電管電阻的減小,光電管和下拉電阻的總電阻從600KΩ以上降至10KΩ。這意味著流過兩個電阻的電流增加,這又導致固定的10KΩ電阻兩端的電壓增加。
環境光,如……環境光(勒克斯)光電管電阻(Ω)LDR + R(Ω)通過LDR + R Rth上的電流
暗淡走廊0.1 lux600KΩ610KΩ0.008 mA0.1 V
月夜1 lux70KΩ80KΩ0.07 mA0.6 V
暗室10 lux10KΩ20KΩ0.25 mA2.5 V
陰暗天/明亮房間100 lux1.5KΩ11.5KΩ0.43 mA4.3 V
陰天1000 lux300Ω10.03KΩ0.5 mA5V
該表根據傳感器的光/電阻(帶有5V電源和10K)顯示了近似的模擬電壓 Ω下拉電阻。
如果您打算將傳感器安裝在亮區域并使用10KΩ下拉電阻,它會迅速飽和。這意味著它將達到5V的“上限”,并且無法區分有點亮和非常亮。在這種情況下,應將10KΩ下拉電阻替換為1KΩ下拉電阻。在這種情況下,它也將無法檢測暗級差異,但將能夠更好地檢測亮光差異。這是一個必須權衡的折衷方案。
您還可以使用“ Axel Benz”公式,首先用萬用表測量最小和最大電阻值,然后通過以下方法找到電阻器值:Pull-Down -Resistor = squareroot(Rmin * Rmax),這將為您提供更好的范圍計算
環境光,如……環境光(lux)光電管電阻(?)LDR + R(?)通過LDR + R R上的電壓
月夜1 lux70KΩ71KΩ0.07 mA0.1 V
暗室10 lux10KΩ11KΩ0.45 mA0.5 V
黑暗的陰天/明亮的房間100 lux1.5KΩ2.5KΩ2 mA2.0 V
陰天1000 lux300Ω1.3KΩ3.8 mA3.8 V
日光充足10,000 lux100Ω1.1KΩ4.5 mA4.5 V
該表基于傳感器的光/電阻(帶有5V電源和1K下拉電阻)顯示了近似模擬電壓。
請注意,我們的方法不提供相對于亮度的線性電壓!而且,每個傳感器都將不同。隨著光強度的增加,即使電阻降低,模擬電壓也會升高:
Vo = Vcc(R/(R + Photocell))
也就是說,電壓與光電池電阻的 反 成正比,而光電池電阻又與光強度成反比。
Arduino代碼
簡單的使用演示 此草圖將采用模擬電壓讀數,并以此來確定紅色LED的亮度。它越黑,LED越亮!請記住,LED必須連接到PWM引腳才能起作用,在本示例中,我使用引腳11。
i》
這些示例假設您知道一些基本的Arduino編程。如果您不這樣做,也許花一些時間在Arduino教程中回顧基礎知識?
下載:file
復制代碼
/* Photocell simple testing sketch.
Connect one end of the photocell to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
Connect LED from pin 11 through a resistor to ground
For more information see http://learn.adafruit.com/photocells */
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the sensor divider
int LEDpin = 11; // connect Red LED to pin 11 (PWM pin)
int LEDbrightness; //
void setup(void) {
// We‘ll send debugging information via the Serial monitor
Serial.begin(9600);
}
void loop(void) {
photocellReading = analogRead(photocellPin);
Serial.print(“Analog reading = ”);
Serial.println(photocellReading); // the raw analog reading
// LED gets brighter the darker it is at the sensor
// that means we have to -invert- the reading from 0-1023 back to 1023-0
photocellReading = 1023 - photocellReading;
//now we have to map 0-1023 to 0-255 since thats the range analogWrite uses
LEDbrightness = map(photocellReading, 0, 1023, 0, 255);
analogWrite(LEDpin, LEDbrightness);
delay(100);
} /* Photocell simple testing sketch.
Connect one end of the photocell to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
Connect LED from pin 11 through a resistor to ground
For more information see http://learn.adafruit.com/photocells */
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the sensor divider
int LEDpin = 11; // connect Red LED to pin 11 (PWM pin)
int LEDbrightness; //
void setup(void) {
// We’ll send debugging information via the Serial monitor
Serial.begin(9600);
}
void loop(void) {
photocellReading = analogRead(photocellPin);
Serial.print(“Analog reading = ”);
Serial.println(photocellReading); // the raw analog reading
// LED gets brighter the darker it is at the sensor
// that means we have to -invert- the reading from 0-1023 back to 1023-0
photocellReading = 1023 - photocellReading;
//now we have to map 0-1023 to 0-255 since thats the range analogWrite uses
LEDbrightness = map(photocellReading, 0, 1023, 0, 255);
analogWrite(LEDpin, LEDbrightness);
delay(100);
}
您可能要根據要檢測的光強范圍嘗試不同的下拉電阻!
模擬光測量的簡單代碼該代碼不執行任何操作計算時,它只是定性地打印出它解釋為光量的信息。對于大多數項目,這幾乎就是所有需要的東西!
下載:文件
復制代碼
/* Photocell simple testing sketch.
Connect one end of the photocell to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
For more information see http://learn.adafruit.com/photocells */
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider
void setup(void) {
// We‘ll send debugging information via the Serial monitor
Serial.begin(9600);
}
void loop(void) {
photocellReading = analogRead(photocellPin);
Serial.print(“Analog reading = ”);
Serial.print(photocellReading); // the raw analog reading
// We’ll have a few threshholds, qualitatively determined
if (photocellReading 《 10) {
Serial.println(“ - Dark”);
} else if (photocellReading 《 200) {
Serial.println(“ - Dim”);
} else if (photocellReading 《 500) {
Serial.println(“ - Light”);
} else if (photocellReading 《 800) {
Serial.println(“ - Bright”);
} else {
Serial.println(“ - Very bright”);
}
delay(1000);
} /* Photocell simple testing sketch.
Connect one end of the photocell to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
For more information see http://learn.adafruit.com/photocells */
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider
void setup(void) {
// We‘ll send debugging information via the Serial monitor
Serial.begin(9600);
}
void loop(void) {
photocellReading = analogRead(photocellPin);
Serial.print(“Analog reading = ”);
Serial.print(photocellReading); // the raw analog reading
// We’ll have a few threshholds, qualitatively determined
if (photocellReading 《 10) {
Serial.println(“ - Dark”);
} else if (photocellReading 《 200) {
Serial.println(“ - Dim”);
} else if (photocellReading 《 500) {
Serial.println(“ - Light”);
} else if (photocellReading 《 800) {
Serial.println(“ - Bright”);
} else {
Serial.println(“ - Very bright”);
}
delay(1000);
}
要測試它,我從一個陽光照射(但有陰影)的房間開始,用手覆蓋傳感器,然后用一塊遮光織物覆蓋。
獎金!讀取沒有模擬引腳的光電管由于光電管基本上是電阻器,因此即使您的微控制器上沒有模擬引腳(或者說您想連接的數量超過模擬輸入引腳),也可以使用它們。我們這樣做的方法是利用電阻器和電容器的基本電子特性。事實證明,如果您使用最初不存儲電壓的電容器,然后通過電阻器將其連接到電源(例如5V),則它將緩慢充電至電源電壓。電阻越大,速度越慢。
從示波器捕獲的該圖像顯示了數字引腳(黃色)上發生的情況。藍線表示草圖何時開始計數以及何時完成計算(大約1.2毫秒后)。
這是因為電容器的作用就像一個桶,電阻的作用就像一根細管。用一根很細的管子裝滿水桶需要花費足夠的時間,您可以通過計時將水桶裝滿一半的時間來確定管子的寬度。
在這種情況下,我們的“桶”是一個0.1uF的陶瓷電容器。您幾乎可以隨意更改電容器,但時序值也會改變。對于這些光電電池,0.1uF似乎是一個不錯的起點。如果要測量較亮的范圍,請使用1uF電容器。如果要測量較暗的范圍,請降低到0.01uF。
下載:文件
復制代碼
/* Photocell simple testing sketch.
Connect one end of photocell to power, the other end to pin 2.
Then connect one end of a 0.1uF capacitor from pin 2 to ground
For more information see http://learn.adafruit.com/photocells */
int photocellPin = 2; // the LDR and cap are connected to pin2
int photocellReading; // the digital reading
int ledPin = 13; // you can just use the ‘built in’ LED
void setup(void) {
// We‘ll send debugging information via the Serial monitor
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // have an LED for output
}
void loop(void) {
// read the resistor using the RCtime technique
photocellReading = RCtime(photocellPin);
if (photocellReading == 30000) {
// if we got 30000 that means we ’timed out‘
Serial.println(“Nothing connected!”);
} else {
Serial.print(“RCtime reading = ”);
Serial.println(photocellReading); // the raw analog reading
// The brighter it is, the faster it blinks!
digitalWrite(ledPin, HIGH);
delay(photocellReading);
digitalWrite(ledPin, LOW);
delay(photocellReading);
}
delay(100);
}
// Uses a digital pin to measure a resistor (like an FSR or photocell!)
// We do this by having the resistor feed current into a capacitor and
// counting how long it takes to get to Vcc/2 (for most arduinos, thats 2.5V)
int RCtime(int RCpin) {
int reading = 0; // start with 0
// set the pin to an output and pull to LOW (ground)
pinMode(RCpin, OUTPUT);
digitalWrite(RCpin, LOW);
// Now set the pin to an input and.。.
pinMode(RCpin, INPUT);
while (digitalRead(RCpin) == LOW) { // count how long it takes to rise up to HIGH
reading++; // increment to keep track of time
if (reading == 30000) {
// if we got this far, the resistance is so high
// its likely that nothing is connected!
break; // leave the loop
}
}
// OK either we maxed out at 30000 or hopefully got a reading, return the count
return reading;
} /* Photocell simple testing sketch.
Connect one end of photocell to power, the other end to pin 2.
Then connect one end of a 0.1uF capacitor from pin 2 to ground
For more information see http://learn.adafruit.com/photocells */
int photocellPin = 2; // the LDR and cap are connected to pin2
int photocellReading; // the digital reading
int ledPin = 13; // you can just use the ’built in‘ LED
void setup(void) {
// We’ll send debugging information via the Serial monitor
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // have an LED for output
}
void loop(void) {
// read the resistor using the RCtime technique
photocellReading = RCtime(photocellPin);
if (photocellReading == 30000) {
// if we got 30000 that means we ‘timed out’
Serial.println(“Nothing connected!”);
} else {
Serial.print(“RCtime reading = ”);
Serial.println(photocellReading); // the raw analog reading
// The brighter it is, the faster it blinks!
digitalWrite(ledPin, HIGH);
delay(photocellReading);
digitalWrite(ledPin, LOW);
delay(photocellReading);
}
delay(100);
}
// Uses a digital pin to measure a resistor (like an FSR or photocell!)
// We do this by having the resistor feed current into a capacitor and
// counting how long it takes to get to Vcc/2 (for most arduinos, thats 2.5V)
int RCtime(int RCpin) {
int reading = 0; // start with 0
// set the pin to an output and pull to LOW (ground)
pinMode(RCpin, OUTPUT);
digitalWrite(RCpin, LOW);
// Now set the pin to an input and.。.
pinMode(RCpin, INPUT);
while (digitalRead(RCpin) == LOW) { // count how long it takes to rise up to HIGH
reading++; // increment to keep track of time
if (reading == 30000) {
// if we got this far, the resistance is so high
// its likely that nothing is connected!
break; // leave the loop
}
}
// OK either we maxed out at 30000 or hopefully got a reading, return the count
return reading;
}
CircuitPython
使用CircuitPython及其內置的模擬輸入支持,很容易讀取光電管看到的光量。通過將光電管連接到電路板上的模擬輸入端,您可以從中讀取電壓,并查看其隨著擊中傳感器的光量的變化而發生的變化。
首先將光電管連接到電路板上顯示在上一頁的Arduino中。您需要使用 10千歐電阻器電路設置相同的分壓器,并將輸出饋送到板上的任何模擬輸入(請注意,沒有模擬輸入的讀取光電管的特殊方法不是
這是將光電管連接到Feather M0的示例:
板卡3.3V 到光電管的單腿 》(與哪條腿無關)。請注意,您要使用板上的電壓,該電壓與最大模擬輸入電壓相對應。對于Feather板,此電壓為3.3V,但對于其他板,該電壓可能更高或更低-請務必咨詢您的電路板文檔。
10千歐電阻器
板GND 到10千歐電阻器的另一端。
》
板A1 (或任何其他模擬輸入)連接到光電管和10千歐姆電阻的連接處。
下一步,連接到電路板的串行REPL,這樣您就可以在CircuitPython上運行》》》 提示。
現在導入電路板和模擬 》允許您讀取模擬輸入的模塊。確保還閱讀了CircuitPython模擬I/O指南,以獲取更多有關使用模擬輸入的背景信息!
下載:文件
復制代碼
import board
import analogio import board
import analogio
為連接到光電管的A1引腳創建模擬輸入,電阻連接點:
下載:文件
復制代碼
photocell = analogio.AnalogIn(board.A1) photocell = analogio.AnalogIn(board.A1)
在這一點上,您可以讀取value屬性以讀取光電管看到的光。嘗試:
下載:文件
復制代碼
photocell.value photocell.value
嘗試用手遮蓋光電管以阻擋可見光并再次讀取該值:
下載:文件
復制代碼
photocell.value photocell.value
請注意,值已更改!當傳感器看到的光線較少時,該值會減小。傳感器看到的光線越多,該值越高。
您可能會想,可能的值范圍是多少?事實證明,對于CircuitPython中的模擬輸入,最大值范圍是0到65535(或最大16位無符號整數值)。如果您在光電池上發出非常明亮的光,您可能會看到一個接近65k的值,如果完全阻塞了傳感器,您可能會看到一個接近0的值。
如果您好奇,還可以轉換取決于照射到傳感器的光量多少,此值將變為更高或更低的電壓。讓我們做一個函數來做到這一點:
下載:文件
復制代碼
def analog_voltage(adc):
return adc.value / 65535 * adc.reference_voltage
volts = analog_voltage(photocell)
print(‘Photocell voltage: {0}V’.format(volts)) def analog_voltage(adc):
return adc.value / 65535 * adc.reference_voltage
volts = analog_voltage(photocell)
print(‘Photocell voltage: {0}V’.format(volts))
酷!請注意,隨著擊中光電管的光的增加,電壓增加到接近3.3伏。如果將光電管蓋好并讀取電壓,您會發現它跌落到0伏附近。
您可以使用原始值或電壓來檢查有多少光照射到光電管上。兩者都將與照射到傳感器的光量成比例地變化。
這是一個完整的程序,可以讀取光電管的值并每秒打印一次值和電壓。將其另存為 main.py ,然后打開串行輸出以查看打印的值。嘗試將光照射到傳感器上或將其遮蓋起來,以查看值和電壓如何變化!
下載:文件
復制代碼
import time
import board
import analogio
# Initialize analog input connected to photocell.
photocell = analogio.AnalogIn(board.A1)
# Make a function to convert from analog value to voltage.
def analog_voltage(adc):
return adc.value / 65535 * adc.reference_voltage
# Main loop reads value and voltage every second and prints them out.
while True:
# Read the value, then the voltage.
val = photocell.value
volts = analog_voltage(photocell)
# Print the values:
print(‘Photocell value: {0} voltage: {1}V’.format(val, volts))
# Delay for a second and repeat!
time.sleep(1.0) import time
import board
import analogio
# Initialize analog input connected to photocell.
photocell = analogio.AnalogIn(board.A1)
# Make a function to convert from analog value to voltage.
def analog_voltage(adc):
return adc.value / 65535 * adc.reference_voltage
# Main loop reads value and voltage every second and prints them out.
while True:
# Read the value, then the voltage.
val = photocell.value
volts = analog_voltage(photocell)
# Print the values:
print(‘Photocell value: {0} voltage: {1}V’.format(val, volts))
# Delay for a second and repeat!
time.sleep(1.0)
這就是使用CircuitPython使用模擬輸入讀取光電管的全部內容!
責任編輯:wv
-
光電管
+關注
關注
0文章
49瀏覽量
12816
發布評論請先 登錄
相關推薦
航天級 100krad、125kHz 光電二極管跨阻放大器 (TIA) 電路應用簡介
![航天級 100krad、125kHz <b class='flag-5'>光電二極管</b>跨阻放大器 (TIA) 電路應用<b class='flag-5'>簡介</b>](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
什么是光電晶體管?光電晶體管的工作原理和結構
![什么是<b class='flag-5'>光電晶體管</b>?<b class='flag-5'>光電晶體管</b>的工作原理和結構](https://file1.elecfans.com/web2/M00/F6/A2/wKgZomaCgSmAZcwVAACJE-NrS5c176.png)
評論