Arduino

DC 모터의 가변저항과 스위치 방향 제어하기

작성자 임베디드코리아 작성일25-05-15 23:53 조회185회 댓글0건

첨부파일

<* DC 모터의 가변저항과 스위치 방향 제어 *>
- 두 핀 모두 연결하여 출력 값을 조절해 DC모터의 회전 방향을 바꿀 수 있다.

---- <  DC 모터의 가변저항과 스위치 방향 제어 소스 코드 > -----------------------
int convertedPin = A0;
int convertedValue=0;
int speedValue = 0;
int inputValue = 0;

void setup() {
  pinMode(Motor_PinA, OUTPUT);
  pinMode(Motor_PinB, OUTPUT);
  pinMode(convertedPin, INPUT);
  pinMode(switchPin, INPUT);

}

void loop() {
  /* 가변저항의 입력 값 읽기 */
  convertedValue = analogRead(convertedPin);

  /* 입력 값 범위를 0 ~ 255로 변환*/
  speedValue = map(convertedValue, 0, 1023, 0, 255);

  if (inputValue ==LOW) {
      analogWrite(Motor_PinA, speedValue);
      analogWrite(Motor_PinB, 0);
  }
  else {
      analogWrite(Motor_PinA, 0);
      analogWrite(Motor_PinB, speedValue);
  }
  delay(100);

}