当前位置:网站首页>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 .
边栏推荐
- Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
- 【QT】自定义控件的封装
- High-Resolution Network (篇一):原理刨析
- MySQL basics 03 introduction to MySQL types
- openresty 缓存
- MySQL foundation 06 DDL
- GDB 在嵌入式中的相关概念
- Button wizard play strange learning - automatic return to the city route judgment
- 【数据挖掘】任务2:医学数据库MIMIC-III数据处理
- [shutter] animation animation (the core class of shutter animation | animation | curvedanimation | animationcontroller | tween)
猜你喜欢
Database SQL language 01 where condition
【数据挖掘】任务5:K-means/DBSCAN聚类:双层正方形
音程的知识的总结
How is the mask effect achieved in the LPL ban/pick selection stage?
Meituan dynamic thread pool practice ideas, open source
LeetCode 987. Vertical order transverse of a binary tree - Binary Tree Series Question 7
Pytest learning notes (12) -allure feature · @allure Step () and allure attach
Scheme and practice of cold and hot separation of massive data
Leetcode 2097 - Legal rearrangement of pairs
[error record] the shutter component reports an error (no directionality widget found. | richtext widgets require a directionality)
随机推荐
MySQL - database query - condition query
Scheme and practice of cold and hot separation of massive data
[system analyst's road] Chapter V double disk software engineering (development model development method)
[FPGA tutorial case 5] ROM design and Implementation Based on vivado core
Expérience de recherche d'emploi d'un programmeur difficile
不登陆或者登录解决oracle数据库账号被锁定。
Detailed explanation of Q-learning examples of reinforcement learning
Do not log in or log in to solve the problem that the Oracle database account is locked.
软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
Mathematical knowledge: divisible number inclusion exclusion principle
【數據挖掘】任務6:DBSCAN聚類
2022 cable crane driver examination registration and cable crane driver certificate examination
Dotconnect for PostgreSQL data provider
[day 29] given an integer, please find its factor number
LDC Build Shared Library
Database SQL language 02 connection query
Arduino dy-sv17f automatic voice broadcast
【数据挖掘】任务2:医学数据库MIMIC-III数据处理
【数据挖掘】任务5:K-means/DBSCAN聚类:双层正方形
Wireshark data analysis and forensics a.pacapng