선풍기로 사용하기에는 모터가 좀 약해보인다. INA와 INB를 PWM 핀에 꽂으면 속도 조절이 가능해진다. 아무데나 꽂는 습관이 있었는데 PWM 핀에 안 꽂으니 안 되더라(우노 호환보드 싸구려).
간단한 설명서 파일 첨부.
깃허브에서 찾은 드라이버 라이브러리
https://github.com/rydepier/L9110-Motor-Driver-and-Fan-motor-for-Arduino./tree/master
GitHub - rydepier/L9110-Motor-Driver-and-Fan-motor-for-Arduino.: Using the Keyes Motor and fan board
Using the Keyes Motor and fan board. Contribute to rydepier/L9110-Motor-Driver-and-Fan-motor-for-Arduino. development by creating an account on GitHub.
github.com
1. 0~255 속도를 지정할 수 있는데 처음에는 속도 조절 없이 최대 속도로 돌아가다가, for 문에서 속도 조절을 시도했다. 방향 전환까지.
int INA = 5;
int INB = 6;
void setup()
{
pinMode(INA,OUTPUT);
pinMode(INB,OUTPUT);
}
void loop()
{
// full speed : forward
digitalWrite(INA,LOW);
digitalWrite(INB,HIGH);
delay(3000);
digitalWrite(INA,HIGH);
digitalWrite(INB,HIGH);
delay(3000);
// full speed : forward
digitalWrite(INA,HIGH);
digitalWrite(INB,LOW);
delay(3000);
digitalWrite(INA,LOW);
digitalWrite(INB,LOW);
delay(3000);
// speed control forward
for (int speed = 0; speed < 256; speed += 1) {
analogWrite(INA, 0);
analogWrite(INB, speed);
delay(20);
}
delay(1000);
for (int speed = 255; speed >= 0; speed -= 1) {
analogWrite(INA, 0);
analogWrite(INB, speed);
delay(20);
}
delay(1000);
// speed control backward
for (int speed = 0; speed < 256; speed += 1) {
analogWrite(INA, speed);
analogWrite(INB, 0);
delay(20);
}
delay(1000);
for (int speed = 255; speed >= 0; speed -= 1) {
analogWrite(INA, speed);
analogWrite(INB, 0);
delay(20);
}
delay(1000);
}
https://www.youtube.com/shorts/VWuEnBRpffc
2. 아래 코드는 L9110 용 간단한 라이브러리인데 핀모드 설정 시에,
pinMode(pushButton, INPUT_PULLUP);
를 설정해줘야 한다.
/***********************************************************
* Fan Driver using L9110 Motor Driver
*
* The L9110 Motor Diver is a simple driver designed for
* toys and robots. It has two inputs INA and INB
* and two outputs to drive a simple DC Motor.
*
* The direction of motor spin can be changed and the speed
* can be controlled using PWM
*
* The device described here is the Keyes Fan Board with
* 4 connections
*
* Connections:
*
* INA to Arduino PIN 5
* INB to Arduino PIN 6
* Vcc to Arduino 5 volts
* GND to Arduino GND
*
* Push Button:
* (the output went LOW on pressing on my unit)
* Gnd to Arduino Gnd
* Vcc to Arduino 5 volts
* S to Adduino PIN 7
*
***********************************************************/
// INA, INB should(!) go to PWN pin of Arduino for speed control.
const int INA = 5;
const int INB = 6;
const int pushButton = 7;
const int ledPin = 13; // onboard LED
int action = 0; // 0 = Stop, 1 = Forward, 2 = Reverse
byte speed = 150; // change this to alter speed 0 - 255 although 80 is the minimum for reliable operation
void setup()
{
pinMode(INA,OUTPUT);
pinMode(INB,OUTPUT);
pinMode(pushButton, INPUT_PULLUP);
pinMode(ledPin, OUTPUT); // onboard LED
Serial.begin(9600); // for debug
}
void loop()
{
if (digitalRead(pushButton) == LOW){ // see if button has been pressed
digitalWrite(ledPin, HIGH); // turn on LED
action = action + 1; // increment action
if(action > 2){
action = 0; // keep action in range
}
if (action > 0){
digitalWrite(ledPin, HIGH); // Turn OFF LED if motor stopped
stopFan();
delay(100); // short delay to make direction change easier for motor
}
else digitalWrite(ledPin, LOW); // turn onboard LED OFF
delay(800); // simple switch debounce
}
switch (action){
case 0:
Serial.println("Stop Fan:");
stopFan();
break;
case 1:
Serial.println("Fan Forwards:");
forward();
break;
case 2:
Serial.println("Fan Reverse:");
reverse();
break;
}
}
void reverse(){
analogWrite(INA,0);
analogWrite(INB,speed);
}
void forward(){
analogWrite(INA,speed);
analogWrite(INB,0);
}
void stopFan(){
digitalWrite(INA,LOW);
digitalWrite(INB,LOW);
}
https://www.youtube.com/shorts/WZfMbUllX1U