国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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 光敏傳感器實驗的評論 (共 條)

分享到微博請遵守國家法律
白玉县| 三穗县| 通道| 岳池县| 巍山| 乌苏市| 永春县| 韶山市| 安阳县| 团风县| 庄浪县| 社旗县| 乌兰察布市| 林周县| 柳林县| 灵宝市| 曲松县| 浏阳市| 漳浦县| 马龙县| 琼结县| 喀什市| 松桃| 张家川| 江达县| 宁国市| 滕州市| 开化县| 慈溪市| 三河市| 凤翔县| 磐安县| 东丽区| 永川市| 股票| 仁布县| 温泉县| 兴业县| 宿松县| 宕昌县| 邓州市|