当前位置:网站首页>STM32 - vibration sensor control relay on
STM32 - vibration sensor control relay on
2022-07-03 01:36:00 【Spade fish】
STM32—— The vibration sensor controls the relay to turn on the light
List of articles
Environmental Overview :
Windows10 pro
MDK—Lite 5.25
Hardware list :
1、 Relay
2、USB The lamp
3、SW-1801P Vibration sensors
4、STM32f103c8t6
Be careful :
stay User Folder create related folders and xx.c and xx.h file , Include related header files ,
Some basic operations have been written in previous articles
The experimental steps :
1、 Can make APB2 Medium GPIOA The clock turns on
Where to find relevant functions , It is also written in the previous article

//1、 Can make APB2 Medium GPIOA The clock turns on
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);
2、 To configure GPIOA Structural content
Before that , In defining structures
GPIO_InitTypeDef Shake_GPIO_Init;

// Drop down input
Shake_GPIO_Init.GPIO_Mode = GPIO_Mode_IPD;
// Set pin to A1
Shake_GPIO_Init.GPIO_Pin = GPIO_Pin_1;
Shake_GPIO_Init.GPIO_Speed = GPIO_Speed_10MHz;
3、 initialization

GPIO_Init(GPIOA,&Shake_GPIO_Init);
Code :
#include "stm32f10x.h"
#include "shake.h"
void Shake_Init()
{
// Defining structure
GPIO_InitTypeDef Shake_GPIO_Init;
//1、 Can make APB2 Medium GPIOA The clock turns on
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);
//2、 To configure GPIOA Structural content
// Drop down input
Shake_GPIO_Init.GPIO_Mode = GPIO_Mode_IPD;
// Set pin to A1
Shake_GPIO_Init.GPIO_Pin = GPIO_Pin_1;
Shake_GPIO_Init.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&Shake_GPIO_Init);
}
main.c file
By reading the level of the sensor , To judge and control the light on
If the reading sensor is low , Then turn on the light

Code :
#include "stm32f10x.h"
#include "led.h"
#include "Relay.h"
#include "Shake.h"
int main(void)
{
LED_Init();// The lamp
Relay_Init();// Relay
Shake_Init();// Vibration sensors
GPIO_SetBits(GPIOA, GPIO_Pin_3);// It's pins 3j Relay high level —— Turn off the lights
while(1){
//1、 By reading the level of the sensor , To judge and control the light on
//
if(GPIO_ReadOutputDataBit(GPIOA,GPIO_Pin_1 == 0)){
// If the reading sensor is low , Then turn on the light
GPIO_ResetBits(GPIOA, GPIO_Pin_3);// turn on the light
delayTime(1000);// Time delay
GPIO_SetBits(GPIOA, GPIO_Pin_3);// Turn off the lights
}else{
GPIO_SetBits(GPIOA, GPIO_Pin_3);// Turn off the lights
}
}
}
summary :
Practice over and over again , Remember the code , Remember the principle , More practice .
边栏推荐
- Arduino DY-SV17F自动语音播报
- Database SQL language 02 connection query
- Why is it not recommended to use BeanUtils in production?
- 2022 coal mine gas drainage examination question bank and coal mine gas drainage examination questions and analysis
- 【QT】自定义控件的封装
- Wireshark data analysis and forensics a.pacapng
- Mathematical knowledge: divisible number inclusion exclusion principle
- C#应用程序界面开发基础——窗体控制(3)——文件类控件
- [keil5 debugging] debug is stuck in reset_ Handler solution
- 看疫情之下服装企业如何顺势而为
猜你喜欢

【QT】自定义控件的封装

力扣 204. 计数质数

Database SQL language 01 where condition

Arduino dy-sv17f automatic voice broadcast

【数据挖掘】任务5:K-means/DBSCAN聚类:双层正方形

【面试题】1369- 什么时候不能使用箭头函数?
![[C language] detailed explanation of pointer and array written test questions](/img/24/c2c372b5c435cbd6eb83ac34b68034.png)
[C language] detailed explanation of pointer and array written test questions

Using tensorboard to visualize the model, data and training process

Qtablewidget lazy load remaining memory, no card!
![[androd] module dependency replacement of gradle's usage skills](/img/5f/968db696932f155a8c4a45f67135ac.png)
[androd] module dependency replacement of gradle's usage skills
随机推荐
[keil5 debugging] debug is stuck in reset_ Handler solution
Installation and use of serial port packet capturing / cutting tool
C application interface development foundation - form control (2) - MDI form
[C language] detailed explanation of pointer and array written test questions
wirehark数据分析与取证A.pacapng
Test shift right: Elk practice of online quality monitoring
High-Resolution Network (篇一):原理刨析
Steps to obtain SSL certificate private key private key file
Qtablewidget lazy load remaining memory, no card!
SSL flood attack of DDoS attack
What are the trading forms of spot gold and what are the profitable advantages?
Kivy tutorial - example of using Matplotlib in Kivy app
GDB 在嵌入式中的相关概念
Scheme and practice of cold and hot separation of massive data
串口抓包/截断工具的安装及使用详解
leetcode刷题_两数之和 II - 输入有序数组
[data mining] task 5: k-means/dbscan clustering: double square
不登陆或者登录解决oracle数据库账号被锁定。
VIM 9.0 is officially released! The execution speed of the new script can be increased by up to 100 times
數學知識:臺階-Nim遊戲—博弈論