【Arduino】108种传感器系列实验(20)-水银开关传感器模块-Arduino爱好者 - Powered by Discuz!

Arduino爱好者

 找回密码
 立即注册

QQ登录

只需一步,快速开始

楼主: eagler8

[经验] 【Arduino】108种传感器系列实验(20)---水银开关传感器模块

[复制链接]
 楼主| 发表于 2019-6-12 17:56 | 显示全部楼层
模块接线:
1.VCC:接电源正
2.GND:接电源负
3.DO:数字量信号输出
09(2).jpg
09.jpg

 楼主| 发表于 2019-6-12 18:02 | 显示全部楼层
模块使用说明:
1、产品不倾斜时,震动开关呈导通状态,输出端输出低电平,绿色指示灯亮;
2、产品倾斜时,震动开关断开状态,输出端输出高电平,绿色指示灯亮;
3、输出端可以与单片机直接相连,通过单片机来检测高低电平,由此来检测环境是否有倾斜,起到角度倾斜报警作用!
12.jpg

 楼主| 发表于 2019-6-12 18:46 | 显示全部楼层
实验示意场景图

13.jpg



 楼主| 发表于 2019-6-12 18:51 | 显示全部楼层
[mw_shl_code=arduino,true]/*
【Arduino】37种传感器模块系列实验(20)
   实验二十:水银开关传感器模块(KY-017)
*/

void setup()
{
      pinMode(3,INPUT);
      pinMode(13,OUTPUT);
}

void loop() {
  if (digitalRead(3)) {
      digitalWrite(13,HIGH);
      delay(1000);
  }
  else {
      digitalWrite(13,LOW);  
  }
}[/mw_shl_code]
 楼主| 发表于 2019-6-12 19:03 | 显示全部楼层
14.jpg
 楼主| 发表于 2019-8-27 09:27 | 显示全部楼层
[mw_shl_code=arduino,true]/*
【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
实验二十:水银开关传感器模块(KY-017)
*/

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:   
    digitalWrite(ledPin, HIGH);  
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}[/mw_shl_code]
 楼主| 发表于 2022-2-23 07:39 | 显示全部楼层
本帖最后由 eagler8 于 2022-2-23 07:41 编辑

水银开关de简单介绍

https://www.bilibili.com/video/B ... id_from=333.337.0.0



 楼主| 发表于 2022-2-23 07:40 | 显示全部楼层
电子元件从零到精通-做实验认识“水银开关”

https://www.bilibili.com/video/B ... id_from=333.337.0.0

 楼主| 发表于 2022-2-23 07:41 | 显示全部楼层
从零学电子:水银开关你用过没,可以拿它做一个电子水平仪

https://www.bilibili.com/video/B ... id_from=333.337.0.0

 楼主| 发表于 2022-2-23 07:42 | 显示全部楼层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|好玩手机游戏盒子|196体育|Arduino爱好者

GMT+8, 2023-9-30 11:24 , Processed in 0.078151 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表