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
}
/*************************************************/

电路:

Arduino 入门学习笔记4 继电器实验

实验效果

Arduino 入门学习笔记4 继电器实验

程序运行起来,可以听到继电器卡塔卡塔声音。