1. 程式人生 > >Arduino 入門學習筆記4 繼電器實驗

Arduino 入門學習筆記4 繼電器實驗

程式

const int relayPin =7; //the "s" of relay module attach to
/**********************************************/
void setup()
{
  pinMode(relayPin, OUTPUT); //initialize relay as an output
}
/***********************************************/
void loop()
{
  digitalWrite(relayPin, HIGH); //Close the relay
  delay(1000); //wait for 1 second
  digitalWrite(relayPin, LOW); //disconnect the relay 
  delay(1000); //wait for 1 second
}
/*************************************************/

電路:

在這裡插入圖片描述

實驗效果

在這裡插入圖片描述

程式執行起來,可以聽到繼電器卡塔卡塔聲音。