Hola en esta ocasión mi problema fue al realizar una práctica que no funciono para mí. Para no enredarlos mas les pongo la información del tutorial donde estoy realizando las prácticas mismo que me dio el proveedor donde compre mi placa.
Honestamente no se cual sea el problema, no creo que sea el codigo, sospecho que es la alimentación o el integrado, pero como dije no estoy seguro.
este es el codigo.
const int motorIn1 = 11; //attach to one of the pin of the motor
const int motorIn2 = 10; //attach to another pin of the motor
int btn1pin=13; //Set the digital 13 to button interface
int led1pin=5; //definition digital 5 pins as pin to control the LED
int btn2pin=12; //Set the digital 12 to button interface
int led2pin=4; //definition digital 4 pins as pin to control the LED
int btn3pin=7; //Set the digital 7 to button interface
int led3pin=3; //definition digital 3 pins as pin to control the LED
int btn4pin=6; //Set the digital 6 to button interface
int led4pin=2; //definition digital 2 pins as pin to control the LED
int state = 0; //Record the motor state. 0:STOP 1:forward 2:reverse
int DCmotorspeed = 128; //Motor speed 0~255
void setup()
{
pinMode(motorIn1,OUTPUT); //initialize the motorIn1 pin as output
pinMode(motorIn2,OUTPUT); //initialize the motorIn2 pin as output
pinMode(btn1pin,INPUT_PULLUP);//Set digital 13 port mode, the INPUT for the input
pinMode(led1pin,OUTPUT); //Set digital 5 port mode, the OUTPUT for the output
pinMode(btn2pin,INPUT_PULLUP);//Set digital 12 port mode, the INPUT for the input
pinMode(led2pin,OUTPUT); //Set digital 4 port mode, the OUTPUT for the output
pinMode(btn3pin,INPUT_PULLUP);//Set digital 7 port mode, the INPUT for the input
pinMode(led3pin,OUTPUT); //Set digital 3 port mode, the OUTPUT for the output
pinMode(btn4pin,INPUT_PULLUP);//Set digital 6 port mode, the INPUT for the input
pinMode(led4pin,OUTPUT); //Set digital 2 port mode, the OUTPUT for the output
}
void loop()
{
if(digitalRead(btn1pin)==LOW) //Detection button interface to low
{
delay(10); //Delay 10ms for the elimination of key leading-edge jitter
if(digitalRead(btn1pin)==LOW) //Confirm button is pressed
{
while(digitalRead(btn1pin)==LOW);//Wait for key interfaces to high
delay(10); //delay 10ms for the elimination of key trailing-edge jitter
while(digitalRead(btn1pin)==LOW);//Confirm button release
for(int i=0;i<4;i++)
{
digitalWrite(led1pin,HIGH); //Output control status LED, ON
delay(100); //delay 100ms
digitalWrite(led1pin,LOW); //Output control status LED, OFF
delay(100); //delay 100ms
}
if(state!=0) //Detecting the motor is running
{
state = 0; // Motor stop
digitalWrite(led1pin,LOW); //Output control status LED, OFF
}
else
{
state = 1; //Motor Run
digitalWrite(led1pin,HIGH);//Output control status LED, ON
}
}
}
if(digitalRead(btn2pin)==LOW) //Detection button interface to low
{
delay(10); //Delay 10ms for the elimination of key leading-edge jitter
if(digitalRead(btn2pin)==LOW) //Confirm button is pressed
{
while(digitalRead(btn2pin)==LOW);//Wait for key interfaces to high
delay(10); //delay 10ms for the elimination of key trailing-edge jitter
while(digitalRead(btn2pin)==LOW);//Confirm button release
if(state!=0) //Detecting the motor is running
{
for(int i=0;i<4;i++)
{
digitalWrite(led2pin,HIGH);//Output control status LED, ON
delay(100); //delay 100ms
digitalWrite(led2pin,LOW); //Output control status LED, OFF
delay(100); //delay 100ms
}
if(state==1) //Motor forward
{state = 2;} //Motor reverse
else if(state==2) //Motor reverse
{state = 1;} //Motor forward
}
}
}
if(digitalRead(btn3pin)==LOW) //Detection button interface to low
{
delay(10); //Delay 10ms for the elimination of key leading-edge jitter
if(digitalRead(btn3pin)==LOW) //Confirm button is pressed
{
while(digitalRead(btn3pin)==LOW);//Wait for key interfaces to high
delay(10); //delay 10ms for the elimination of key trailing-edge jitter
while(digitalRead(btn3pin)==LOW);//Confirm button release
if(state!=0)
{
for(int i=0;i<4;i++)
{
digitalWrite(led3pin,HIGH);//Output control status LED, ON
delay(100); //delay 100ms
digitalWrite(led3pin,LOW); //Output control status LED, OFF
delay(100); //delay 100ms
}
if(DCmotorspeed<230)
{DCmotorspeed += 20;} //Motor speed increases 20
else
{DCmotorspeed = 230;} //Motor speed 230
}
}
}
if(digitalRead(btn4pin)==LOW) //Detection button interface to low
{
delay(10); //Delay 10ms for the elimination of key leading-edge jitter
if(digitalRead(btn4pin)==LOW) //Confirm button is pressed
{
while(digitalRead(btn4pin)==LOW);//Wait for key interfaces to high
delay(10); //delay 10ms for the elimination of key trailing-edge jitter
while(digitalRead(btn4pin)==LOW);//Confirm button release
if(state!=0)
{
for(int i=0;i<4;i++)
{
digitalWrite(led4pin,HIGH);//Output control status LED, ON
delay(100); //Delay 100ms
digitalWrite(led4pin,LOW); //Output control status LED, OFF
delay(100); //Delay 100ms
}
if(DCmotorspeed>30)
{DCmotorspeed -= 20;} //Motor speed reduction 20
else
{DCmotorspeed = 20;} //Motor speed 20
}
}
}
switch(state)
{
case 0: clockwise(0); //rotate clockwise
break;
case 1: clockwise(DCmotorspeed); //rotate clockwise
break;
case 2: counterclockwise(DCmotorspeed);//rotate clockwise
break;
default: clockwise(0); //rotate clockwise
break;
}
}
//The function to drive motor rotate clockwise
void clockwise(int Speed)
{
analogWrite(motorIn1,Speed); //set the speed of motor
analogWrite(motorIn2,0); //stop the motorIn2 pin of motor
}
//The function to drive motor rotate counterclockwise
void counterclockwise(int Speed)
{
analogWrite(motorIn1,0); //stop the motorIn1 pin of motor
analogWrite(motorIn2,Speed); //set the speed of motor
}
El problema fue que no sucedio lo que deberia suceder es decir con 4 push botons controlaria el motor, un con respectivo led cada boton. les pongo imagenes.
Ahora mi gran duda aparte del circuito que no me funciono es esto, no entiendo como alimentar arduino aparte de la conexión USB.
¿Se daña el arduino si esta conectado mediante USB y un fuente externa?
¿Como se realiza esta conexión? estoy confundido ya que de acuerdo a la práctica que les pase, tiene una conexión diferente a un video que vi, donde en el jack conectan la alimetnación, y no por el Vin además de que alimentan un servomotor con el pin 5V.
Tal vez se reiran de mi, pero alguien pudiera hacerme un diagrama de como conectar arduino directamente al USB mas fuente externa alimentando un motor u otro elemento.
Otra cosa alguno de estos transistores me funciona para controlar un motor DC, S8050 Y S8550?
Gracias