歐姆龍按鍵開關模塊

出自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引腳。


電路連接示意圖

按鍵控制LED


示例代碼
/*
  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) {
    buttonState = digitalRead(buttonPin);
  }
  // 当按键按下时,点亮或熄灭LED
  if (ledState == true) {
    digitalWrite(ledPin, LOW);
    ledState = !ledState;
  } else {
    digitalWrite(ledPin, HIGH);
    ledState = !ledState;
  }
  delay(500);
}

程序下載地址:ButtonTest

程序運行結果:按下一次按鍵,點亮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 電子工作室