모터의 종류도 여러가지가 있지만, 흔히 쓰이는 DC모터를 제어하기 위해서는 모터드라이버가 필요하다.

DC모터를 아두이노에 직접 연결하여 사용하는 경우에, 모터의 회전 또는 멈춤에서 노이즈와 스파크가 발생하는 과정에서 아두이노에 손상을 가할 수 있다. 모터드라이버란 쉽게 말해, 모터의 회전 방향, 속도를 더 쉽게 제어하도록 만들어진 하나의 모듈이라고 보면 된다.
모터드라이버
모터드라이버의 종류도 굉장히 많지만, 가장 저렴하게 구입할 수 있는 L298N 모터드라이버를 사용하도록 한다.

L298N 모터의 pin out은 다음과 같다.

준비물
NO | 부품명 | 수량 |
1 | 아두이노 UNO R3 | 1 |
2 | 모터드라이버 L298N | 1 |
3 | DC모터 | 2 |
4 | 6V 배터리 | 1 |
5 | 점퍼 케이블 | 8 |
회로도

코드
코드 보기void setup() { pinMode(7, OUTPUT); // Motor A 방향설정1 pinMode(8, OUTPUT); // Motor A 방향설정2 pinMode(4, OUTPUT); // Motor B 방향설정1 pinMode(5, OUTPUT); // Motor B 방향설정2 } void loop() { /*모터A설정*/ digitalWrite(7, HIGH); // Motor A 방향설정1 digitalWrite(8, LOW); // Motor A 방향설정2 analogWrite(9, 100); // Motor A 속도조절 (0~255) /*모터B설정*/ digitalWrite(4, LOW); // Motor B 방향설정1 digitalWrite(5, HIGH); // Motor B 방향설정2 analogWrite(3, 100); // Motor B 속도조절 (0~255) delay(3000); // 3초 유지 }
모터의 방향과 속도를 계속해서 조절하면서 테스트 해보자.
You actually make it appear really easy together with your presentation but
I find this matter to be really one thing that I believe
I might by no means understand. It kind of feels too complicated and extremely huge
for me. I’m looking ahead in your subsequent post, I’ll attempt
to get the grasp of it!
Hey There. I found your weblog the usage of msn. That is a very well written article.
I’ll make sure to bookmark it and return to learn extra of your helpful
information. Thanks for the post. I will definitely return.
No matter if some one searches for his required thing, thus he/she wants to be available that in detail, so that thing is maintained over
here.
Undeniably believe that that you stated. Your favorite justification appeared to be
at the net the easiest factor to take into accout of.
I say to you, I certainly get annoyed whilst other
folks consider worries that they just do not recognize about.
You controlled to hit the nail upon the top and defined out the whole thing with no need side effect , other folks can take a signal.
Will likely be again to get more. Thanks
I got this site from my buddy who told me about this site and
at the moment this time I am browsing this site and reading very informative content here.