Jun 5, 2021

[Arduino code] limit switch (Endstop switch) (리미트 스위치, 엔드스탑 스위치)

- Supplies: limit switch, Arduino board

- How to connect and the result of serial monitor.



- Example code

#define limit_switch_pin 2

void setup() {
  // put your setup code here, to run once:
  // switch pin setting
  Serial.begin(9600);
  pinMode(limit_switch_pin, INPUT);
 
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(limit_switch_pin) == LOW){
    Serial.println("Switch close");
  }else{
    Serial.println("Switch open");
  }
}



No comments:

Post a Comment