当前位置:网站首页>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 .
边栏推荐
- 什么是调。调的故事
- What are the trading forms of spot gold and what are the profitable advantages?
- Mathematical Knowledge: Steps - Nim Games - Game Theory
- C application interface development foundation - form control (4) - selection control
- Button wizard play strange learning - automatic return to the city route judgment
- 给你一个可能存在 重复 元素值的数组 numbers ,它原来是一个升序排列的数组,并按上述情形进行了一次旋转。请返回旋转数组的最小元素。【剑指Offer】
- 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
- Mathematical knowledge: Nim game game theory
- C language course information management system
- VIM 9.0 is officially released! The execution speed of the new script can be increased by up to 100 times
猜你喜欢

Top ten regular spot trading platforms 2022

并发编程的三大核心问题 -《深入理解高并发编程》

After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-9

传输层 TCP主要特点和TCP连接

MySQL basics 03 introduction to MySQL types
![[interview question] 1369 when can't I use arrow function?](/img/7f/84bba39965b4116f20b1cf8211f70a.png)
[interview question] 1369 when can't I use arrow function?

Steps to obtain SSL certificate private key private key file

看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
![[Arduino experiment 17 L298N motor drive module]](/img/e2/4511eaa942e4a64c8ca2ee70162785.jpg)
[Arduino experiment 17 L298N motor drive module]

CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr
随机推荐
看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
[Androd] Gradle 使用技巧之模块依赖替换
Meituan dynamic thread pool practice ideas, open source
tail -f 、tail -F、tailf的区别
海量数据冷热分离方案与实践
[机缘参悟-36]:鬼谷子-飞箝篇 - 面对捧杀与诱饵的防范之道
[day 29] given an integer, please find its factor number
dotConnect for PostgreSQL数据提供程序
JDBC courses
MySQL foundation 07-dcl
英语常用词汇
Mathematical Knowledge: Steps - Nim Games - Game Theory
Uniapp component -uni notice bar notice bar
VIM 9.0 is officially released! The execution speed of the new script can be increased by up to 100 times
Arduino dy-sv17f automatic voice broadcast
Druid database connection pool
Is there anything in common between spot gold and spot silver
数学知识:能被整除的数—容斥原理
GDB 在嵌入式中的相关概念
How is the mask effect achieved in the LPL ban/pick selection stage?