五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

ESP32 光敏傳感器實驗

2023-06-15 08:29 作者:南冥的鳥  | 我要投稿

1.1 項目介紹:??????????????????????????????????????????????????????????????????

光敏傳感器它對環(huán)境光線最敏感,S輸出一個模擬信號,一般用來檢測周圍環(huán)境的光線的亮度,觸發(fā)單片機或繼電器模塊等。傳感器自帶2個定位孔,方便你將傳感器固定在其他設(shè)備。

相關(guān)資料下載鏈接:https://sourl.cn/YxyUvG


1.3連接 ?? ? ? ? ??

?


1.4測試代碼?

Arduino IDE測試程序

//**********************************************************************************

/* ?

?* Filename ???: Photoresistance

?* Description : Read the basic usage of ADC,DAC and Voltage

?* Auther ?????: http//www.keyestudio.com

*/

#define PIN_ANALOG_IN ?34 ?//the pin of the Photoresistance

void setup() {

??Serial.begin(9600);

}

//In loop(),the analogRead() function is used to obtain the ADC value,

//and then the map() function is used to convert the value into an 8-bit precision DAC value.

//The input and output voltage are calculated according to the previous formula,

//and the information is finally printed out.

void loop() {

??int adcVal = analogRead(PIN_ANALOG_IN);

??int dacVal = map(adcVal, 0, 4095, 0, 255);

??double voltage = adcVal / 4095.0 * 3.3;

??Serial.printf("ADC Val: %d, \t DAC Val: %d, \t Voltage: %.2fV\n", adcVal, dacVal, voltage);

??delay(200);

}

//**********************************************************************************

?

Thonny?IDE測試程序

# Import Pin, ADC and DAC modules.

from machine import ADC,Pin,DAC

import time

?

# Turn on and configure the ADC with the range of 0-3.3V

adc=ADC(Pin(34))

adc.atten(ADC.ATTN_11DB)

adc.width(ADC.WIDTH_12BIT)

?

# Read ADC value once every 0.1seconds, convert ADC value to DAC value and output it,

# and print these data to “Shell”.

try:

????while?True:

????????adcVal=adc.read()

????????dacVal=adcVal//16

????????voltage = adcVal / 4095.0 * 3.3

????????print("ADC Val:",adcVal,"DACVal:",dacVal,"Voltage:",voltage,"V")

????????time.sleep(0.1)

except:

????pass

?

1.5測試結(jié)果 ??????????????????????????????????????????

按照實驗接線圖連接好線,編譯并上傳代碼到ESP32,代碼上傳成功后,利用USB線上電后,打開串口監(jiān)視器,設(shè)置波特率為9600,串口監(jiān)視器顯示出光敏傳感器的ADC值,DAC值和電壓值,光照越強,可以看到ADC值,DAC值和電壓值變大。如下圖。

?



?


ESP32 光敏傳感器實驗的評論 (共 條)

分享到微博請遵守國家法律
达拉特旗| 宁明县| 成安县| 永和县| 海盐县| 洮南市| 石楼县| 西盟| 郧西县| 荥阳市| 浮梁县| 晴隆县| 峨眉山市| 海南省| 上高县| 鄢陵县| 抚松县| 尉犁县| 郴州市| 松江区| 汤原县| 蒙阴县| 阿鲁科尔沁旗| 噶尔县| 淄博市| 嘉祥县| 容城县| 荔波县| 萝北县| 平陆县| 揭东县| 曲周县| 渑池县| 孟村| 寻乌县| 五台县| 翁源县| 清原| 磐石市| 弋阳县| 元氏县|