当前位置:网站首页>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 .
边栏推荐
- Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm
- Arduino DY-SV17F自动语音播报
- Tâche 6: regroupement DBSCAN
- 看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
- [fh-gfsk] fh-gfsk signal analysis and blind demodulation research
- d,ldc构建共享库
- MySQL --- 数据库查询 - 基本查询
- 【数据挖掘】任务5:K-means/DBSCAN聚类:双层正方形
- leetcode 6103 — 从树中删除边的最小分数
- 什么是调。调的故事
猜你喜欢

Telecom Customer Churn Prediction challenge

Wireshark data analysis and forensics a.pacapng

MySQL foundation 04 MySQL architecture

SSL flood attack of DDoS attack
![[shutter] animation animation (basic process of shutter animation | create animation controller | create animation | set value listener | set state listener | use animation values in layout | animatio](/img/70/54eb9359ac91aa43383b240eb036b7.gif)
[shutter] animation animation (basic process of shutter animation | create animation controller | create animation | set value listener | set state listener | use animation values in layout | animatio

MySQL foundation 05 DML language

Androd Gradle 对其使用模块依赖的替换

Dotconnect for PostgreSQL data provider

Force buckle 204 Count prime

MySQL basics 03 introduction to MySQL types
随机推荐
数学知识:Nim游戏—博弈论
海量数据冷热分离方案与实践
d,ldc构建共享库
Force buckle 204 Count prime
The latest analysis of tool fitter (technician) in 2022 and the test questions and analysis of tool fitter (technician)
The thread reuse problem of PageHelper using ThreadLocal, did you use it correctly?
Introduction to flask tutorial
Druid database connection pool
Mathematical knowledge: divisible number inclusion exclusion principle
C#应用程序界面开发基础——窗体控制(1)——Form窗体
Type expansion of non ts/js file modules
【數據挖掘】任務6:DBSCAN聚類
Learn the five skills you need to master in cloud computing application development
【系统分析师之路】第五章 复盘软件工程(开发模型开发方法)
數學知識:臺階-Nim遊戲—博弈論
Tâche 6: regroupement DBSCAN
ThinkPHP+Redis实现简单抽奖
Makefile中wildcard、patsubst、notdir的含义
Expérience de recherche d'emploi d'un programmeur difficile
C application interface development foundation - form control (4) - selection control