当前位置:网站首页>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
边栏推荐
- Sum of factor numbers of interval product -- prefix sum idea + fixed one shift two
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8
- Typora adds watermarks to automatically uploaded pictures
- 91.(cesium篇)cesium火箭發射模擬
- 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/
- Leetcode (Sword finger offer) - 58 - ii Rotate string left
- Message queue monitoring refund task batch process
- Virtualenv+pipenv virtual environment management
- Redis' attack tactics
- 二叉堆(一) - 原理与C实现
猜你喜欢

LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制

Message queue monitoring refund task batch process
![[classic example] classic list questions @ list](/img/d8/a259e5f9d08eacbef31254d1bc3304.jpg)
[classic example] classic list questions @ list

Dlhsoft Kanban, Kanban component of WPF

ACLY与代谢性疾病

Neo4j Chinese developer monthly - issue 202206

Deep understanding of grpc part1

C serialization simple experiment

自组织是管理者和成员的双向奔赴

JS reverse | m3u8 data decryption of a spring and autumn network
随机推荐
Interpretation of R & D effectiveness measurement framework
Personnaliser le plug - in GRPC
Summary of JFrame knowledge points 1
Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation
Pandas reads MySQL data
指纹浏览器工作原理、使用场景以及重要性简单讲解
自定義 grpc 插件
Consolidate -c operator
Machine learning - Data Science Library - day two
Golang des-cbc
The specified service is marked for deletion
巩固-C#运算符
Self organization is the two-way rush of managers and members
伸展树(一) - 概念和C实现
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-防止消息丢失及重复消费
NOV Schedule for . Net to display and organize appointments and recurring events
Onenet Internet of things platform - mqtts product equipment connected to the platform
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐