当前位置:网站首页>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
边栏推荐
- 消息队列之监控退款任务批处理过程
- Learning summary on June 29, 2022
- 比特熊直播间一周年,英雄集结令!邀你来合影!
- ABBIRB120工业机器人机械零点位置
- Force button homepage introduction animation
- LeetCode 454. 四数相加 II
- C summary of knowledge points 3
- usb peripheral 驱动 - cable connect/disconnect
- LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3
猜你喜欢
研发效能度量框架解读
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7
Istio、eBPF 和 RSocket Broker:深入研究服务网格
How to understand the developed query statements
博途V15添加GSD文件
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/
MQ prevent message loss and repeated consumption
C summary of knowledge points 1
CPU 上下文切换的机制和类型 (CPU Context Switch)
C knowledge point form summary 2
随机推荐
【datawhale202206】pyTorch推荐系统:多任务学习 ESMM&MMOE
Value/list in redis
Epoll introduction
The specified service is marked for deletion
Impressive bug summary (continuously updated)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3
Implementation of address book management system with C language
用于分类任务的数据集划分脚本
Typora realizes automatic uploading of picture pasting
自定义 grpc 插件
Personnaliser le plug - in GRPC
Onenet Internet of things platform - mqtts product equipment connected to the platform
How does Nike dominate the list all the year round? Here comes the answer to the latest financial report
Adjacency matrix undirected graph (I) - basic concepts and C language
Self organization is the two-way rush of managers and members
自组织是管理者和成员的双向奔赴
Force button homepage introduction animation
Redis的攻击手法
比特熊直播间一周年,英雄集结令!邀你来合影!
GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021