이 예에서는 Arduino와 두 개의 순간 스위치를 사용하여 선형 액추에이터의 방향을 제어합니다. 이 튜토리얼은 튜토리얼“Arduino를 사용한 모터 드라이버 속도 제어”, 계속하기 전에 해당 자습서를 검토하는 것이 좋습니다.
이 튜토리얼은 순간 모드에서 작동하는 푸시 버튼 (즉, 버튼을 놓을 때 액추에이터가 움직이지 않음)과 지속 모드에서 작동하는 푸시 버튼 (즉, 버튼을 놓아도 작동기가 계속 움직인다)의 두 섹션으로 나뉩니다.
참고 :이 튜토리얼은 기본적인 전자 원리, Arduino 하드웨어 및 소프트웨어에 대한 사전 지식이 있다고 가정합니다. Arduino를 처음 사용하는 경우 Google 및 YouTube 검색을 통해 제공되는 많은 훌륭한 초보자 자습서 중 하나에서 기본 사항을 배우는 것이 좋습니다. 사용자 지정 응용 프로그램에 대한 기술 지원을 제공 할 리소스가 없으며 공개적으로 사용 가능한 자습서 외부에서 코드 또는 배선 다이어그램을 디버그, 편집, 제공하지 않습니다.
구성품
- 12V 선형 액추에이터
- 12V 전원
- Arduino
- 모터 드라이버
- 두 개의 순간 버튼 (선택적으로 래칭 제어를위한 세 번째 버튼)
- 연결 및 압착 공구 또는 납땜 인두를위한 전선
배선
순간 제어를위한 하드웨어 및 소프트웨어 개요
순간 스위치는 버튼을 누르고있는 동안 액추에이터 만 움직이기를 원할 때 사용되며, 버튼을 놓으면 액추에이터가 자동으로 움직이지 않습니다. 아래 코드를 업로드하세요.
순간 제어를위한 코드
https://gist.github.com/Will-Firgelli/aeee209bda6b2246359eed70ec353eb8
/* Firgelli Automations
* Limited or no support: we do not have the resources for Arduino code support
*
* Program enables momentary direction control of actuator using push button
*/
int RPWM = 10; //connect Arduino pin 10 to IBT-2 pin RPWM
int LPWM = 11; //connect Arduino pin 11 to IBT-2 pin LPWM
int downPin = 12;
int upPin = 13;
int Speed = 255; //choose any speed in the range [0, 255]
void setup() {
pinMode(RPWM, OUTPUT);
pinMode(LPWM, OUTPUT);
pinMode(downPin, INPUT_PULLUP);
pinMode(upPin, INPUT_PULLUP);
}
void loop() {
if(digitalRead(upPin)==LOW){ //check if extension button is pressed
analogWrite(RPWM, 0);
analogWrite(LPWM, Speed);
}
else if(digitalRead(downPin)==LOW){ //check if retraction button is pressed
analogWrite(RPWM, Speed);
analogWrite(LPWM, 0);
}
else{ //if no button is pushed, remain stationary
analogWrite(RPWM, 0);
analogWrite(LPWM, 0);
}
}
지속적인 제어를위한 하드웨어 및 소프트웨어 개요
또는 때때로 래칭 버튼을 사용하고 싶을 수 있습니다. 버튼을 누를 때 액추에이터가 움직이고 버튼을 놓을 때 계속 움직입니다. 이를 위해서는 핀 8과 GND에 연결된 스위치를 하나 더 추가 한 다음 아래 프로그램을 업로드해야합니다. 버튼을 놓아도 액추에이터가 움직이지 않기 때문에이 새로운 스위치는 "정지"버튼으로 작동합니다.
지속적인 통제를위한 코드
https://gist.github.com/Will-Firgelli/2b96dce14c0cee7a0009e61e47cc5f67/* Firgelli Automations
* Limited or no support: we do not have the resources for Arduino code support
*
* Program enables latching direction control of actuator using push button
*/
int RPWM = 10; //connect Arduino pin 10 to IBT-2 pin RPWM
int LPWM = 11; //connect Arduino pin 11 to IBT-2 pin LPWM
int stopPin = 8;
int downPin = 12;
int upPin = 13;
int Speed = 255; //choose any speed in the range [0, 255]
void setup() {
pinMode(RPWM, OUTPUT);
pinMode(LPWM, OUTPUT);
pinMode(stopPin, INPUT_PULLUP);
pinMode(downPin, INPUT_PULLUP);
pinMode(upPin, INPUT_PULLUP);
}
void loop() {
if(digitalRead(upPin)==LOW){ //check if extension button is pressed
analogWrite(RPWM, 0);
analogWrite(LPWM, Speed);
}
else if(digitalRead(downPin)==LOW){ //check if retraction button is pressed
analogWrite(RPWM, Speed);
analogWrite(LPWM, 0);
}
else if(digitalRead(stopPin)==LOW){ //check if retraction button is pressed
analogWrite(RPWM, 0);
analogWrite(LPWM, 0);
}
}