I try to use a arduino nano to control a simple motor thru' a L9110 motor drive IC.
I use the pin D9 an D10 as signal output and control it by digitalWrite(HIGH), but it was not as expected 5V when it was measured by a multimeter.
The arduino is powered by a 7.4 V LiPo battery and the 5V output is connector to a HC-06 bluetooth and a mini-servo.
The whole program is also attached.
thanks for your help.
#include <SoftwareSerial.h>
#include <Wire.h> //引用二個函式庫SoftwareSerial及Wire SoftwareSerial
#include <Servo.h>
SoftwareSerial I2CBT(A0,A1); //定義PIN10及PIN11分別為RX及TX腳位
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
int INA = 9;
int INB = 10;
//int LED = 13;
void setup() {
Serial.begin(9600); //Arduino起始鮑率9600
I2CBT.begin(9600); //藍牙鮑率57600
myservo.attach(3); // attaches the servo on pin 3 to the servo object
pinMode(INA,OUTPUT);
pinMode(INB,OUTPUT);
}
void loop() {
byte cmmd[20];
int insize;
servo(90);
while(1){
if ((insize=(I2CBT.available()))>0){
Serial.print("input size = ");
Serial.println(insize); //顯示接收多少訊息
for (int i=0; i<insize; i++) {
Serial.print(cmmd*=char(I2CBT.read()));//將接收的訊息顯示出來*
-
//Serial.print("\n");*
-
} //for*
-
switch (cmmd[0]) {*
-
case 97: //'a' *
-
//digitalWrite(LED,HIGH);*
-
motorforward();*
-
Serial.print(" go");*
-
break; *
-
case 98: //'b'*
-
//digitalWrite(LED,LOW);*
-
motorstop();*
-
Serial.print(" stop");*
-
break;*
-
case 102: //'f'*
-
//digitalWrite(LED,LOW);*
-
motorback();*
-
Serial.print(" back");*
-
break;*
-
case 99: //'c'*
-
servo(150);*
-
Serial.print(" Left");*
-
break;*
-
case 100: //'d'*
-
servo(90);*
-
Serial.print(" Ctr");*
-
break;*
-
case 101: //'e'*
-
servo(30);*
-
Serial.print(" Right");*
-
break;*
-
} //Switch *
-
Serial.print("\n");*
-
} //if*
-
} //while*
}
//**************************
void servo(int servopos) { -
myservo.write(servopos); // tell servo to go to position in variable 'pos'*
-
delay(15); // waits 15ms for the servo to reach the position*
}
void motorforward() { -
digitalWrite(INA,LOW);*
-
digitalWrite(INB,HIGH);*
-
//delay(1000);*
}
void motorstop() { -
digitalWrite(INA,LOW);*
-
digitalWrite(INB,LOW);*
-
//delay(1000);*
}
void motorback() { -
digitalWrite(INA,HIGH);*
-
digitalWrite(INB,LOW);*
-
//delay(1000);*
}