欧姆龙按键开关模块
来自YFRobotwiki
产品简介
欧姆龙按键模块采用原装进口欧姆龙轻触式按键设计制作。欧姆龙按键具有轻快的按键触感,高品质寿命长。五色按键帽自由选择,外观大气美观。
欧姆龙按键模块按下时,输出低电平;释放时,输出高电平。
规格参数
- 供电电压:DC3.3 - 5V
- 工作温度:-25~+70℃,60%RH以下(无结冰、无凝露)
- 工作湿度:35~85%RH(+5~+35℃)
- 接点结构:1A常开接点
- 接触阻值:100mΩ以下
- 绝缘阻值:100MΩ以上
- 使用寿命:1000万次以上
- 安装孔径:3MM
- 模块尺寸:28*21*15.8MM(长*宽*高)
- 孔间距:15MM
- 模块重量:3.8g
引脚说明
- 1. G -- Gnd(地)
- 2. V -- Vcc(电源+5V)
- 3. S -- Sign(信号)
应用示例
示例一:按键控制LED
- 电路连接
- 欧姆龙按键模块的 G、V、S分别连接 Arduino UNO的GND、VCC(+5V)、D2引脚。
- 食人鱼LED模块的 G、V、S分别连接 Arduino UNO的GND、VCC(+5V)、D10引脚。
- 电路连接示意图
- 示例代码
/*
Button_switch
按键开关:按一次按键,点亮LED,再按一次按键,熄灭LED
This example code is in the public domain.
www.yfrobot.com
*/
// 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 = 10; // the number of the LED pin
boolean ledState = false; // 记录LED状态
boolean buttonState = true; // 记录按键状态
void setup ()
{
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
}
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// 等待按键按下
while (buttonState == HIGH) {}
// 当按键按下时,点亮或熄灭LED
if (ledState == true) {
digitalWrite(ledPin, LOW);
ledState = !ledState;
} else {
digitalWrite(ledPin, HIGH);
ledState = !ledState;
}
delay(500);
}
程序下载地址:
程序运行结果:按下按键,点亮LED,释放按键,熄灭LED。
示例二:按键控制无源蜂鸣器发声
- 电路连接
- 5个欧姆龙按键模块的 G、V、S分别连接 Arduino UNO的GND、VCC(+5V)、D8~D12引脚。
- 无源蜂鸣器模块的 G、V、S分别连接 Arduino UNO的GND、VCC(+5V)、D6引脚。
- 电路连接示意图
- 示例代码
//button test
int buzzerPin = 6;
int buttonPin[5] = {8,9,10,11,12};
int buttonState = 0;
int buttonVal[5];
int notes_DL[7] = {147,165,175,196,221,248,278};
int notes_D[7] = {294,330,350,399,441,495,556};
int notes_DH[7] = {589,667,700,786,882,990,1112};
void setup ()
{
pinMode(buzzerPin,OUTPUT);
}
void loop()
{
for(int i = 0;i < 5;i++){
if(digitalRead(buttonPin[i]) == LOW){
buttonState = buttonPin[i];
}
}
switch(buttonState){
case 8: makeSound(1); break;
case 9: makeSound(2); break;
case 10: makeSound(3); break;
case 11: makeSound(4); break;
case 12: makeSound(5); break;
}
buttonState = 0;
}
// s value: 1 - 7
void makeSound(int s){
tone(buzzerPin,notes_D[s-1]);
delay(400);
noTone(buzzerPin);
}
程序下载地址:buttonTest
程序运行结果:每个按键,可以发一个音符,按下即可发声,分别 "dol re mi fa so" 。
程序演示视频:button
参考资料
更多建议和问题欢迎反馈至 YFRobot论坛
购买方式:YFRobot 电子工作室