当前位置:网站首页>STM32 project practice (1) introduction and use of photosensitive resistor
STM32 project practice (1) introduction and use of photosensitive resistor
2022-07-01 12:08:00 【Proficient in embedded】
List of articles
Preface
In this article, we will take you to understand the use of photoresistors
One 、 Introduction to photosensitive resistance
Here is 4 Physical drawing of line photosensitive resistance 
Product wiring instructions :
1、VCC Connect the positive pole of the power supply 3.3-5V
2、GND Connect the negative pole of the power supply
3、DO TTL Switch signal output ( Configured for output mode )
4、AO Analog signal output (ADC Sampling channels )
Photosensitive resistance is mainly used to detect the surrounding light intensity , Light intensity changes, then ADC The sampled value will also send changes .
Two 、cubeMX To configure
We won't talk more about simple configuration, mainly ADC Configuration of sampling
What I'm using here is ADC1 passageway 4 So photoresistor A0 It should be connected to the corresponding ADC On the channel .
By the way D0 Output mode for simple detection of light intensity .
3、 ... and 、 Code instructions
//IO Definition of mouth
#define D0_SET() HAL_GPIO_WritePin(D0_GPIO_Port, D0_Pin, GPIO_PIN_SET)
#define D0_RESET() HAL_GPIO_WritePin(D0_GPIO_Port, D0_Pin,GPIO_PIN_RESET)
//ADC Sampling value
typedef struct
{
u32 adc_vol;//ADC Measured value
float vol;// Actual voltage value
}RESIST;
HAL_ADC_Start_IT(&hadc1);// Interrupt mode on ADC
//ADC Callback function
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
resist_data.adc_vol=HAL_ADC_GetValue(hadc);// obtain ADC Conversion result
resist_data.vol=resist_data.adc_vol*5/4095;// Convert to voltage value
}
// Test function when the voltage is greater than 2.5 when D0 Output on low-level photoresistor LED The indicator light is on
void Resist_Test(void)
{
if(resist_data.vol>2.5)
{
D0_RESET();
}
else
{
D0_SET();
}
}
while(1)
{
Resist_Test();
}
summary
The use of photoresistors is actually ADC Use of sampling , If you are not familiar with ADC If sampling, you can see my previous article :ADC sampling
边栏推荐
- LeetCode 454. 四数相加 II
- The specified service is marked for deletion
- 【datawhale202206】pyTorch推荐系统:精排模型 DeepFM&DIN
- Istio、eBPF 和 RSocket Broker:深入研究服务网格
- Redis' attack tactics
- The Missing Semester
- Exposure: a white box photo post processing framework reading notes
- C#依赖注入(直白明了)讲解 一看就会系列
- JPA and criteria API - select only specific columns - JPA & criteria API - select only specific columns
- 耐克如何常年霸榜第一名?最新財報答案來了
猜你喜欢

消息队列之监控退款任务批处理过程
![Wechat applet reports an error: [rendering layer network layer error] pages/main/main Local resource pictures in wxss cannot be obtained through wxss. You can use network pictures, Base64, or < image/](/img/6a/fe448ca635690bc5260436546b588e.jpg)
Wechat applet reports an error: [rendering layer network layer error] pages/main/main Local resource pictures in wxss cannot be obtained through wxss. You can use network pictures, Base64, or < image/
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 6](/img/0e/0900e386f3baeaa506cc2c1696e22a.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 6

Botu V15 add GSD file

Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS

二叉堆(一) - 原理与C实现

91.(cesium篇)cesium火箭發射模擬

MQ prevent message loss and repeated consumption

【语音信号处理】3语音信号可视化——prosody

Leetcode force buckle (Sword finger offer 31-35) 31 Stack push pop-up sequence 32i II. 3. Print binary tree from top to bottom 33 Post order traversal sequence 34 of binary search tree The path with a
随机推荐
MQ-防止消息丢失及重复消费
Impressive bug summary (continuously updated)
91. (cesium chapter) cesium rocket launch simulation
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8
Leetcode force buckle (Sword finger offer 31-35) 31 Stack push pop-up sequence 32i II. 3. Print binary tree from top to bottom 33 Post order traversal sequence 34 of binary search tree The path with a
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
Istio, ebpf and rsocket Broker: in depth study of service grid
技术分享 | MySQL:从库复制半个事务会怎么样?
usb peripheral 驱动 - cable connect/disconnect
Unity xlua co process packaging
Theoretical basis of graph
The Missing Semester
Learning summary on June 30, 2022
The Missing Semester
easyexcel的使用
迅为i.MX8Mmini开发板离线构建Yocto系统
邻接矩阵无向图(一) - 基本概念与C语言
ABBIRB120工业机器人机械零点位置
Use set_ Handler filters out specific SystemC wrapping & error messages
Summary of JFrame knowledge points 2